FCM onMessageReceived在应用程序运行时返回空白消息和标题 [英] FCM onMessageReceived Returns blank message and title when the app is running

查看:143
本文介绍了FCM onMessageReceived在应用程序运行时返回空白消息和标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如您在标题中所写,当应用程序关闭时,它运行良好,并且onMessageReceived获取消息正文和标题,但是如果应用程序处于前台模式(运行模式),则可以发送通知,但不发送消息和标题!

As you wrote in the title , when the application is closed it's working well and the onMessageReceived gets the message body and the title but if the app is in the foreground mode (running mode) the notifications can be sent but without message and title !

该怎么办?

代码:

@Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        super.onMessageReceived(remoteMessage);

        String title = remoteMessage.getData().get("title");
        String message = remoteMessage.getData().get("body");
        sendNotification(title,message);
    }

我知道Stackoverflow此处发布了很多问题,但是我已经尝试了它们的解决方案,但是问题仍然存在!

I know there are alot of issues published here in Stackoverflow but I've tried their solutions but the problem still exist !

推荐答案

替换

String title = remoteMessage.getData().get("title");
String message = remoteMessage.getData().get("body);

通过

String title = remoteMessage.getNotification().getTitle();
String message = remoteMessage.getNotification().getBody();

您使用的是发送通知时设置为键值对的数据有效负载.您可以在Firebase通知控制台的Advanced Options部分下的Custom Data下找到它们的输入字段.

What you used is for data payload that you set as key-value pair while sending a notification. You may find input fields for them under Advanced Options section as Custom Data in firebase notification console.

这篇关于FCM onMessageReceived在应用程序运行时返回空白消息和标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆