在后台应用时未收到Firebase云消息传递

mui*_*lpp 6 android firebase firebase-cloud-messaging

我最近更新了我的应用程序,通过FCM发送消息,当应用程序在Jelly Bean上运行时,它运行良好.问题是,它不是棒棒糖和应用程序在后台.

我阅读了文档,并指出当有效载荷是数据消息时,它将由onMessageReceived()处理.我发送数据有效负载,而不是通知,只要它是JellyBean就可以正确处理.对于Lollipop,它仅在应用程序位于前台时处理消息.如果没有,没有任何反应.

这就是我的FirebaseMessagingService的开头如下所示:

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();
        .....
    }
}
Run Code Online (Sandbox Code Playgroud)

清单:

<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>
Run Code Online (Sandbox Code Playgroud)

有效载荷:

{ 
    "data": {
        "test": "test"
    },
    "to" : "MY FCM REGISTRATION ID"
}
Run Code Online (Sandbox Code Playgroud)

哪个通过POST发送到https://fcm.googleapis.com/fcm/send,其中包含Authorization和Content-type标头.

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

mui*_*lpp 14

好的,原来华为有一些节电功能导致某些应用无法接收通知,因此它与Android版本无关.

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

更多信息在这里.

  • 针对华为设备的每个人的有用信息.所有华为设备都受此"功能"的影响吗? (2认同)