我编写了一个非常简单的 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 两次发送推送通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!