我在我的应用中使用 Firebase 推送通知.但是,当我发送某个事件的通知时,我会在 Nougat 设备 上 2-3 分钟后多次收到通知.在版本低于 Nougat 的设备上,我只收到一条通知.
I am using Firebase push notifications in my app. But when I am sending a notification for some event, I am getting notification's multiple times after 2-3 minutes on Nougat devices only. I am getting only a single notification on the devices which are having lower version than Nougat.
我检查过服务器一次只发送一个通知.我的应用程序 gradle 有以下依赖项.
I have checked that server is sending only a single notification at a time. I am having below dependency in my app gradle.
compile `com.google.firebase:firebase-messaging:11.8.0`
这是 FCM 监听器的代码:
And here is the code for FCM Listener:
public class MyFcmListenerService extends FirebaseMessagingService {
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
}
}
在清单文件中:
<service android:name="com.myApp.test.fcm.MyFcmListenerService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
当我尝试从旧 GCM 迁移到新 FCM 时,这开始发生在我身上.您需要确保删除所有与 GCM 相关的代码,包括 gradle(删除 com.google.android.gms:play-services-gcm
)和 Manifest
This started happening to me when I tried to migrate from old GCM to new FCM.
You need to make sure you remove all GCM related code, including gradle (remove com.google.android.gms:play-services-gcm
) and Manifest
(删除:
<uses-permission android:name="mypackage.permission.C2D_MESSAGE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission
android:name="mypackage.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
)
还要确保您CLEAN您的项目并REBUILD它,以删除对 GCM 类的任何缓存引用.最后一部分花了我大约 2 个小时才弄清楚.一个不错的技巧是查找所有 (F) "GCM" 并查看是否从生成的文件中获得命中.
Also make sure you CLEAN your project and REBUILD it, to remove any cached reference to GCM classes. The last part took me like 2 hours to figure out. A nice trick can be to find-all (F) "GCM" and see if you get hits from the generated files.
这篇关于在 Nougat 上多次接收 FCM 通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!