小编Pra*_*ain的帖子

为什么我在android 7上收到多个FCM通知

我正在尝试在我的项目中集成FCM通知.我有云功能后端,应用程序在Android上运行.以下是发送通知的云代码:

exports.notificationTest =  functions.database.ref(`/test/childA/childB/status`).onUpdate(event => {

    const status = event.data.val();
    console.info("Processing notificationTest cloud function")
    console.info(`status : ${status}`)
    const token = "EnterYourNotificationTokenHere"

    const randomNum = Math.floor(Math.random() * 100)
    var message = { 
        notification: { title : "My App", body : `Notification Test ${randomNum}`}
    }   
    console.info(`Sending message on notification token`)  
    return admin.messaging().sendToDevice(token, message)
    .then((response) => {
        console.info("Successfully sent notification")
    }).catch(function(error) {
        console.warn("Error sending notification " , error)
    })
})
Run Code Online (Sandbox Code Playgroud)

在原生Android应用上,我会多次收到通知,间隔时间为几分钟.在这里,我看到过这样的通知:

Notification Test 30
Run Code Online (Sandbox Code Playgroud)

然后在2,4,8,16,32分钟之前的通知时间后,我再次得到以下消息

Notification Test 30
Run Code Online (Sandbox Code Playgroud)

我不认为我需要在这里粘贴日志,因为代码肯定只执行一次(因为通知中的随机数保持不变).

那么,为什么会发生这种情况以及如何解决它?

以下是我的环境:

Native Android …
Run Code Online (Sandbox Code Playgroud)

android firebase firebase-cloud-messaging firebase-notifications

7
推荐指数
1
解决办法
1718
查看次数