Firebase发送推送通知两次 [英] Firebase send push notification twice

查看:186
本文介绍了Firebase发送推送通知两次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个非常简单的android应用程序来测试firebase推送通知,并且我得到了两次通知。

这是清单服务:

 < 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>

这是app gradle:

  compile'c​​om.google.android.gms:play-services:9.0.0'
compile'c​​om.google.firebase:firebase-core:9.0.0'
编译'com.google.firebase:firebase-messaging:9.0.0'
}
apply plugin:'com.google.gms.google-services'

这里是项目级gradle:

  classpath'com.google.gms:google-services:3.0.0'


解决方案

看起来您正在使用 com.google.android.gms:play-services:9.0.0 (其中包括play-services-gcm)和 com.google.firebase:firebase-messaging:9.0.0



来自firebase-massaging的FCM会自动注册一个实例ID令牌(设备ID),所以如果你有在你的应用程序注册一个令牌的逻辑,它可能是你注册两次。这可能会导致您收到多个通知。更一般的,虽然你不应该在同一个应用程序中使用FCM和GCM正是因为这个原因。所以,如果你要使用FCM,你应该从你的应用程序中删除GCM。

另外,使用play-services包括所有的play-services-x A​​PI,例如play-services -gcm和play-services-drive等。所以总是使用像play-services-x这样的分割库,而不仅仅是play-services。

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'

解决方案

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.

这篇关于Firebase发送推送通知两次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆