首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么我在android 7上收到多个FCM通知

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

Stack Overflow用户
提问于 2017-11-22 15:36:45
回答 0查看 2.7K关注 0票数 9

我正在尝试将FCM通知集成到我的项目中。我有Cloud Function后台,应用程序运行在android上。以下是用于发送通知的云代码:

代码语言:javascript
复制
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)
    })
})

在原生Android应用程序上,我多次收到通知,间隔几分钟。在这里,我看到了这样的通知:

代码语言:javascript
复制
Notification Test 30

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

代码语言:javascript
复制
Notification Test 30

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

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

下面是我的环境:

代码语言:javascript
复制
Native Android App
Using Android 7
Latest Android Studio Stable
Android Gradle Plugin - 3.1.1
Gradle - 4.1
Firebase-Ui - 3.1.0
Play Services - 11.4.2

请尝试在上面提到的环境中繁殖。

EN

回答

页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47429141

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档