I\'m working with Firebase and testing sending notifications to my app from my server while the app is in the background. The notification is sent successfully, it even appe
Remove notification
field completely from your server request. Send only data
and handle it in onMessageReceived()
otherwise your onMessageReceived()
will not be triggered when app is in background or killed.
Don't forget to include "priority": "high"
field in your notification request. According to the documentation: data messages are sent with a normal priority, thus they will not arrive instantly; it could also be the problem.
Here is what I am sending from server
{
"data":{
"id": 1,
"missedRequests": 5
"addAnyDataHere": 123
},
"to": "fhiT7evmZk8:APA91bFJq7Tkly4BtLRXdYvqHno2vHCRkzpJT8QZy0TlIGs......",
"priority": "high"
}
So you can receive your data in onMessageReceived(RemoteMessage message)
like this....let say I have to get id
Object obj = message.getData().get("id");
if (obj != null) {
int id = Integer.valueOf(obj.toString());
}