首页 > 解决方案 > FMC push notification android background

问题描述

I'm new in push notifications and I have an issue, when app receive a notification and app is open the class "FCMIntentService extends FirebaseMessagingService" execute correctly, but when app is closed or in background don't execute this class. Why? and Which class process the notification?

标签: push-notificationfmc

解决方案


Firebase 云消息传递有两个概念,一是“通知”,二是“数据”。

在此处输入图像描述

在前台通知被onMessageReceived()正确发送到方法,但在后台的情况下,通知被发送到系统托盘参见图像。

解决方案:使用数据字段从服务器发送通知。

不要使用通知对象从服务器发送通知

{
  "message":{
    "token":"bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...",
    "notification":{   // Don't use the notification           
      "title":"Portugal vs. Denmark",
      "body":"great match!"
    }
  }
}

使用数据字段从服务器发送通知,它将在后台和前台工作。

{
      "message":{
        "token":"bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...",
        "data":{   // Use the data object to send the notification
          "title":"Portugal vs. Denmark",
          "body":"great match!"
        }
      }
    }

推荐阅读