Android: Right place to create notification channel - android

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.

Related

Flutter double notifications

I have chat app with end-to-end encryption made in Flutter. When push notifications arrive, the app process it, decrypt the content and show notification. But the problem is, that there is one more notification not created by the app with unencrypted content. It looks like this:
This is really annoing and I don't know how to solve this problem.
Flutter logs:
Handling a background message: 0:1620226730325270%0454fd8a0454fd8a
W/FirebaseMessaging(23000): Notification Channel set in AndroidManifest.xml has not been created by the app. Default value will be used.
I/flutter (23000): true
D/FlutterSecureStoragePl(23000): Read: key exists => Running ensureInitStorageCipher
D/FlutterSecureStoragePl(23000): Initializing StorageCipher
D/FlutterSecureStoragePl(23000): StorageCipher initialization complete
D/NotificationSender(23000): Notification created
I/flutter (23000): Notification created
I/flutter (23000): Notification displayed
The log says that Notification Channel set in AndroidManifest.xml has not been created by the app. Default value will be used. But the channel was created by the app.
Thank you for you help.
Btw, I'm using AwesomeNitifications plugin for notifications.
EDIT:
Notification Channel set in AndroidManifest.xml has not been created by the app. Default value will be used. Error is not showing anymore, because I set notification channel id in FCM message this ID, but the notifications are still showing twice.
In fact, Firebase push notifications can be sent in the background or exposed as soon as they arrive.
In this case, you will have to change the sending of push notifications, to be sent only in the background, and this way your filter will not expose the message that is encrypted.
For more info:
https://firebase.google.com/docs/cloud-messaging/concept-options#notifications_and_data_messages

Notification Channel Id Should be Unique for Each Notification

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.

How to detect a Notification Channel is blocked by user in Android 8.0

Is there any callback my application receives when user blocks a Notification Channel created by my application OR it can be detected later ?
Starting from Android P, there is a system broadcast for this: https://developer.android.com/reference/android/app/NotificationManager.html#ACTION_NOTIFICATION_CHANNEL_BLOCK_STATE_CHANGED
It's impossible to reliably sync our backend push servers with the channel settings without this (you have to poll...)
No, there is no such listener provided by the APIs.
You will have to check each time before you make a notification.
From the developer document
To find out if a user blocked a notification channel, you can call getImportance(). If the notification channel is blocked, getImportance() returns IMPORTANCE_NONE.

Notifications sample only showing the last received on Android

I'm running the Worklight's Notifications sample. I invoke the adapter to send a notification to the application, and it shows the notification into the top bar perfectly.
But when I send another notification, it don't stack with the previous one, it overwrites with the new one.
And I don't want that it being overwriten. How can I solve this?
This is a limitation that is currently imposed (by default) by Worklight.
In essence, in Worklight there is internally a GCMIntentService class that listens for received notifications and if received, creates and sends to the OS an object with a static ID. This is repeated for every incoming notification, replacing the previously received notification.
What you can do is:
Submit a feature request to be evaluated by Worklight's product designers: http://www.ibm.com/developerworks/rfe/
In your project, there is an empty class in android\native\src\com\app-name\GCMIntentService.java. What you could try to do, is basically implement your own "push mechanism" based on Google's documentation to have all notifications display rather than just the last received notification by not using a static id like how it is currently implemented in Worklight.
You need to set a diferent notification id in the client. In the notification manager create a notification id using the timestamp for exemple.

Android: Right Handling with multiple Notifications

I receive Push-Notifications from GCM and want them to be shown in the Notification-Bar. So I generation the Notifications in the GCMIntentService-class.
If there is already a notification in the notification-area, this notification have to be appended with the new message (with use of the BigTextStyle). But how do I know if there is a notification from my app in the notification-area?
You cannot get existing notification, but you can update existing notification by setting up Notification ID.
NotificationManager.notify(NotificationId, NotificationObject);
No, you can't find out if there's already a notification posted; this is something you should keep track of in your app.
Fortunately, however, the API for updating an existing notification is identical to the API for creating a new one: notify(). That is, once you get new information, add it to some internal buffer (possibly just a StringBuilder) representing the complete set of received push notifications, then build a new notification with Notification.Builder and call notify() with the same ID and tag you used last time. Any existing notification with that ID and tag will be replaced with the new content.

Categories

Resources