Firebase Cloud Messaging Android receive silent push notifications

南笙酒味 提交于 2019-12-23 09:02:14

问题


I am trying to migrate to Firebase cloud messaging from GCM and I noticed that when the application is not running the notifications are coming in the notifications tray. With GCM this was not the case, it was up to the developer to show a notification or not. I want to have similar behavior with FCM where when the app is running I want to silently handle the push message instead of having user to click on the notification and start the app. How can I achieve that.

Thanks, P


回答1:


Firebase Cloud Messages has two types of messages:

  1. Notification Message: this type of message has the same behavior as the GCM messages

FCM automatically displays the message to end-user devices on behalf of the client app. Notification messages have a predefined set of user-visible keys

  1. Data Message: this type has the behavior you described above.

Client app is responsible for processing data messages.
Data messages have only custom key-value pairs.

To send data messages you need to use the HTTP API [for Data Message]. (quoted from Arthur)

Full documentation: https://firebase.google.com/docs/cloud-messaging/concept-options



来源:https://stackoverflow.com/questions/38134894/firebase-cloud-messaging-android-receive-silent-push-notifications

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!