FCM onMessageReceived Returns blank message and title when the app is running

时光总嘲笑我的痴心妄想 提交于 2020-01-13 02:14:46

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!