Remove notification payload completely from your server request. Send only data and handle it in onMessageReceived()
, otherwise your onMessageReceived
will not be triggered when the app is in background or killed.
Here is what I am sending from server:
{
"data":{
"id": 1,
"missedRequests": 5
"addAnyDataHere": 123
},
"to": "fhiT7evmZk8:APA91bFJq7Tkly4BtLRXdYvqHno2vHCRkzpJT8QZy0TlIGs......"
}
So you can receive your data in onMessageReceived(RemoteMessage message)
like this: (let's say I have to get the id)
Object obj = message.getData().get("id");
if (obj != null) {
int id = Integer.valueOf(obj.toString());
}
And similarly you can get any data which you have sent from server within onMessageReceived()
.