Firebase 两次发送推送通知

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

问题描述

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

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

How to target newer versions in .gitlab-ci.yml using auto devops (java 11 instead of 8 and Android 31 instead of 29)(如何在.gitlab-ci.yml中使用自动开发工具(Java 11而不是8,Android 31而不是29)瞄准较新的版本)
Android + coreLibraryDesugaring: which Java 11 APIs can I expect to work?(Android+core LibraryDesugering:我可以期待哪些Java 11API能够工作?)
How to render something in an if statement React Native(如何在If语句中呈现某些内容Reaction Native)
How can I sync two flatList scroll position in react native(如何在本机Reaction中同步两个平面列表滚动位置)
Using Firebase Firestore in offline only mode(在仅脱机模式下使用Firebase FiRestore)
Crash on Google Play Pre-Launch Report: java.lang.NoSuchMethodError(Google Play发布前崩溃报告:java.lang.NoSuchMethodError)