I've been trying to group notifications by an id to have them displayed as WhatsApp for example, without having one notification per line.
Adding setGroup in either onNotification or onNotificationDisplayed seems to have no effect see examples below:
1
componentDidMount() {
this.notificationListener = firebase.notifications().onNotification(async (notification) => {
// Process your notification as required
notification.android.setAutoCancel(true)
notification.android.setGroup(notification.data.channelId)
notification.android.setGroupSummary(true)
}
}
2
componentDidMount() {
this.notificationDisplayedListener = firebase.notifications().onNotificationDisplayed((notification) => {
notification.android.setGroup(notification.data.channelId)
notification.android.setGroupSummary(true)
});
}
Any idea how can I group them by id?
To group notifications by an id, you will need to create a notification channel with the same id for all the notifications that you want to group together.
You can do this by calling the createNotificationChannel method from the Android module of the react-native-firebase library, passing in an object with the channel's id and other relevant configuration options such as the channel's name and importance level.
Here's an example of how you can create a notification channel and set it for a notification:
import firebase from 'react-native-firebase'; // Create the notification channelconst channel = new firebase.notifications.Android.Channel('channelId', 'Channel Name', firebase.notifications.Android.Importance.High) .setDescription('A description of the channel'); // Set the channel for the notification firebase.notifications().android.createChannel(channel); const notification = new firebase.notifications.Notification() .setNotificationId('notificationId') .setTitle('Notification Title') .setBody('Notification Body') .setData({ channelId: 'channelId', // Set the channel id for the notification }) .android.setChannelId('channelId'); // Set the channel id for the notification firebase.notifications().displayNotification(notification);
With this setup, all notifications with the same channelId will be grouped together in the notification tray.