Receive FCM notifications multiple times at Nougat

I am using Firebase push notifications in my application. But when I send a notification for an event, I get a notification several times in 2-3 minutes only on Nougat devices . I get only one notification on devices that have a lower version than Nougat.

I checked that the server sends only one notification at a time. I have a dependency below in my gradle application.

compile `com.google.firebase:firebase-messaging:11.8.0` 

And here is the code for the FCM listener:

 public class MyFcmListenerService extends FirebaseMessagingService { @Override public void onMessageReceived(RemoteMessage remoteMessage) { } } 

In the manifest file:

 <service android:name="com.myApp.test.fcm.MyFcmListenerService"> <intent-filter> <action android:name="com.google.firebase.MESSAGING_EVENT" /> </intent-filter> </service> 
+1
source share
2 answers

It started with me when I tried to switch from the old GCM to the new FCM. You must make sure that you delete all GCM-related codes, including gradle (remove com.google.android.gms:play-services-gcm ) and the manifest

(delete:

 <uses-permission android:name="mypackage.permission.C2D_MESSAGE" /> <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /> <permission android:name="mypackage.permission.C2D_MESSAGE" android:protectionLevel="signature" /> 

)

Also make sure you are running CLEAN and REBUILD to remove any cached reference to GCM classes. The last part took me 2 hours to understand. A good trick might be to find all (โ‡งโŒ˜F) "GCMs" and see if you get hits from the generated files.

+4
source

The same thing happened to me, I tried in vain

Then I realized that we store all the fcm tokens of an Android device from start to finish, without checking or deleting them.

I deleted all fcm tokens and re-entered my application, which inserted a new token into the FCM token list in my server database.

This worked fine, I think FCM should invalidate earlier tokens before issuing new ones, even between installations, multiple apk and multiple apk debugging sessions

Try sending only 1 token, also clear the assembly and reinstall the application

0
source

All Articles