android - remoteMessage.getMessageType 在 onMessageReceived 中返回 null

标签 android firebase firebase-cloud-messaging

public class FirebaseMessagingService extends com.google.firebase.messaging.FirebaseMessagingService{

    String TAG = "FirebaseMessagingService";
    @Override
    public void onMessageReceived(RemoteMessage remoteMessage){

        Log.i(TAG," input string :"+ String.valueOf(remoteMessage.getData()));
        /**
         * Parse remote input and pass id, action, frequency and payload to eventHandler.
         * **/

        String messageType = remoteMessage.getMessageType();// messageType is null always
        if(messageType.equalsIgnoreCase("Data")){
            Log.i(TAG, " Data notification received");
        }
        else if(messageType.equalsIgnoreCase("Notification")){
            Log.i(TAG, " Push notification received");
        }
}

最佳答案

我不确定 getMessageType() 应该返回什么。但它似乎不太可能返回 DataNotification,因为 a single message can contain both notification and data information .

关于android - remoteMessage.getMessageType 在 onMessageReceived 中返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38405281/

相关文章:

android - 如何将 Android 库发布到 Maven 存储库以方便使用?

java - 使用 SQLite 创建表时出错

java - 如何从 firebase 获取 json 列的名称?我在问题下面留下了一个例子

firebase - 错误 : Failed to create project. 有关详细信息,请参阅 firebase-debug.log

ios - 无法将字符串从 Firebase 数据库闭包 block 快速传递给公共(public)变量

android - 无法在动态添加布局的android中使用findViewById找到单选按钮

android - 完成对话框和 Activity

ios - “证书 bundleId 与您应用的证书不匹配”Firebase 云消息传递

node.js - 如何同时使用 "web-push"和 "fcm-push" Node 包?

ios - swift 2.3 中的 Xcode 8.1 推送通知与 firebase 集成没有得到?