-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Grouping notifications #449
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
where do you see documentation for functions like createLocalNotification? All I could find is this and it doesnt seem comprehensive. |
The messaging docs are incomplete which we realise. There's some discussion about how we progress with it as it really needs an overhaul. |
thanks @Ehesp the layout of that page and the ios installation instructions are quite good, so i thought i might be crazy. have you thought about adding a "underconstruction" message with a link to contribute. I get a ton of value from rn+firebase and would be happy to help. |
@kevando Yeah I guess we should - there is an edit button at the bottom of each page :) |
Thanks for reporting. We're aware of lots of issues with notifications and will be addressing them all as part of the v3.2.0 release stream. Please see #595 for updates. |
Good news, the long awaited alpha of our messaging and notifications overhaul is now available!! Check out the release notes here: https://github.com/invertase/react-native-firebase/releases/tag/v4.0.0-alpha.1 If you have any comments and suggestions or want to report an issue, come find us on Discord |
I've tried to grouping notifications and still does not work. I'm using Can you help me please? |
I also can't get grouping to work, using 4.2.0 too with Android SDK 26. setVisibility also does not seem to be working but I think that's already a known issue, possibly fixed already. |
Re-opening to re-visit grouping issue, has been mentions on discord as well of it not working. Unless anyone can say otherwise or has it working for them? Loving
|
@Salakar , grouping is working to me. This is a feature of Android 7.0 and above, as documented here. In my case, I'm creating local notifications from remote messages. The trick is to create an additional notification that will contain the notifications for that group. This is the relevant code: // ID for grouping notifications, always the same
const SUMMARY_ID = `${ALERTS_GROUP}.summary`
const sendIt = (notification: Firebase.notifications.Notification) => {
return firebase.messaging().hasPermission().then((yes) => {
if (yes) {
try {
return firebase.notifications().displayNotification(notification)
.catch((err) => {
Log.e(`[sendNotification] ERROR: ${err}`)
return Promise.resolve()
})
} catch (err) {
Log.e('[sendNotification] Error displaying notification: ' + err)
}
}
return Promise.resolve()
})
}
const sendSummary = (data: MessageData) => {
const summary = new firebase.notifications.Notification()
.setNotificationId(SUMMARY_ID)
.setTitle(_T('notification.channels.alert.description'))
.setData(data)
.android.setAutoCancel(true)
.android.setCategory(firebase.notifications.Android.Category.Message)
.android.setChannelId(getChannelId(MsgType.Alert))
.android.setColor(variables.scheme.primaryColor)
.android.setSmallIcon(STATUS_ICON)
.android.setGroup(ALERTS_GROUP)
.android.setGroupSummary(true)
.android.setGroupAlertBehaviour(firebase.notifications.Android.GroupAlert.Children)
sendIt(summary)
}
/**
* Called by `bgMessaging` or the `onMessage` handler.
*/
export function sendNotification (message: Firebase.messaging.RemoteMessage) {
const payload: MessagePayload = message.data as any || {}
const notification = new firebase.notifications.Notification()
// ... more code
if (Platform.OS === 'android' && Platform.Version >= 24) {
notification.android.setGroup(ALERTS_GROUP)
sendSummary(notification.data)
}
Log.v('[sendSummary] sending notification.')
return sendIt(notification)
} There's an inbox-style which also allows grouping and works in SDK 23 and bellow, but is not implemented in RNF react-native-firebase. |
@aMarCruz thanks for confirming and the detailed example. Will close this again. |
I found it is pretty tricky to show the notification group. Thanks @aMarCruz 's comment, but it still costs me several hours to make it work so I'd like to share my code: This is mine:
Be careful, tag / notificationId, group, groupSummary and channel id, these are very important fields and you need to set. And I am still running into an unexpected behavior, which is every time I see a notification, it pops up twice, I think one is for the groupNotification and the other one is for notification. Not found a solution yet. Anyway hope this will help someone. |
@chinalwb try using ...and sorry, my example was incomplete and it missed relevant lines under "// ... more code" |
@aMarCruz Thank you, I added the group alert behaviour to both group and child notification, it works now. |
So this is the latest code.
|
@aMarCruz Sorry to bother you, I have one more issue about the group notification, that is you can see my code in above comment, I didn't set smallIcon to the (child) notification -- only setSmallIcon onto groupNotification, but in fact every child notification are being shown with a small icon. Notice the gray square to the left side of each notification. (The green one at the group notification is being shown as expected.) Can you help to give me some advice? Thanks. |
@chinalwb of course, you need set the desired icon and color for individual notifications as well, otherwise, rn-firebase will put this (contrary to what is said in the docs) to the default icon of your App (mipmap/ic_launcher). |
@aMarCruz Thanks, I set a different small icon string and it shows, but in fact I want to remove the icon from the child notification. Just like this: Also I want to remove the / icon from the child notification, it makes the child notification looks like a group. Many Thanks. |
@chinalwb I really don't know how to hide the icon in group elements. Also, check in your AndroidManifest.xml and delete the meta with the name "com.google.firebase.messaging.default_notification_icon" if any, ...it is something like this: <meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="@drawable/ic_notification" /> Please tell me if some works. |
@aMarCruz Thank you very much for your help! I found the trick. To hide the smallIcon in the child notification, I need to keep the I.e.: with the code in my above comment, it was:
See the embeded comment inside the code, I set smallIcon and color to group notification but didn't set either of them to child notification, this is one of the case that the child notification isn't the same to the group notification, so each child notification shows a small icon of itself -- in fact here, if there is no smallIcon set for child notification, it uses the default one, i.e.: 'ic_launcher', but because I set the color to group notification, so this action makes them different. So to resolve (hide the smallIcon of the child notification) the issue, I did like this:
And BTW, to remove the \/ icon at the RHS of the child notification, just need to remove the call to And what's more, remove or keep the Thank you @aMarCruz ! |
@aMarCruz Thanks, will pay attention to the PR. |
How's the PR coming up? Is there any way to show the messages in the group since the inbox style isn't available. |
Why is this thing closed? It's a must-have. |
Hey guys, Did anyone find the solution? I am still stuck in the grouping of notification |
@chinalwb Thank you so much for your solution. it works perfectly when the app is in the foreground. unfortunately, the onNotification listener doesn't get triggered when the app is in the background or killed hence the notification doesn't group. do you have any workaround? |
How can we group notifications?
I've seen the code of your library and the
setGroup
method is called onNotificationBuilder
but my notifications are not grouped.I'm using the following code to create a local notification:
How can I handle grouping?
NOTE: I'm using android 8.0
The text was updated successfully, but these errors were encountered: