我写了一个非常简单的 android 应用程序来测试 firebase 推送通知,我收到了两次通知。
这是 list 服务:
<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:
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:
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-消息:9.0.0
来自 firebase-massaging 的 FCM 会自动注册一个实例 ID token (设备 ID),因此如果您有在您的应用程序中注册 token 的逻辑,那么您很可能会注册两次。这可能会导致您收到多个通知。更一般地说,正是出于这个原因,您不应该在同一个应用程序中使用 FCM 和 GCM。因此,如果您打算使用 FCM,则应从您的应用中移除 GCM。
此外,使用 play-services 包括所有 play-services-x API,如 play-services-gcm 和 play-services-drive 等。所以总是使用像 play-services-x 这样的拆分库,而不仅仅是 play-services .
关于android - Firebase 发送推送通知两次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38167125/