Notification Channels (Android)

With the introduction of Android Oreo, Google has strived to make the Notifications system more user-friendly. Android Oreo has completely redesigned notifications.

Notification Channels are somewhat like groups or categories of notifications - say you’re building a social networking app, the channels can be “activity” - likes, or comments on your posts, “messages”, etc.

To define your channels, take inventory of all the notifications you want to send. Group these notifications into sets that have the following things in common:

Subject matter: A single topic can succinctly describe all of these notifications, such as "Downloads".

Users can get fine control of what they want to be notified about. They can specifically

A. Turn off notifications for a certain channel

B. Specify the importance

C. Set the preferred sound for a particular category of notifications

After you create a notification channel, you cannot change the notification behaviors — the user has complete control at that point. However you can still change a channel's name and description.

📘

Note

If you target Android 8.0 (API level 26) and post a notification without specifying a notification channel, the notification does not appear and the system logs an error.

Creating Notification Channels

You can create stand-alone notification channels in your app, by using the following line of code.

const channelData = {
      channelId: 'Channel123',
      channelName: 'MyChannal',
      channelDescription: 'Used for different tone',
      channelImportance: '5',
      enableLights: true,
      shouldVibrate: true,
      lightColor: '#ffffff',
      soundFileName: 'tone1',
    };

 NotifyVisitors.createNotificationChannel(channelData);

//Example

const channelData = {
      channelId: 'Channel123',
      channelName: 'MyChannal',
      channelDescription: 'Used for different tone',
      channelImportance: '5',
      enableLights: true,
      shouldVibrate: true,
      lightColor: '#ffffff',
      soundFileName: 'tone1',
    };

NotifyVisitors.createNotificationChannel(channelData);

You can create more than one channel using the above line of code, just make sure that the channel ID differs in every Notification Channel. Also, this Channel ID will be used to send Push Notifications using the NotifyVisitors dashboard.

Creating Notification Channel Groups

Once you have the NotifyVisitors Android SDK integrated successfully, you can create a notification channel group. Notification channel groups allow you to manage multiple notification channels with identical names within a single app, which can be useful if your app supports multiple accounts. You can create a notification group using the following line of code –

const groupName = 'NSGroup';
const groupId = 'NSID';

const finalData = { groupId, groupName };
NotifyVisitors.createNotificationChannelGroup(finalData);

//Example

const groupName = 'NSGroup';
const groupId = 'NSID';

const finalData = { groupId, groupName };
NotifyVisitors.createNotificationChannelGroup(finalData);

Deleting Notification Channels

You can delete the notification channels created previously in your app. There is no error thrown when you try to delete a notification channel that doesn’t exist. You can delete the notification channels using the following line of code.

const channelId = 'Neeraj';
const finalData = { channelId };
NotifyVisitors.deleteNotificationChannel(finalData);

//Example
const channelId = 'Neeraj';
const finalData = { channelId };
NotifyVisitors.deleteNotificationChannel(finalData);

Deleting Notification Groups

NotifyVisitors SDK also allows you to remove the notification groups you have created previously. Please note that you will need to delete all the channels associated with a group prior to deleting a group. You can delete a notification group using the following line of code.

const groupId = 'NSID';
const finalData = { groupId };
NotifyVisitors.deleteNotificationChannelGroup(finalData);

//Example
const groupId = 'NSID';
const finalData = { groupId };
NotifyVisitors.deleteNotificationChannelGroup(finalData);

Notification Channel ID Settings in Dashboard

You can choose to have a notification channel ID as optional or mandatory for creating a push notification. Select the 'Notification Channels' option. It is available at Mobile Push → Configuration → Assets → Notification Channels. You can create a selection list of channel IDs for your messages.

By default, we have a channel called “General Notifications”. If you want to change the default setting then you can mark any of your custom channels as default in the dashboard.

After you are done with the setting whenever you create or send the push notification you can choose the channel among the defined channels in “Advanced Options” of the push notification.

Importance Level(s)

Channel Importance affects the interruption level of all notifications posted in the channel. There are five importance levels available, ranging from IMPORTANCE_NONE(0) to IMPORTANCE_HIGH(4). The importance level you assign to a channel applies to all notification messages that you post to it.

User-Visible Importance LevelImportance (Android 8.0 and higher)Priority (Android 7.1 and lower)
Urgent
Makes a sound and appears as a heads-up notification
IMPORTANCE_HIGHPRIORITY_HIGH or PRIORITY_MAX
High
Makes a sound
IMPORTANCE_DEFAULTPRIORITY_DEFAULT
Medium
No sound
IMPORTANCE_LOWPRIORITY_LOW
Low
No sound and does not appear in the status bar
IMPORTANCE_MINPRIORITY_MIN

Once you submit the channel to the Notification Manager, you cannot change the importance level. However, the user can change their preferences for your app's channels at any time.

IMPORTANCEUSAGEEXAMPLES
HIGHTime-critical information that the user must know, or act on, immediatelyText messages, alarms, phone calls
DEFAULTInformation that should be seen at the user’s earliest convenience, but not interrupt what they're doingTraffic alerts, task reminders
LOWNotification channels that don't meet the requirements of other importance levelsNew content the user has subscribed to, social network invitations
MINNon-essential information that can wait or isn’t specifically relevant to the userNearby places of interest, weather, promotional content.