正如您在标题中所写,当应用程序关闭时它运行良好并且 onMessageReceived
获取消息正文和标题但是如果应用程序处于前台模式(运行模式)则通知可以发送但没有消息和标题!
请问怎么办?
代码:
@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 中发布了很多问题,但我已经尝试了他们的解决方案,但问题仍然存在!
最佳答案
替换
String title = remoteMessage.getData().get("title");
String message = remoteMessage.getData().get("body);
通过
String title = remoteMessage.getNotification().getTitle();
String message = remoteMessage.getNotification().getBody();
您使用的是您在发送通知时设置为键值对的数据负载。您可以在 Advanced Options
部分下找到它们的输入字段作为 firebase 通知控制台中的 Custom Data
。
关于android - FCM onMessageReceived 在应用程序运行时返回空白消息和标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45019915/