FCM onMessageReceived在应用程序运行时返回空白消息和标题 [英] FCM onMessageReceived Returns blank message and title when the app is running
问题描述
正如您在标题中所写,当应用程序关闭时,它运行良好,并且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屋!