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

  • <legend id='77KNg'><style id='77KNg'><dir id='77KNg'><q id='77KNg'></q></dir></style></legend>

      <small id='77KNg'></small><noframes id='77KNg'>

      1. Firebase 通知和数据

        Firebase Notification and Data(Firebase 通知和数据)

            <tfoot id='FeEPm'></tfoot>

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

                  <tbody id='FeEPm'></tbody>
                • <legend id='FeEPm'><style id='FeEPm'><dir id='FeEPm'><q id='FeEPm'></q></dir></style></legend>
                  本文介绍了Firebase 通知和数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在使用 Firebase 云消息传递 API 创建应用程序...我能够从服务器向我的客户端应用程序发送通知和数据.但问题是当应用程序打开时,数据出现时通知没有触发(我的意思是我记录了它)这不是问题.但是当应用程序关闭时,会收到通知,当我单击通知时,活动已打开,而我看不到日志数据.我需要将数据更新到 TextView..

                  I am Creating an App using Firebase cloud messaging API... I am able to send notification and data to my client application from the server. But the problem is When the application is open the notification is not firing while the data appears (I Mean I logged it) It is not an issue. But when the application is closed, the notification is received, while I clicked on notification the activity is opened while I am not able to see the log data. I need to Update the data to a TextView..

                  我的 MyFirebaseMessagingService :

                  My MyFirebaseMessagingService :

                  public void onMessageReceived(RemoteMessage remoteMessage) {
                          // TODO: Handle FCM messages here.
                          // If the application is in the foreground handle both data and notification messages here.
                          // Also if you intend on generating your own notifications as a result of a received FCM
                          // message, here is where that should be initiated.
                          Log.d(TAG, "From: " + remoteMessage.getFrom());
                          Log.d(TAG, "Notification Message Body: " + remoteMessage.getNotification().getBody());
                          Log.e("FROM", "From: " + remoteMessage.getFrom());
                          String data = remoteMessage.getData().get("message");
                          Log.e("KOIII", "Notification Message Body: " + remoteMessage.getNotification().getBody());
                         // showNotificationS(remoteMessage.getNotification().getBody(),2);
                          if(data.equals("true")){
                              Log.e("DATA", "SUCCESS");
                             // Fragment1.getInstace().updateTheTextView(data, data, data);
                          }
                      }
                  

                  我的清单:

                  <activity
                              android:name=".SplashScreen"
                              android:label="@string/app_name"
                              android:launchMode="singleInstance">
                              <intent-filter>
                                  <action android:name="android.intent.action.MAIN" />
                  
                                  <category android:name="android.intent.category.LAUNCHER" />
                              </intent-filter>
                          </activity>
                          <activity
                              android:name=".myHome"
                              android:label="@string/app_name">
                          </activity>
                  <service android:name=".MyFirebaseMessagingService">
                              <intent-filter>
                                  <action android:name="com.google.firebase.MESSAGING_EVENT"/>
                              </intent-filter>
                          </service>
                          <service android:name=".FirebaseIDService">
                              <intent-filter>
                                  <action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
                              </intent-filter>
                          </service>
                  

                  推荐答案

                  如果您的应用在前台,FCM 将不会显示通知,因此您手动显示如下:-

                  FCM will not show notification if your app is in foreground, So you have manually show that like this:-

                  @Override
                      public void onMessageReceived(RemoteMessage remoteMessage) {
                          // TODO(developer): Handle FCM messages here.
                          // If the application is in the foreground handle both data and notification messages here.
                          // Also if you intend on generating your own notifications as a result of a received FCM
                          // message, here is where that should be initiated. See sendNotification method below.
                          Log.d(TAG, "From: " + remoteMessage.getFrom());
                          Log.d(TAG, "From: " + remoteMessage.getData().get("message"));
                  //        Log.d(TAG, "Notification Message Body: " + remoteMessage.getNotification().getBody());
                          sendNotification(remoteMessage.getData().get("message"));
                      }
                      // [END receive_message]
                  
                      /**
                       * Create and show a simple notification containing the received FCM message.
                       *
                       * @param messageBody FCM message body received.
                       */
                      private void sendNotification(String messageBody) {
                          Intent intent = new Intent(this, MarketActivity.class);
                  //        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                          PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
                                  PendingIntent.FLAG_ONE_SHOT);
                  
                          Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
                          NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
                                  .setSmallIcon(R.drawable.ic_launcher)
                                  .setContentTitle("Fred Notification")
                                  .setContentText(messageBody)
                                  .setAutoCancel(true)
                                  .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
                                  .setContentIntent(pendingIntent);
                  
                          NotificationManager notificationManager =
                                  (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
                  
                          notificationManager.notify(0 /* ID of notification */, notificationBuilder.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 通知)
                  Firebase FCM MismatchSenderID(Firebase FCM 不匹配SenderID)
                    <tbody id='wJaj6'></tbody>
                    <i id='wJaj6'><tr id='wJaj6'><dt id='wJaj6'><q id='wJaj6'><span id='wJaj6'><b id='wJaj6'><form id='wJaj6'><ins id='wJaj6'></ins><ul id='wJaj6'></ul><sub id='wJaj6'></sub></form><legend id='wJaj6'></legend><bdo id='wJaj6'><pre id='wJaj6'><center id='wJaj6'></center></pre></bdo></b><th id='wJaj6'></th></span></q></dt></tr></i><div id='wJaj6'><tfoot id='wJaj6'></tfoot><dl id='wJaj6'><fieldset id='wJaj6'></fieldset></dl></div>

                      • <bdo id='wJaj6'></bdo><ul id='wJaj6'></ul>

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

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

                            <tfoot id='wJaj6'></tfoot>