Firebase Cloud Messaging Android接收静默推送通知
我正在尝试从GCM迁移到Firebase云消息传递,我注意到当应用程序未运行时,通知会进入通知托盘.使用GCM并非如此,这取决于开发人员是否显示通知.我希望在FCM中具有类似的行为,其中当应用程序运行时,我希望静默处理推送消息,而不是让用户单击通知并启动应用程序.我该怎么做到.
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.
谢谢, P
Firebase Cloud消息具有两种类型的消息:
Firebase Cloud Messages has two types of messages:
- 通知消息:这种消息的行为与GCM消息相同
- Notification Message: this type of message has the same behavior as the GCM messages
FCM代表客户端应用程序自动将消息显示给最终用户设备.通知消息具有一组预定义的用户可见键
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
- 数据消息:此类型具有您上述的行为.
- 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.
要发送数据消息,您需要使用HTTP API [用于数据消息]. (引自完整文档: https://firebase.google.com/docs/cloud-messaging/concept-options