更改推送
This commit is contained in:
41
app/src/main/java/com/aiosman/riderpro/JpushReciver.kt
Normal file
41
app/src/main/java/com/aiosman/riderpro/JpushReciver.kt
Normal file
@@ -0,0 +1,41 @@
|
||||
package com.aiosman.riderpro
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.util.Log
|
||||
import cn.jpush.android.api.NotificationMessage
|
||||
import cn.jpush.android.service.JPushMessageReceiver
|
||||
import com.google.gson.Gson
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
data class ActionExtra(
|
||||
@SerializedName("action")
|
||||
val action: String,
|
||||
@SerializedName("postId")
|
||||
val postId: String?,
|
||||
)
|
||||
|
||||
class JpushReciver : JPushMessageReceiver() {
|
||||
val gson = Gson()
|
||||
override fun onInAppMessageClick(p0: Context?, p1: NotificationMessage?) {
|
||||
super.onInAppMessageClick(p0, p1)
|
||||
// 打开自定义的页面
|
||||
Log.d("JpushReciver", "onInAppMessageClick")
|
||||
}
|
||||
|
||||
override fun onNotifyMessageOpened(context: Context?, message: NotificationMessage) {
|
||||
super.onNotifyMessageOpened(context, message)
|
||||
// 打开自定义的页面
|
||||
Log.d("JpushReciver", "onNotifyMessageOpened")
|
||||
val actionExtra = message.notificationExtras?.let {
|
||||
gson.fromJson(it, ActionExtra::class.java)
|
||||
}
|
||||
actionExtra?.postId?.let {
|
||||
val intent = Intent(context, MainActivity::class.java).apply {
|
||||
putExtra("POST_ID", it)
|
||||
flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
|
||||
}
|
||||
context?.startActivity(intent)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user