Skip to content

Instantly share code, notes, and snippets.

@abhishekhugetech
Created January 9, 2019 21:18
Show Gist options
  • Save abhishekhugetech/55b27698c46e7fcbe43f2226e7837b0e to your computer and use it in GitHub Desktop.
Save abhishekhugetech/55b27698c46e7fcbe43f2226e7837b0e to your computer and use it in GitHub Desktop.
Code for Creating a notification channel in Android.
private void createNotificationChannel() {
// Create the NotificationChannel, but only on API 26+ because
// the NotificationChannel class is new and not in the support library
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
CharSequence name = "name_of_channel";
String description = "description for notification channel";
int importance = NotificationManager.IMPORTANCE_DEFAULT;
NotificationChannel channel = new NotificationChannel( "channel_id_here" , name, importance);
channel.setDescription(description);
// Register the channel with the system; you can't change the importance
// or other notification behaviors after this
NotificationManager notificationManager = getSystemService(NotificationManager.class);
notificationManager.createNotificationChannel(channel);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment