Notification Channel Id Should be Unique for Each Notification - android

Since Android 8 notification channels required for notifications. My Question is each and every notification should have different notification channel Id or same channel Id?

Notification channels let you group related types of notifications together.
Why would you need that?
A user may only want to disable notifications for a specific type. Let's say in a Calendar App he may want to disable all notifications which are of type reminder. Instead of disabling all notifications, the user (if a channel for reminders exists) can now specifically say: Ok I only want to disable reminder notifications.
In short: It enables the user to filter notifications more granular.
Just provide a different notification channel for each different notification "type" (meaning: they do not relate to each other).

Ok very good question, I am sure, I am late to answer but today I came across same problem. Actually I am showing multiple notification and when I long press on it and click on turn off notifications for my app, I came to know that same channel is being added multiple times as shown below:
So as and when I show the notification, I was using unique channel id while showing the notification, so even though notification channel name is same but channel id is different & unique, it keeps adding new channel each time I show the notification, that is completely wrong. It unnecessary ads multiple channels, very hard to turn off notification and many more reason.
So, in short, while you show particular group's notification, please use same channel name and channel id. Notification of particular type is grouped under channel id, not the channel name technically. But user can see the channel name only when he wants to turn it off.
Hope this answer your query and it will also help to others who are facing same issue of duplicate or multiple channels being created on each notification.

Related

Removing/Dismissed all notification belong to particular channel in android

I am creating one application where I created two notification channel. Let say,
Channel 1 : to show one type of notification
channel 2 : to show another type of notification
Now I want to dismiss all notification on channel 1 when user click on any one of the notification of channel 2.
Till now I only found solution that to keep track of all notification ID of channel 1 and after that cancel notification with those id.
Is there is better way to do, without keeping track of IDs??
Thanks in advance :)

Should these two be the same? NotificationChannel.setGroup and Notification.Builder.setGroup

While creating notification channels, I categorise them by assigning them to a group (NotificationChannel.setGroup).
Later, while displaying notification, I use Notification.Builder. Should the value given to setGroup method here be the same as the first to function properly?
Not necessarily. Even though they might be related in your business rules, channel groups and notification groups are used for different reasons.
As stated in https://developer.android.com/training/notify-user/channels:
If you'd like to further organize the appearance of your channels in the settings UI, you can create channel groups. This is a good idea when your app supports multiple user accounts (such as for work profiles), so you can create a notification channel group for each account. This way, users can easily identify and control multiple notification channels that have identical names.
So, if you set different channel groups they'll be displayed separately in App Info -> Notifications. I'd say you just need it if your app has multiple channels and you want to further organize them.
A notification group, the one you set in Notification.Builder.setGroup(), is used to group notifications in the notification tray. You can learn more about it at https://developer.android.com/training/notify-user/group.

Android: Right place to create notification channel

I know how to create notification and notification channel in an Android app.
I showed many examples that say create notification channel while you generate a notification from FCM listener. So when the app receives notification at that point it generates channel.
But I saw in many apps, it create all channels without receiving any notification.
Question: From where we should create a notification channel?
From the docs:
Creating an existing notification channel with its original values
performs no operation, so it's safe to call this code when starting an
app.

Android Oreo: Grouped Notifications With Notification Channels

I followed the documentation provided here and can successfully create a notification group on Android N and higher. The issue I'm having however, is with Android Oreo, each notification posted to the group plays the sound for the group.
This is annoying because I'd just like the sound to play once. Each individual notification is a summary of the chats the user hasn't read for each chat room they're in. I need the grouping for when there are multiple chat rooms with unread messages.
There doesn't seem to be a way to set the sound for a notification dynamically, it's limited to channel creation.
I tried following what Dan Lew suggested here but the notification sound plays for each notification still.
My question therefore is, how do you get grouped notification in Android Oreo without having a notification sound play for each?
I'd been working for the entire week trying to solve it, but I find the answer shortly after asking on StackOverflow lol.
The answer comes courtesy of Dan Lew again, but I needed to call
notificationBuilder.setGroupAlertBehavior(Notification.GROUP_ALERT_SUMMARY)
on the children notifications.
More detail can be found here.

how to impliment Notifications aggregation

My application displays event notifications, and I'm looking for a way to have notification aggregation.
Meaning, I would like to show 4 notification, but if the fifth comes, I would like to collect all notifications and show only one general notification.
Os there a way to know how many live notifications i have?
Is it possible to approach these notification and cancel them?
Thanks!
According to the android design guidelines you should stack your notifications. So you should avoid showing multiple notification for the same app.
You can stack your notifications using
NotificationManager.notify(ID, notification) where you specify same ID for each notification.
You can check the docs on how to implement it.
For your case
Is there a way to know how many live notifications i have - No
But you can keep a track of the notifications using Shared Preferences, where you store the ID of the notificaion and remove it when the user clicks on the notificaion
Is it possible to approach these notification and cancel them? - Yes
You can cancel a notification using the cancel(int id) method, where you pass the ID of the notification to be removed.
So you can use this method to acheive what you want, but it advisable to stack all the notifications.

Categories

Resources