[英]onMessageReceived not called on Android
Please note that there are NO basic issues with the client code like service registration or token issuance issue. 请注意,客户端代码没有基本问题,例如服务注册或令牌发行问题。
I am using the FCM REST API to send messaged from my app server. 我正在使用FCM REST API从我的应用服务器发送消息。 The requirement is to show a dialog when the push messages comes and app is in foreground or if the app is in background, just display a notification.
要求是在推送消息到来且应用程序位于前台时或在应用程序位于后台时显示对话框,仅显示通知。
When I use the simple notification payload, everything works fine as expected. 当我使用简单的通知有效负载时,一切都按预期工作。 But as soon as my message contains a data payload too (in addition to the notification payload), none of the callbacks on my app gets called irrespective of whether the app is in foreground or background.
但是,一旦我的消息也包含数据有效负载(除了通知有效负载之外),无论应用程序处于前台还是后台,我的应用程序上的任何回调都不会被调用。
From documentation, it sounds like message with both kind of payloads should still work - FireBase Android doc . 从文档中,听起来像带有两种有效负载的消息都应该仍然有效-FireBase Android doc 。
To summarise this works - 总结一下这项工作-
{
"to":"verylongtoken",
"token":"verylongtoken",
"notification":{
"title":"title",
"body":"body"
},
"priority":"high"
}
But this does not - 但这不是-
{
"to":"verylongtoken",
"token":"verylongtoken",
"notification":{
"title":"title",
"body":"body"
},
"data":{
"message_type":"1"
},
"priority":"high"
}
Sounds really silly, but what am i missing ? 听起来真的很傻,但是我想念什么呢?
From FCM official site: https://firebase.google.com/docs/cloud-messaging/concept-options 在FCM官方网站上: https : //firebase.google.com/docs/cloud-messaging/concept-options
If you want to set priority for a message then change your json format from 如果您想为消息设置优先级,则将json格式从
{
"to":"verylongtoken",
"token":"verylongtoken",
"notification":{
"title":"title",
"body":"body"
},
"data":{
"message_type":"1"
},
"priority":"high"
}
to 至
{
"to":"verylongtoken",
"token":"verylongtoken",
"notification":{
"title":"title",
"body":"body"
},
"data":{
"message_type":"1"
},
"android":{
"priority":"high"
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.