Documentation > Android

Push Notifications for Android O

Android has modified the way push notifications can be sent to an app in its latest version Oreo. Starting with CleverTap SDK 3.1.7, we support Android Oreo’s latest features like Notification Channels and Notification Badges.

Prerequisites

Since Notification channels and badges are the features of the latest Android version, you as a developer will have to update your SDK and Build Tools to the latest versions. The latest SDK tools version is 26.0.2 and the latest Build Tools version is 26.0.1. You will have to make sure that in your build.gradle file, the compileSdkVersion is 26 and buildToolsVersion is 26.0.1

android {
   compileSdkVersion 26
   buildToolsVersion "26.0.1"
}
copy Copied

Creating Notification Channel Groups

Once you have the CleverTap 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 –

CleverTapAPI cleverTapAPI = CleverTapAPI.getInstance(getApplicationContext());
cleverTapAPI.createNotificationChannelGroup(getApplicationContext(),"YourGroupId","YourGroupName");
copy Copied

Creating Notification Channels with Notification Groups

Once you have created a notification channel group you can use the group Id to create notification channels for that specific group. You can create a notification channel specifying the group id using the following line of code –

CleverTapAPI cleverTapAPI = CleverTapAPI.getInstance(getApplicationContext());
cleverTapAPI.createNotificationChannel(getApplicationContext(),"YourChannelId","YourChannelName","YourChannelDescription",NotificationManager.IMPORTANCE_MAX,"YourGroupId",true);
copy Copied

Creating Notification Channels

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

CleverTapAPI cleverTapAPI = CleverTapAPI.getInstance(getApplicationContext());
cleverTapAPI.createNotificationChannel(getApplicationContext(),"YourChannelId","Your Channel Name","Your Channel Description",NotificationManager.IMPORTANCE_MAX,true);
copy Copied

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 CleverTap dashboard.

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 which doesn’t exist. You can delete the notification channels using the following line of code –

CleverTapAPI cleverTapAPI = CleverTapAPI.getInstance(getApplicationContext());
cleverTapAPI.deleteNotificationChannel(getApplicationContext(),"YourChannelId");
copy Copied

Deleting Notification Groups

CleverTap 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 –

CleverTapAPI cleverTapAPI = CleverTapAPI.getInstance(getApplicationContext());
cleverTapAPI.deleteNotificationChannelGroup(getApplicationContext(),"YourGroupId");
copy Copied

Sending Notifications via Dashboard

To send Push Notifications, login to the CleverTap Dashboard and on the left navigation menu click on Messages. Then click on +Message button on the top right to select Mobile Push. Now, set up your Push Notification campaign by selecting when you want to send out your notification, who do you want to send it out to (in this case it will be Android users) and what kind of push notification you want to send out. Once you reach the what section, select the Single Message option. Select the checkbox which says Send Message to Android O.

Fill in the Channel with the channel id you used to create the notification channel in your app. This field is mandatory as Android O requires a valid channel to send notifications. Badge Icon can be set as the app icon or the small icon used to denote push notifications. The default is app icon. Badge ID is the number you want to set the Notification Badge with, by default it auto-increments. Both Badge Icon and Badge ID are optional.

Android O Push Notifications