<legend id='XOynz'><style id='XOynz'><dir id='XOynz'><q id='XOynz'></q></dir></style></legend>
      <i id='XOynz'><tr id='XOynz'><dt id='XOynz'><q id='XOynz'><span id='XOynz'><b id='XOynz'><form id='XOynz'><ins id='XOynz'></ins><ul id='XOynz'></ul><sub id='XOynz'></sub></form><legend id='XOynz'></legend><bdo id='XOynz'><pre id='XOynz'><center id='XOynz'></center></pre></bdo></b><th id='XOynz'></th></span></q></dt></tr></i><div id='XOynz'><tfoot id='XOynz'></tfoot><dl id='XOynz'><fieldset id='XOynz'></fieldset></dl></div>
        <tfoot id='XOynz'></tfoot>
        • <bdo id='XOynz'></bdo><ul id='XOynz'></ul>
      1. <small id='XOynz'></small><noframes id='XOynz'>

        当应用程序处于后台时,FCM 显示重复通知

        FCM showing duplicate notification when app is in background(当应用程序处于后台时,FCM 显示重复通知)

        <legend id='Eqsx7'><style id='Eqsx7'><dir id='Eqsx7'><q id='Eqsx7'></q></dir></style></legend>

        1. <tfoot id='Eqsx7'></tfoot>
            <bdo id='Eqsx7'></bdo><ul id='Eqsx7'></ul>

                <i id='Eqsx7'><tr id='Eqsx7'><dt id='Eqsx7'><q id='Eqsx7'><span id='Eqsx7'><b id='Eqsx7'><form id='Eqsx7'><ins id='Eqsx7'></ins><ul id='Eqsx7'></ul><sub id='Eqsx7'></sub></form><legend id='Eqsx7'></legend><bdo id='Eqsx7'><pre id='Eqsx7'><center id='Eqsx7'></center></pre></bdo></b><th id='Eqsx7'></th></span></q></dt></tr></i><div id='Eqsx7'><tfoot id='Eqsx7'></tfoot><dl id='Eqsx7'><fieldset id='Eqsx7'></fieldset></dl></div>

                <small id='Eqsx7'></small><noframes id='Eqsx7'>

                    <tbody id='Eqsx7'></tbody>
                • 本文介绍了当应用程序处于后台时,FCM 显示重复通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我在我的项目中实施了 FCM.推送通知按预期工作,收到通知时调用 onMessageReceived.当应用程序在前台时是这样.

                  I implemented FCM in my project. Push notification is working as expected, onMessageReceived is called when a notification is received. This is true when app is in the foreground.

                  但是,当应用程序在后台时,系统托盘总是在一个到达时显示重复的通知(例如,当收到通知 A 时,系统托盘显示 2 个通知 A)

                  However, when the app is in the background, the system tray always display a duplicate notification when one arrives (e.g. when Notification A is received, system tray display 2 Notification A)

                  如何解决这个问题?

                  添加代码

                  我扩展了 FirebaseMessagingService 类,并在 onMessageReceived 方法中有这个

                  I extended FirebaseMessagingService class and have this in the onMessageReceived method

                  这是项目中我使用 NotificationManager 的唯一部分.

                  This is the only part in the project where I used NotificationManager.

                  另外,我尝试在此方法上添加日志.当应用程序在前台时调用 onMessageReceived.应用在后台时不会被调用

                  Also, I tried to add a log on this method. onMessageReceived is called when app is in foreground. It doesn't get called when app is in background

                  @Override
                  public void onMessageReceived(RemoteMessage remoteMessage)
                  {
                      RemoteMessage.Notification notification = remoteMessage.getNotification();
                  
                          Intent intent = new Intent(this, MainActivity.class);
                          intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                          PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
                                  PendingIntent.FLAG_ONE_SHOT);
                  
                          String title = notification.getTitle();
                          String message = notification.getBody();
                  
                          NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
                                  .setSmallIcon(R.mipmap.ic_launcher)
                                  .setContentTitle(title)
                                  .setContentText(message)
                                  .setAutoCancel(true)
                                  .setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE)
                                  .setContentIntent(pendingIntent);
                  
                  
                          NotificationManager notificationManager =
                                  (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
                  
                          notificationManager.notify(0, notificationBuilder.build());
                  }
                  

                  推荐答案

                  同样的问题.我修改了 AndroidManifest.xml,因为我正在像这样请求对旧 GCM 的权限...

                  Same problem. I modified AndroidManifest.xml because i was requesting permissions to old GCM like this...

                  <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" />
                  

                  所以,从清单中删除它并卸载并重新安装应用程序,我的问题就解决了.

                  So, removing it from manifest and uninstalling and reinstalling the app my problem was solved.

                  这篇关于当应用程序处于后台时,FCM 显示重复通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  How can I use CClistview in COCOS2d Android?(如何在 COCOS2d Android 中使用 CClistview?)
                  cocos2d-android: how to display score(cocos2d-android:如何显示分数)
                  Sqlite database not copied from asset folder Android(Sqlite 数据库未从资产文件夹 Android 复制)
                  SQLite Database Copy Appears Corrupted When Generated by Device and not Emulator(SQLite 数据库副本在由设备而不是模拟器生成时出现损坏)
                  Android file copy(安卓文件拷贝)
                  Android how to detect Copy event of Edittext in android(Android如何在android中检测Edittext的Copy事件)
                • <small id='1aCUW'></small><noframes id='1aCUW'>

                    • <i id='1aCUW'><tr id='1aCUW'><dt id='1aCUW'><q id='1aCUW'><span id='1aCUW'><b id='1aCUW'><form id='1aCUW'><ins id='1aCUW'></ins><ul id='1aCUW'></ul><sub id='1aCUW'></sub></form><legend id='1aCUW'></legend><bdo id='1aCUW'><pre id='1aCUW'><center id='1aCUW'></center></pre></bdo></b><th id='1aCUW'></th></span></q></dt></tr></i><div id='1aCUW'><tfoot id='1aCUW'></tfoot><dl id='1aCUW'><fieldset id='1aCUW'></fieldset></dl></div>

                          <bdo id='1aCUW'></bdo><ul id='1aCUW'></ul>
                          <legend id='1aCUW'><style id='1aCUW'><dir id='1aCUW'><q id='1aCUW'></q></dir></style></legend>
                          <tfoot id='1aCUW'></tfoot>
                              <tbody id='1aCUW'></tbody>