问题
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 !
What to do please ?
The Code :
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
String title = remoteMessage.getData().get("title");
String message = remoteMessage.getData().get("body");
sendNotification(title,message);
}
I know there are alot of issues published here in Stackoverflow but I've tried their solutions but the problem still exist !
回答1:
Replace
String title = remoteMessage.getData().get("title");
String message = remoteMessage.getData().get("body);
By
String title = remoteMessage.getNotification().getTitle();
String message = remoteMessage.getNotification().getBody();
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.
来源:https://stackoverflow.com/questions/45019915/fcm-onmessagereceived-returns-blank-message-and-title-when-the-app-is-running