在 Nougat 上多次接收 FCM 通知

Receiving the FCM notifications multiple times on Nougat(在 Nougat 上多次接收 FCM 通知)
本文介绍了在 Nougat 上多次接收 FCM 通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用中使用 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 通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

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

相关文档推荐

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)