Why am I getting several FCM notifications about android 7

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.

+7
android firebase firebase-cloud-messaging firebase-notifications
source share
2 answers

I solved the problem by renaming my application name for example, the old name: com.xyz to com.xyz2

Using the new name, I added this (new) Android application to the firebase project (it generated a new application identifier). And the notifications started working as expected (don't repeat).

But it's a shame that I need to rename the application package in order to allow it. If this application was released on Google Play, I could not rename the application, otherwise no one will be able to receive additional updates in this application, and this will become a new application!

It would be great if some firebase developers could shed light on what is happening.

Recreating the firebase project and recreating the Android project did not help when the application / top-level package name was the same. Currently fixed a change in the application name and corresponding namespaces in an existing Android project.

Ideally, I would like to know the correct fix for this and use the existing name, not the suffix 2 at the end of the application name.

+1
source share

I had the same problem with my Ionic Android app. The same notification is repeated after 2, 4 and 8 minutes. This seems like a problem on the client side because it happens even when sending a message directly from the Firebase console.

I tried several things to fix this, and it seems that the only way to make it work as intended is to create a new Android project and a new Firebase application.

+1
source share

All Articles