Reputation: 14499
When user clicks a Firebase Notification in Android, you can get the following keys
google.sent_time
(long) from
(string) google.message_id
(String)collapse_key
(String)with the following code:
if (getIntent().getExtras() != null) {
for (String key : getIntent().getExtras().keySet()) {
String value = getIntent().getExtras().getString(key);
Log.d(TAG, "Key: " + key + " Value: " + value);
}
}
However, I need to get the Body
from the message. Is it possible?
Upvotes: 3
Views: 2180
Reputation: 9225
Not if the app is in the background, the values defined in the notification payload are really for the purposes of generating a notification. If you want access to the values that are defined in the notification payload of the message then you should repeat them in the data payload so when the user taps on the notification you will be able to retrieve them from the extras of the intent. Something like:
{
"to": "/topics/sometopic",
"notification": {
"title": "some title",
"body": "some body"
},
"data": {
"noti_title": "some title",
"noti_body": "some body",
"other_key": "other value"
}
}
Upvotes: 3
Reputation: 7720
You have to handle the notification manually, just follow this guide.
To get the notification body, call remoteMessage.getNotification().getBody()
in the onMessageReceived
method.
And then when showing the notification (look at this file), add the body as extra to the intent.
intent.putExtra("body", notificationBody);
intent.putExtra("title", notificationTitle);
Hope this helps :)
Upvotes: -1