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

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

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

        应用程序在后台时未收到 Firebase 云消息

        时间:2023-07-29
          <bdo id='d0GPE'></bdo><ul id='d0GPE'></ul>
        • <legend id='d0GPE'><style id='d0GPE'><dir id='d0GPE'><q id='d0GPE'></q></dir></style></legend>

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

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

                    <tbody id='d0GPE'></tbody>

                1. 本文介绍了应用程序在后台时未收到 Firebase 云消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我最近更新了我的应用程序以通过 FCM 发送消息,当应用程序在 Jelly Bean 上运行时效果很好.问题是,如果它是 Lollipop 并且应用程序位于 背景 中,则它不会.

                  I recently updated my app to send messages through FCM and it works great when the app is run on Jelly Bean. The problem is it doesn't in case it's Lollipop and the app is in the background.

                  我阅读了 文档,并指出当有效载荷是一条数据消息,它将由 onMessageReceived() 处理.我正在发送一个数据负载,不是通知,只要它是 JellyBean,它就会被正确处理.对于 Lollipop,它仅在应用程序位于前台时处理消息.如果没有,什么都不会发生.

                  I read the documentation and it's stated that when the payload is a data message, it will be handled by onMessageReceived(). I am sending a data payload, not a notification, and it's handled correctly as long as it's JellyBean. For Lollipop it only handles the message if the app is in the foreground. If not, nothing happens.

                  这就是我的 FirebaseMessagingService 开头的样子:

                  This is how the beginning of my FirebaseMessagingService looks like:

                  public class FirebaseBroadcastReceiverService extends FirebaseMessagingService {
                      private final String TAG = FirebaseBroadcastReceiverService.class.getName();
                  
                      @Override
                      public void onMessageReceived(RemoteMessage message){
                          Log.i(TAG, "A message is received");
                          String from = message.getFrom();
                          Map<String, String> data = message.getData();
                          .....
                      }
                  }
                  

                  清单:

                  <application
                      android:name=".controller.application.AppResources"
                      android:allowBackup="true"
                      android:icon="@mipmap/ic_launcher_shadow"
                      android:label="@string/app_name"
                      android:supportsRtl="true"
                      android:theme="@android:style/Theme.Black.NoTitleBar">
                  
                     <service
                          android:name=".model.firebase.FirebaseListenerService">
                          <intent-filter>
                              <action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
                          </intent-filter>
                      </service>
                      <service android:name=".model.firebase.FirebaseBroadcastReceiverService">
                          <intent-filter>
                              <action android:name="com.google.firebase.MESSAGING_EVENT" />
                          </intent-filter>
                      </service>
                      .......
                  </application>
                  

                  还有有效载荷:

                  { 
                      "data": {
                          "test": "test"
                      },
                      "to" : "MY FCM REGISTRATION ID"
                  }
                  

                  通过 POST 发送到 https://fcm.googleapis.com/fcm/使用 Authorization 和 Content-type 标头发送.

                  Which is sent via POST to https://fcm.googleapis.com/fcm/send with the Authorization and Content-type headers.

                  我可能已经阅读了与此相关的所有其他 SO 线程,但我找不到答案,而且 Android 监视器中也没有日志跟踪.有人对此有提示吗?

                  I might have read all other SO threads related to this but I couldn't find an answer to it and there are also no log traces in the Android Monitor. Does anyone have a hint on this?

                  推荐答案

                  好吧,原来华为有一些省电功能,导致某些应用无法接收通知,所以与安卓版本无关.

                  Ok, turns out Huawei has some power-saving features which cause that some apps won't be able to receive notifications, so it's not related to the Android version.

                  我找不到以编程方式解决此问题的方法,但如果有人感兴趣,请转到设置/受保护的应用程序并选择您希望允许在后台运行的应用程序,以便他们接收通知.

                  I couldn't find a way to fix this programmatically, but if anyone's interested, go to Settings / Protected apps and select the apps you want to allow to be run on the background, so they receive notifications.

                  更多信息这里.

                  这篇关于应用程序在后台时未收到 Firebase 云消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:Firebase 云消息传递 API 密钥 下一篇:应用程序在 iOS 10 中处于后台时未收到推送通知

                  相关文章

                    <legend id='6jSOZ'><style id='6jSOZ'><dir id='6jSOZ'><q id='6jSOZ'></q></dir></style></legend>
                    <tfoot id='6jSOZ'></tfoot>
                  1. <small id='6jSOZ'></small><noframes id='6jSOZ'>

                    • <bdo id='6jSOZ'></bdo><ul id='6jSOZ'></ul>

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