My push notification(using FCM) is working correctly in foreground and background state, but in killed state I am able to receive only notification from the system tray but can't get "data payload". I am aware about the fact that onMessageReceived() is not called in killed state(correct me if I am wrong), is there any way to call this method in killed state as well or any other way to get "data payload". Please help!
How can I get "data payload" from push notification (using FCM) when android app is in killed state?
Asked
Active
Viewed 6,744 times
1
-
2See my answer [here](https://stackoverflow.com/a/39505298/4625829) for some additional details. If you are able to receive push notifications (even just through the System Tray -- which means you have the `notification` message payload as well), then you should be able to retrieve the `data` payload details from the intent after clicking on the notification. See my answer [here](https://stackoverflow.com/a/41458543/4625829) as well – AL. Jun 30 '17 at 10:51
3 Answers
1
I have the perfect Solution for you :
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
Log.e("FCM_MESSAGE", remoteMessage.getData().toString());
Map<String, String> dataMap = remoteMessage.getData();
}
Just put your whole data in a Map and get values by putting in different keys from map.
I would also suggest to use only data instead of notification and build your own custom notification using http://www.androidbegin.com/tutorial/android-custom-notification-tutorial/
Hope this helps.

Sarthak Gandhi
- 2,130
- 1
- 16
- 23
1
if you want read data payload when when app in kill state then don`t send notification payload manage all operation using data payload only . if app in kill state and you send notification payload then it does not call onRecive() method so send tital and message of notification in data payload and generate notification in onRecive()

Sagar BHomkar
- 67
- 3
-
5 years late but i am experiencing this exact issue. I cant receive the data payload ( no notificstion payload sent) when the app is killed on my android device. Can you please help – Yeo Bryan May 12 '22 at 15:59
-1
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
if (remoteMessage.getData().size() > 0) {
Map<String, String> data = remoteMessage.getData();
ArrayList<String> ndata = new ArrayList<>();
for (Map.Entry<String, String> entry: data.entrySet()){
ndata.add(entry.getValue());
}
if(ndata.size()>0){
showNotification(ndata.get(1), ndata.get(0));
}
}
if (remoteMessage.getNotification() != null) {
showNotification(
remoteMessage.getNotification().getTitle(),
remoteMessage.getNotification().getBody());
}
}

Fabich
- 2,768
- 3
- 30
- 44