Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase send push notification twice

I wrote a very simple android app to test firebase push notification and I get one notification twice.

this is the manifest service:

<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 the app gradle:

    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 project level gradle:

classpath 'com.google.gms:google-services:3.0.0'
like image 218
Siavash Abdoli Avatar asked Jul 03 '16 05:07

Siavash Abdoli


1 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 an Instance ID token (device ID) so if you have logic that registers for a token in your app it is likely that you are registering twice. This could account for you receiving multiple notifications. More generally though you should not use FCM and GCM in the same app for exactly this reason. So if you are going to use FCM you should remove GCM from your app.

Also, using play-services includes all the play-services-x APIs like play-services-gcm and play-services-drive etc. So always use the split libraries like play-services-x instead of just play-services.

like image 59
Arthur Thompson Avatar answered Sep 19 '22 15:09

Arthur Thompson