Setup Notification Channel
CEE offers a feature to add a custom sound that will be played when a push notification is delivered. Starting in Android 8.0 (API level 26), all notifications must be assigned to a notification channel. For each channel, you can set the visual and auditory behaviour that is applied to all notifications in that channel.
To create a notification channel, implement the following code:
SMTNotificationChannel.Builder smtBuilder = new SMTNotificationChannel.Builder(
"<Channel_ID>",
"<Channel_Name>",
<Notification_Importance>);
//To set the description to the channel add below method.
smtBuilder.setChannelDescription("<Channel_Description>");
//To set the group ID to the channel add below method. (Make sure that before setting group ID here, that group must be created before. Check the code below)
smtBuilder.setChannelGroupId("<Group_ID>");
//To set sound to channel, add below method. (Note that sound name must be without extention.)
smtBuilder.setNotificationSound("<Sound_File_Name_Without_Extenstion>");
SMTNotificationChannel smtNotificationChannel = smtBuilder.build();
Smartech.getInstance(new WeakReference<>(context)).createNotificationChannel(smtNotificationChannel);
val smtBuilder: SMTNotificationChannel.Builder= SMTNotificationChannel.Builder(
"<Channel_ID>",
"<Channel_Name>",
<Notification_Importance>)
//To set the description to the channel add below method.
smtBuilder.setChannelDescription("<Channel_Description>")
//To set the group ID to the channel add below method. (Make sure that before setting group ID here, that group must be created before. Check the code below)
smtBuilder.setChannelGroupId("<Group_ID>")
//To set sound to channel, add below method. (Note that sound name must be without extention.)
smtBuilder.setNotificationSound("<Sound_File_Name_Without_Extenstion>")
val smtNotificationChannel: SMTNotificationChannel = smtBuilder.build()
Smartech.getInstance(WeakReference(context)).createNotificationChannel(smtNotificationChannel)
Note :
For Notification importance, you can pass below levels.
Importance | User-visible importance level |
---|---|
NotificationManager.IMPORTANCE_HIGH or NotificationManager.IMPORTANCE_MAX | Urgent Makes a sound and appears as a heads-up notification |
NotificationManager.IMPORTANCE_DEFAULT | High Makes a sound |
NotificationManager.IMPORTANCE_LOW | Medium No sound |
NotificationManager.IMPORTANCE_MIN | Low No sound and does not appear in the status bar |
For more details, please refer Google's Channel Importance Level document .
Create a notification channel group
The following snippet demonstrates how to create a notification channel group.
Smartech.getInstance(new WeakReference<>(context)).createNotificationChannelGroup("<Group_ID>", "<Group_Name>");
Smartech.getInstance(WeakReference(context)).createNotificationChannelGroup("<Group_ID>", "<Group_Name>")
Delete a notification channel
You can delete notification channels by calling the following method.
Smartech.getInstance(new WeakReference<>(context)).deleteNotificationChannel("<Channel_ID>");
Smartech.getInstance(WeakReference(applicationContext)).deleteNotificationChannel("<Channel_ID>")
Delete a notification channel group
You can delete notification channels group by calling the following method.
Smartech.getInstance(new WeakReference< (context)).deleteNotificationChannelGroup("<Group_ID>");
Smartech.getInstance(WeakReference(applicationContext)).deleteNotificationChannelGroup("<Group_ID>")
Updated 5 months ago