Firebase Remote消息在remotemessage.getDate()上返回null数据

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Firebase Remote消息在remotemessage.getDate()上返回null数据相关的知识,希望对你有一定的参考价值。

使用FirebaseMessagingService使用php发送远程消息。它工作正常,直到约会,突然app停止接收通知,调试后我发现

onMessegeReceived(remoteMessage)
remoteMessage.getData() returns null Array Map.

但我可以在Bundle中看到有效载荷数据

Bundle[google.delivered_priority=high, google.sent_time=1556008551748, google.ttl=2419200, google.original_priority=high, 
from=982221224130, 
google.message_id=0:1556008551825452%903f05e2903f05e2, 
gcm.notification.data="image":"https:url","nId":1313,"time":"14:05:51","priority":"normal","title":"testttt","message":"","type":"1", google.c.a.e=1, collapse_key=com.sam.grapemundo]

我期望结果remoteMessage.getData()返回

data="image":"https:url","nId":1313,"time":"14:05:51","priority":"normal","title":"testttt","message":"","type":"1", google.c.a.e=1, collapse_key=com.sam.grapemundo]
答案

首先,你必须检查通知是否被解雇: -

@Override
    public void onMessageReceived(RemoteMessage remoteMessage) 
        Log.e(TAG, "From: " + remoteMessage.getFrom());
        Log.e(TAG, "Data Payload: " + remoteMessage.getData().toString());

        if (remoteMessage.getNotification() == null)
            return;
        // Check if message contains a notification payload.
        if(remoteMessage.getNotification() != null) 
            handleNotification(remoteMessage, remoteMessage.getNotification().getBody(), remoteMessage.getNotification().getTitle());
        

以上是关于Firebase Remote消息在remotemessage.getDate()上返回null数据的主要内容,如果未能解决你的问题,请参考以下文章

Firebase onMessageReceived(RemoteMessage remoteMessage),当应用程序在后台时不被调用[重复]

Flutter 2 - firebase_remote_config 0.6.0 & firebase_core ^0.7.0 版本冲突

Firebase Remote Config App Version 条件比较

如何使用 Kotlin 在 Android 中处理从 Firebase Remote Config 解析 JSON 的效果方式?

Akka源码分析-Remote-发消息

Notification.BigPictureStyle不起作用