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

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

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

        <tfoot id='EE2Zo'></tfoot>
          <bdo id='EE2Zo'></bdo><ul id='EE2Zo'></ul>

        活动是否在后台时,Firebase 通知不起作用

        时间:2023-07-28
        <tfoot id='XYqeK'></tfoot>
        <i id='XYqeK'><tr id='XYqeK'><dt id='XYqeK'><q id='XYqeK'><span id='XYqeK'><b id='XYqeK'><form id='XYqeK'><ins id='XYqeK'></ins><ul id='XYqeK'></ul><sub id='XYqeK'></sub></form><legend id='XYqeK'></legend><bdo id='XYqeK'><pre id='XYqeK'><center id='XYqeK'></center></pre></bdo></b><th id='XYqeK'></th></span></q></dt></tr></i><div id='XYqeK'><tfoot id='XYqeK'></tfoot><dl id='XYqeK'><fieldset id='XYqeK'></fieldset></dl></div>

            <bdo id='XYqeK'></bdo><ul id='XYqeK'></ul>
              <tbody id='XYqeK'></tbody>
              1. <small id='XYqeK'></small><noframes id='XYqeK'>

                <legend id='XYqeK'><style id='XYqeK'><dir id='XYqeK'><q id='XYqeK'></q></dir></style></legend>
                  本文介绍了活动是否在后台时,Firebase 通知不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我的编码与 firebase 示例代码提供的编码相同.当活动处于前台状态或打开时,它工作正常.但是当活动关闭或处于后台状态时,它就不能正常工作.问题是这样的……

                  I have same coding as provided by firebase sample code. It works fine when activity is in foreground state or opened. But when activity is closed or in background state then it does not work properly. Problem is like that...

                  1. 应用程序图标不显示.

                  1. App icon is not shown of application.

                  默认以应用名称作为通知标题

                  By default take app name as a title of notification

                  当应用程序处于后台状态或未在设备上打开时,会发生时间通知,LogCat 会显示以下详细信息:

                  And when app is in background state or not opened on device that time notification occurs then LogCat shows following details :

                  09-16 15:55:56.056 12113-12113/com.testdemofb D/FirebaseApp: com.google.firebase.auth.FirebaseAuth is not linked. Skipping initialization.
                  09-16 15:55:56.089 12113-12113/com.testdemofb D/FirebaseApp: com.google.firebase.crash.FirebaseCrash is not linked. Skipping initialization.
                  09-16 15:55:56.176 12113-12113/com.testdemofb I/FA: App measurement is starting up, version: 9452
                  09-16 15:55:56.177 12113-12113/com.testdemofb I/FA: To enable debug logging run: adb shell setprop log.tag.FA VERBOSE
                  09-16 15:55:56.286 12113-12113/com.testdemofb I/FirebaseInitProvider: FirebaseApp initialization successful
                  09-16 15:55:56.518 12113-12147/com.testdemofb I/FA: Tag Manager is not found and thus will not be used
                  

                  如果有任何解决方案,请帮助我

                  if any solution for that then help me

                  谢谢...

                  MyFirebaseMessagingService.java

                  MyFirebaseMessagingService.java

                  package com.testdemofb;
                  
                  import android.app.Notification;
                  import android.app.NotificationManager;
                  import android.app.PendingIntent;
                  import android.content.BroadcastReceiver;
                  import android.content.Context;
                  import android.content.Intent;
                  import android.graphics.Bitmap;
                  import android.graphics.BitmapFactory;
                  import android.graphics.Color;
                  import android.media.RingtoneManager;
                  import android.net.Uri;
                  import android.support.v4.app.NotificationCompat;
                  import android.util.Log;
                  import android.widget.Toast;
                  
                  import com.google.firebase.messaging.FirebaseMessagingService;
                  import com.google.firebase.messaging.RemoteMessage;
                  
                  public class MyFirebaseMessagingService extends FirebaseMessagingService {
                  
                  private static final String TAG = "MyFirebaseMsgService";
                  
                  
                  @Override
                  public void onMessageReceived(RemoteMessage remoteMessage) {
                  
                      // Check if message contains a data payload.
                      if (remoteMessage.getData().size() > 0) {
                          Log.d(TAG, "Message data payload: " + remoteMessage.getData());
                          sendNotification(remoteMessage.getData().get("title"));
                      }
                  
                      // Check if message contains a notification payload.
                      if (remoteMessage.getNotification() != null) {
                          Log.d(TAG, "Message Notification Body: " + remoteMessage.getNotification().getBody());
                          Log.d(TAG, "Message Notification BodyLocalize: " + remoteMessage.getNotification().getBodyLocalizationKey());
                          Log.d(TAG, "Message Notification Title: " + remoteMessage.getNotification().getTitle());
                          Log.d(TAG, "Message Notification TitleLocalize: " + remoteMessage.getNotification().getTitleLocalizationKey());
                          sendNotification(remoteMessage.getNotification().getBody());
                      }
                  
                  
                  }
                  
                  private void sendNotification(String messageBody) {
                      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);
                  
                      Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
                      Bitmap bm = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher);
                      NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
                              .setLargeIcon(bm)
                              .setSmallIcon(R.mipmap.ic_launcher)
                              .setContentTitle("Title")
                              .setContentText(messageBody)
                              .setAutoCancel(true)
                              .setSound(defaultSoundUri)
                              .setContentIntent(pendingIntent);
                  
                      NotificationManager notificationManager =
                              (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
                  
                      notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
                  
                  }
                  }
                  

                  AndroidManifest.xml 文件放在 application 标签之间...

                  AndroidManifest.xml file put like this between application tag...

                      <service android:name=".MyFirebaseMessagingService"
                          android:process="remote">
                          <intent-filter>
                              <action android:name="com.google.firebase.MESSAGING_EVENT" />
                          </intent-filter>
                      </service>
                  
                      <service android:name=".MyFirebaseInstanceIDService" >
                          <intent-filter>
                              <action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
                          </intent-filter>
                      </service>
                  

                  推荐答案

                  FCM 使用两种类型的消息,即.通知和数据.在此处了解更多信息.我认为您正在发送通知.您需要发送数据消息.

                  There are two types of messages that FCM uses, viz. notification and data. Read more about it here. I think you are sending a notification. You need to send a data message.

                  类似的东西.

                  {
                  "to" : "bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...",
                     "data" : {
                   "Nick" : "Mario",
                   "body" : "great match!",
                   "Room" : "PortugalVSDenmark"
                  },
                  }
                  

                  这篇关于活动是否在后台时,Firebase 通知不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:Android Firebase 消息传递 SDK 如何防止 Intent 欺骗? 下一篇:想知道 FCM 在以下场景中的工作原理

                  相关文章

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

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

                    <bdo id='fLTvT'></bdo><ul id='fLTvT'></ul>