简体   繁体   English

在Android上未调用onMessageReceived

[英]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.

相关问题 Android通知:未调用onMessageReceived - Android notifications: onMessageReceived not called FCM android onmessagereceived未调用 - FCM android onmessagereceived not called Android FCM-在后台未调用onMessageReceived - Android FCM - onMessageReceived not called on background 在Android上未调用SendBird ChannelHandler onMessageReceived - SendBird ChannelHandler onMessageReceived is not called on Android android中的onMessageReceived在后台应用时没有调用 - onMessageReceived in android O not called when app in background Java Android FirebaseMessagingService:根本没有调用onMessageReceived - Java Android FirebaseMessagingService: onMessageReceived not called at all Android FirebaseMessaging 服务 onMessageReceived 调用了两次 - Android FirebaseMessaging Service onMessageReceived called twice 在 GCM 事件中解析时间戳时出错 - Null Android(未调用 onMessageReceived) - Error while parsing timestamp in GCM event - Null Android (onMessageReceived not called) Android Mobile / Wear App onMessageReceived为一条消息调用多次 - Android Mobile/Wear App onMessageReceived Called Multiple Times for One Message 从不使用Android中的Firebase从服务器调用通知中的onMessageReceived - onMessageReceived never called in notification from server using Firebase in Android
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM