Pra*_*ain 7 android firebase firebase-cloud-messaging firebase-notifications
我正在尝试在我的项目中集成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 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
Run Code Online (Sandbox Code Playgroud)
请尝试在上述环境中重现.
我通过将应用程序包名称重命名(例如旧名称:com.xyz)解决了问题 com.xyz2
使用新名称,我将这个(新)Android 应用程序添加到 firebase 项目中(它生成了新的应用程序 ID)。通知开始按预期工作(无需重试)。
但遗憾的是我必须重命名应用程序包才能解决它。如果这个应用程序在谷歌播放中发布,那么我就不能重命名该应用程序,否则没有人可以得到这个应用程序的进一步更新,它就成为一个新的应用程序!
如果一些 Firebase 开发人员能够阐明正在发生的事情,那就太好了。
当应用程序名称/顶级包名称相同时,重新创建 firebase 项目和重新创建 android 项目没有帮助。更改现有 Android 项目中的应用程序名称和相关命名空间暂时修复了该问题。
理想情况下,我想知道对此的正确修复方法并使用现有名称,而不是在应用程序名称末尾添加后缀 2。
归档时间: |
|
查看次数: |
1718 次 |
最近记录: |