Created
January 9, 2019 21:18
-
-
Save abhishekhugetech/55b27698c46e7fcbe43f2226e7837b0e to your computer and use it in GitHub Desktop.
Code for Creating a notification channel in Android.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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