Setup Notification Channel
CE offers a feature to add a custom sound that will be played when a push notification is delivered. Starting from 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();
SmartPush.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()
SmartPush.getInstance(WeakReference(context)).createNotificationChannel(smtNotificationChannel)
Note :
To specify the notification importance, you can pass the 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 to Google's Channel Importance Level document.
Create a notification channel group
The snippet below demonstrates how to create a notification channel group.
SmartPush.getInstance(new WeakReference<>(context)).createNotificationChannelGroup("<Group_ID>", "<Group_Name>");
SmartPush.getInstance(WeakReference(context)).createNotificationChannelGroup("<Group_ID>", "<Group_Name>")
Delete a notification channel
You can delete notification channels by calling the following method.
SmartPush.getInstance(new WeakReference<>(context)).deleteNotificationChannel("<Channel_ID>");
SmartPush.getInstance(WeakReference(applicationContext)).deleteNotificationChannel("<Channel_ID>")
Delete a notification channel group
You can delete the notification channels group by calling the following method.
SmartPush.getInstance(new WeakReference< (context)).deleteNotificationChannelGroup("<Group_ID>");
SmartPush.getInstance(WeakReference(applicationContext)).deleteNotificationChannelGroup("<Group_ID>")
Updated 6 months ago