'Push notification doesn't pop up on Android
I am creating flutter application using FCM for sending push notifications. I am sending notifications with Cloud Functions from website by sending JSON to device. This however works perfectly on iOS (notification pops up) on Android I get sound and notification only appears in status bar. Any advice on how to make it pop up?
This is the JSON I am sending:
{
"message":{
"token" : result,
"notification" : {
"body" : body,
"title" : title,
},
"data": {
"body": body,
"title": title
},
"apns": {
"headers": {
'apns-priority': '10',
},
"payload": {
"aps": {
"sound": 'default',
}
},
},
"android": {
"priority": 'high',
"notification": {
"sound": 'default',
}
},
}
}
Solution 1:[1]
You are correctly setting "priority": "high", but I think this might be the case that FCM lowers the priority. This is from the FCM Documentation:
High priority messages generally should result in user interaction with your app or its notifications. If FCM detects a pattern in which they don't, your messages may be de-prioritized.
If your app is on the foreground, you can achieve desired behaviour if you set NotificationChannel priority and also notification priority in the NotificationBuilder to high priority. If the app is on the foreground the notification is created by your extended FirebaseMessagingService and priority can be set.
But if the app is on the background or closed, notification is created by the notification tray by the system.
This applies if you send both notification
and data
object.
Possible solution is to send only data
object (without notification
object). Like this, the notification is always created by the FirebaseMessagingService. Whether the app is on the foreground or in the background or closed. See this table this table
Solution 2:[2]
Add this line to your Notification Builder Channel:
channel.setShowBadge(true);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Petr Kubá? |
Solution 2 | Roslan Amir |