我是推送通知的新手,我有一个问题,当应用程序收到通知并且应用程序打开时,"FCMIntentService extends“类可以正确执行,但当应用程序关闭或在后台时,不要执行这个类。为什么?哪个类处理通知?
发布于 2020-09-30 12:28:43
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!"
}
}
}https://stackoverflow.com/questions/64130741
复制相似问题