Firebase sends push notification twice

I wrote a very simple Android app to test pushbase notification, and get one notification twice.

This is a service shown:

<service android:name="com.google.firebase.messaging.FirebaseMessagingService"> <intent-filter> <action android:name="com.google.firebase.MESSAGING_EVENT"/> </intent-filter> </service> <service android:name="com.google.firebase.iid.FirebaseInstanceIdService"> <intent-filter> <action android:name="com.google.firebase.INSTANCE_ID_EVENT"/> </intent-filter> </service> 

this is gradle application:

  compile 'com.google.android.gms:play-services:9.0.0' compile 'com.google.firebase:firebase-core:9.0.0' compile 'com.google.firebase:firebase-messaging:9.0.0' } apply plugin: 'com.google.gms.google-services' 

and here is the gradle project level:

 classpath 'com.google.gms:google-services:3.0.0' 
+12
source share
7 answers

It looks like you are using com.google.android.gms:play-services:9.0.0 (which includes play-services-gcm) and com.google.firebase:firebase-messaging:9.0.0

FCM from firebase-massaging automatically registers the instance identifier token (device identifier), so if you have logic that registers the token in your application, you are probably registered twice. This may explain the receipt of several notifications. More generally, although you should not use FCM and GCM in the same application for this reason. Therefore, if you intend to use FCM, you must remove GCM from your application.

In addition, the use of game services includes all the play-services-x APIs, such as play-services-gcm and play-services-drive, etc. Therefore, always use split libraries, such as play-services-x, and not just game services.

+9
source

For me, it was the 3rd party sdk that used GCM, while our application used FCM. Registering with both services will give you two notifications.

(I also called super.onMessageReceived(remoteMessage) in my FirebaseMessagingService, causing a third notification to appear: p

+3
source

The accepted answer did not help me. The following is the work:

I used data-messages instead of display-messages , so even if the application is in the foreground or in the background, only one notification will appear.

Replace

 { "to": "/topics/journal", "notification": { "title" : "title", "text": "data!", "icon": "ic_notification" } } 

FROM

 { "to": "/topics/dev_journal", "data": { "text":"text", "title":"", "line1":"Journal", "line2":"刊物" } } 

Link: How to handle application notification in the background in firebase

+1
source

I had the same problem when the application was in the background or closed (and sent both notifications and data). Called by requesting old GCM permissions in AndroidManifest.xml

Take a look at fooobar.com/questions/1007478 / ...

+1
source

use gradle file compile 'com.google.firebase: firebase-core: 10.2.1' in the assembly, compile 'com.google.firebase: firebase-messaging: 10.2.1' and use handleIntent () in the reciver.

0
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

I had to remove

 <receiver android:name="com.google.android.gms.gcm.GcmReceiver" android:exported="true" android:permission="com.google.android.c2dm.permission.SEND"> <intent-filter> <action android:name="com.google.android.c2dm.intent.RECEIVE" /> <category android:name="${applicationId}" /> </intent-filter> </receiver> 

from AndroidManifest.xml

It worked for me, thanks

0
source

All Articles