【发布时间】:2022-08-18 18:04:24
【问题描述】:
我正在研究android推送通知,通知处于所有三种状态,然后,当我点击通知数据时,只会进入前台状态,但不会进入终止和后台。
服务文件中的待处理意图:
val intentVid = Intent(context, MainActivity::class.java)
intentVid.putExtra(\"Id\", \"787789\")
intentVid.flags = Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_CLEAR_TOP
val pendingIntent = PendingIntent.getActivity(
context, 0,
intentVid, PendingIntent.FLAG_UPDATE_CURRENT
)
下面的函数在 onCreate 和 onNewIntent 函数中被调用:
private fun handleNotificationEvent(intent: Intent?) {
if (intent!!.extras != null) {
order_status = intent.extras!!.getString(\"Id\", \"\")
if (order_status.length == 6) {
Toast.makeText(
this,
\"ID :- \" + intent.extras!!.getString(\"Id\", \"\"),
Toast.LENGTH_LONG
)
.show()
}
}
}
标签: android android-studio kotlin push-notification android-notifications