I am trying to integrate FCM notification into my project. I have a Cloud Function, and the application runs on android. Below is the cloud code for sending notifications:
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) }) })
In my own Android application, I receive a notification several times at intervals of a few minutes. Here I saw a notification like this:
Notification Test 30
then after 2,4,8,16,32 minutes of the previous notification time, I again get the message below
Notification Test 30
I donβt think I need to insert a log here because the code definitely only runs once (since the random number in the notification remains the same).
So why is this happening and how to fix it?
Below is my environment:
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
Try playing in the above environment.
android firebase firebase-cloud-messaging firebase-notifications
Gabbar singh
source share