how get message body when FCM notification message is tap?

半世苍凉 提交于 2019-12-04 07:19:09

try this

  @Override
        public void onMessageReceived(RemoteMessage remoteMessage) {
            // TODO(developer): Handle FCM messages here.
            // If the application is in the foreground handle both data and notification messages here.
            // Also if you intend on generating your own notifications as a result of a received FCM
            // message, here is where that should be initiated. See sendNotification method below.
            Log.d(TAG, "From: " + remoteMessage.getFrom());
            Log.d(TAG, "From: " + remoteMessage.getData().get("message"));
    //        Log.d(TAG, "Notification Message Body: " + remoteMessage.getNotification().getBody());
// if you sending data with custom key
 Log.d(TAG, "Notification Message of custom key: " +remoteMessage.getData().get("your key"));
            sendNotification(remoteMessage.getData().get("message"));
        }

I am sorry but what you are trying to do is not possible.

Currently it's not possible to access the (body, title, icon ...) information of a
notification-message from the activity that is launched when the notification is opened.

You can instead access the data component of the notification message.

One possible alternative is to use data-message messages and create your own custom notification and custom logic.

see notification-message vs data-message here:
https://firebase.google.com/docs/cloud-messaging/concept-options#notifications_and_data_messages

PS: if would be useful if you could report a Feature Request through the firebase support page.
In this way the team can correctly prioritize future features. https://firebase.google.com/support/contact/bugs-features/

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