在牛轧糖上多次接收FCM通知 [英] Receiving the FCM notifications multiple times on Nougat

查看:137
本文介绍了在牛轧糖上多次接收FCM通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用中使用Firebase推送通知.但是,当我为某个事件发送通知时,仅在牛轧糖设备上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" />

)

还要确保您清洁您的项目并重建该项目,以删除对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.

这篇关于在牛轧糖上多次接收FCM通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆