【发布时间】:2022-11-09 06:03:39
【问题描述】:
根据我在这里遵循的文档documentation
我发送的有效载荷不会触发 onMessageReceived 方法让我解析它,而是自动触发华为通知中心的通知。
这是我发送的示例有效负载,我已经包含了foreground_show 并将其设置为 false,如网络中所述:
{
"validate_only":false,
"message": {
"notification": {
"title": "message title",
"body": "message body"
},
"android": {
"notification": {
"foreground_show": false,
"click_action": {
"type": 3
}
}
},
"data":"{'param2':'value1','param3':'value2'}",
"token": [
"ABW18Q4Rw5CAB68f9yS_1f859k0s-t3G1aIZheq5l6TedFj_Iold4I6M2EK-pwPTzt6HXxL_"
]
}
}
结果是,它不会触发 onMessageReceive 函数,但它会自动在设备上创建通知。
但是如果我从有效负载中删除通知和 android 并且只发送数据它成功触发 onMessageReceive :
{
"validate_only": false,
"message": {
"data": "{'param1':'value1','param2':'value2'}",
"token": [
"ABW18Q4Rw5CAB68f9yS_1f859k0s-t3G1aIZheq5l6TedFj_Iold4I6M2EK-pwPTzt6HXxL_"
]
}
}
这是我已经覆盖 onMessageReceived 的类:
class CustomPushService : HmsMessageService() {
private val TAG = "PushTokenLog"
override fun onNewToken(token: String?, bundle: Bundle?) {
super.onNewToken(token, bundle)
Log.d(TAG, "receive token:$token")
}
override fun onMessageReceived(remoteMessage: RemoteMessage?) {
Log.d(TAG, "onMessageReceived")
Log.d(TAG, "onMessageReceived:title:${remoteMessage?.notification?.title}")
super.onMessageReceived(remoteMessage)
}
}
我已经包含了前台显示:false,它不会触发 onMessageReceived,除非我只在有效负载中发送数据,那么它将触发 onMessageReceived。
那么是否无法发送第一个有效负载中所示的完整有效负载并触发 onMessageReceived 以便我可以处理有效负载?如果我的方法错误,请告诉我
【问题讨论】:
标签: android kotlin huawei-push-notification