[英]Receive FCM data messages in service when the app is not in Foreground
FCM documentation states that when app is in foreground, FCM messages are delivered to system tray. FCM 文档指出,当应用程序处于前台时,FCM 消息将传递到系统托盘。
I want to handle these messages in a FirebaseMessagingService.我想在 FirebaseMessagingService 中处理这些消息。 Is it possible to access the system tray to get the firebase messages (as I've already a scheduled Service) or to reactivate the FirebaseMessagingService.onMessageReceived behaviour as on older firebase API versions?
是否可以访问系统托盘以获取 firebase 消息(因为我已经安排了服务)或重新激活 FirebaseMessagingService.onMessageReceived 行为,就像旧 firebase ZDB974238714CA8DE6FZA7 版本一样?
onMessageReceived
is called only when the when there is no notification attached to the message.仅当消息没有附加通知时才调用
onMessageReceived
。 So for messages with both notification and payload, it won't be called.因此,对于同时具有通知和有效负载的消息,它不会被调用。
According to FCM documentation :根据FCM 文档:
onMessageReceived is provided for most message types, with the following exceptions:
大多数消息类型都提供了 onMessageReceived,但以下情况除外:
Notification messages delivered when your app is in the background .
当您的应用程序在后台时传递的通知消息。 In this case, the notification is delivered to the device's system tray.
在这种情况下,通知将传送到设备的系统托盘。 A user tap on a notification opens the app launcher by default.
默认情况下,用户点击通知会打开应用启动器。
Messages with both notification and data payload , when received in the background.
在后台接收时带有通知和数据负载的消息。 In this case, the notification is delivered to the device's system tray, and the data payload is delivered in the extras of the intent of your launcher Activity.
在这种情况下,通知被传递到设备的系统托盘,数据负载被传递到启动器 Activity 的附加内容中。
As you can see, onMessageReceived
is called even if your app is in background.如您所见,即使您的应用程序在后台,也会调用
onMessageReceived
。
The messages disappeared on a Xiaomi device due to power saving restriction.由于节电限制,消息在小米设备上消失了。 After changing batterie management settings data messages arrived
更改电池管理设置后,数据消息到达
FCM message will show in system tray if your app is in background but if your app is in foreground your FirebaseMessagingService.onMessageReceived will trigger so you can show a dialog or snackBar.如果您的应用程序在后台,FCM 消息将显示在系统托盘中,但如果您的应用程序在前台,您的 FirebaseMessagingService.onMessageReceived 将触发,因此您可以显示对话框或snackBar。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.