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

  • <legend id='iIOqd'><style id='iIOqd'><dir id='iIOqd'><q id='iIOqd'></q></dir></style></legend>
      <bdo id='iIOqd'></bdo><ul id='iIOqd'></ul>
  • <tfoot id='iIOqd'></tfoot>

  • <small id='iIOqd'></small><noframes id='iIOqd'>

        当应用程序处于前台时如何处理 Firebase 通知

        How to handle the Firebase notification when app is in foreground(当应用程序处于前台时如何处理 Firebase 通知)

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

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

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

                  <tbody id='S46Xq'></tbody>
                • <tfoot id='S46Xq'></tfoot>

                  本文介绍了当应用程序处于前台时如何处理 Firebase 通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我已将 Firebase 云消息传递与我的应用程序集成.当我从 Firebase 控制台发送通知时,如果应用程序在后台或未打开,我会成功收到通知,否则,如果应用程序在前台或已打开,我没有收到它.

                  I have integrated Firebase Cloud Messaging with my application. When I sent a notification from the Firebase console, if the app is in background or not opened I receive successfully the notification, otherwise if the app is in foreground or opened, I did not receive it.

                  感谢所有建议.

                  推荐答案

                  应用在前台时,不会自己生成通知.您需要编写一些额外的代码.收到消息时,会调用 onMessageReceived() 方法,您可以在其中生成通知.代码如下:

                  When app is in foreground, notifications are not generated themselves. You need to write some additional code. When message is received onMessageReceived() method is called where you can generate the notification. Here is the code:

                  public class MyFirebaseMessagingService extends FirebaseMessagingService {
                      @Override
                      public void onMessageReceived(RemoteMessage remoteMessage) {
                          super.onMessageReceived(remoteMessage);
                          Log.d("msg", "onMessageReceived: " + remoteMessage.getData().get("message"));
                          Intent intent = new Intent(this, MainActivity.class);
                          intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                          PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);
                          String channelId = "Default";
                          NotificationCompat.Builder builder = new  NotificationCompat.Builder(this, channelId)
                                  .setSmallIcon(R.mipmap.ic_launcher)
                                  .setContentTitle(remoteMessage.getNotification().getTitle())
                                  .setContentText(remoteMessage.getNotification().getBody()).setAutoCancel(true).setContentIntent(pendingIntent);;
                          NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
                          if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
                              NotificationChannel channel = new NotificationChannel(channelId, "Default channel", NotificationManager.IMPORTANCE_DEFAULT);
                              manager.createNotificationChannel(channel);
                          }
                          manager.notify(0, builder.build());
                      }
                  }
                  

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

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

                  相关文档推荐

                  When does a FCM token expire?(FCM 令牌何时到期?)
                  Firebase Cloud Messaging (FCM) - Launch Activity when user clicks the notification with extras(Firebase Cloud Messaging (FCM) - 当用户点击带有附加功能的通知时启动活动)
                  Implement Firebase inside of a Library(在库中实现 Firebase)
                  Firebase Backward compatibility with GCM(Firebase 与 GCM 的向后兼容性)
                  Receiving the FCM notifications multiple times on Nougat(在 Nougat 上多次接收 FCM 通知)
                  Push Notifications are delivered but didReceiveRemoteNotification is never called Swift(推送通知已交付,但 didReceiveRemoteNotification 从未被称为 Swift)
                      <legend id='I6TPo'><style id='I6TPo'><dir id='I6TPo'><q id='I6TPo'></q></dir></style></legend>
                    • <i id='I6TPo'><tr id='I6TPo'><dt id='I6TPo'><q id='I6TPo'><span id='I6TPo'><b id='I6TPo'><form id='I6TPo'><ins id='I6TPo'></ins><ul id='I6TPo'></ul><sub id='I6TPo'></sub></form><legend id='I6TPo'></legend><bdo id='I6TPo'><pre id='I6TPo'><center id='I6TPo'></center></pre></bdo></b><th id='I6TPo'></th></span></q></dt></tr></i><div id='I6TPo'><tfoot id='I6TPo'></tfoot><dl id='I6TPo'><fieldset id='I6TPo'></fieldset></dl></div>

                      <tfoot id='I6TPo'></tfoot>

                            <bdo id='I6TPo'></bdo><ul id='I6TPo'></ul>
                              <tbody id='I6TPo'></tbody>

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