I\'m using FCM to send notifications to Android devices. When the app is in background, if I send 10 notifications, the devices will show up 10 entries on the notification bar.<
To achieve this, in your notification payload, use the tag key
{
"notification" : {
"title" : "Notification Title",
"body" : "Notification Body",
"tag" : "your_unique_tag"
}
}
Cheers.
It's possible. Two approaches.
First is you make use of the collapse_key
parameter to set the message as a collapsible message. Referring to the FCM docs:
A collapsible message is a message that may be replaced by a new message containing the same collapse key if it has yet to be delivered to the device.
It's actually included in the link you provided (first parameter under Options):
collapse_key - This parameter identifies a group of messages (e.g., with collapse_key: "Updates Available") that can be collapsed, so that only the last message gets sent when delivery can be resumed. This is intended to avoid sending too many of the same messages when the device comes back online or becomes active.
Note that there is no guarantee of the order in which messages get sent.
Note: A maximum of 4 different collapse keys is allowed at any given time. This means a FCM connection server can simultaneously store 4 different send-to-sync messages per client app. If you exceed this number, there is no guarantee which 4 collapse keys the FCM connection server will keep.
Second approach is Notification bundling/stacking/grouping. As per my answer here:
By grouping the notification, I'm presuming you mean stacking or bundling notifications.
This is more on how you handle the notification in your client app. You simply have to make use of the setGroup() to add all your notifications to a single group then calling notify() to let the NotificationManager of the changes.
This Add Each Notification to a Group documentation pretty much sums it all up.
Update:
From one of the linked posts, using the tag parameter is also an option:
Identifier used to replace existing notifications in the notification drawer.
If not specified, each request creates a new notification.
If specified and a notification with the same tag is already being shown, the new notification replaces the existing one in the notification drawer.