Reputation: 273
There's been trending topics about Firebase Cloud Messaging that Data Payload message is not fired from onMessageReceived()
method for some lower-end devices. And it's true. Here is the result:
App getting killed scenario:
Devices got data payload:
Devices didn't get data payload:
Be ensured that I'm not sending notification key from Server/Postman.
I am looking for the solution, I got data payload from Firebase including all types of devices, OS & obviously from API level 15. My Postman details are as follows.
{
"registration_ids": ["fC5uxGSRCsg:APA91bHh9fMXQ41LpX6tjjSsBKGrKTWYpzKimLDzvBGSHDPo2pq87JHqogUp2kqrmJi06siG_p6DfgRCim23iFzlBQAIrgtMDqRW4s39zUqv9CzyPqzxVl5PtnHPRDs4OagTuTePNyDI"],
"data": {
"title" : "my_custom_value",
"message" : "tekksdasdasdsa",
"isBackground" : "",
"payload" : {
},
"timestamp" : "",
"imageUrl" : "",
}
}
Upvotes: 6
Views: 3592
Reputation: 1663
In some devices Like MI you will not receive Notification if the application is removed from application tray! but you will receive notifications if you killed an activity and haven't removed from application tray!
In Xiaomi phones, they whitelist or blacklist an app based on certain criteria. If you download an app and if it is in their whitelist, they'll permit the app to show notifications.
How to Test:-
Try testing your app after killing your app activities rather removing from app tray if that works fine , thats all you could do at your end!
Upvotes: 2
Reputation: 11873
According to Firebase documentation:
You have two options for assigning delivery priority to downstream messages: normal and high priority. Delivery of normal and high priority messages works like this:
Normal priority. This is the default priority for data messages.
High priority. This is the default priority for notification messages.
Since you are using data payload the notification priority is by default set to normal. Back to the documentation:
onMessageReceived
is provided for most message types, with the following exceptions:Notification messages: delivered when your app is in the background. In this case, the notification is delivered to the device’s system tray. A user tap on a notification opens the app launcher by default.
Data messages: On Android platform, the data message can work on background and foreground. The data message will be handled by
onMessageReceived()
. A platform specific note here would be: On Android, the data payload can be retrieved in the Intent used to launch your activity.Messages with both notification and data payload: Both background and foreground. In this case, the notification is delivered to the device’s system tray, and the data payload is delivered in the extras of the intent of your launcher Activity.
I suspect it's related to using the data payload. Due to app getting killed for ram management in some devices, onMessageReceived()
might be skipped. A simple workaround trick would be using both of the data and notification payload. So that even when If the app is no longer running you'll still get a notification in the system tray. Later handle the notification after getting clicked from the notification tray.
{
"data": {
"message": "message_body",
"title": "message_title"
},
"notification": {
"body": "message_body",
"title": "message_title"
}
}
Check the official documentation here.
Upvotes: 1