问题描述
我编写了一个非常简单的 android 应用程序来测试 firebase 推送通知,我收到了两次通知.
I wrote a very simple android app to test firebase push notification and I get one notification twice.
这是清单服务:
<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>
这是应用程序 gradle:
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'
这是项目级别的gradle:
and here is the project level 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
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
来自 firebase-massaging 的 FCM 会自动注册一个实例 ID 令牌(设备 ID),因此如果您有在应用中注册令牌的逻辑,则您可能会注册两次.这可能会导致您收到多个通知.更一般地说,尽管出于这个原因,您不应该在同一个应用程序中使用 FCM 和 GCM.因此,如果您要使用 FCM,您应该从您的应用中移除 GCM.
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.
此外,使用 play-services 包括所有 play-services-x API,例如 play-services-gcm 和 play-services-drive 等.所以请始终使用拆分库,例如 play-services-x 而不仅仅是 play-services.
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 两次发送推送通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!


大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)