FMC推送通知Android背景

时间:2020-09-30 04:12:43

标签: push-notification fmc

我是推送通知的新手,但有一个问题,当应用程序收到通知且应用程序打开时,类“ FCMIntentService extended FirebaseMessagingService”可以正确执行,但是当应用程序关闭或在后台运行时,请勿执行该类。为什么?哪个类处理通知?

1 个答案:

答案 0 :(得分:0)

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

enter image description here

在前台通知中,通知已正确发送到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!"
        }
      }
    }