Last active
May 11, 2018 06:35
-
-
Save adriantache/ec2ee3a73bd81b6d93f707a9c9e71736 to your computer and use it in GitHub Desktop.
Notification Channel code
This file contains hidden or 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 final static String manasia_notification_channel = "Manasia Event Reminder"; | |
// 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) { | |
//define the importance level of the notification | |
int importance = NotificationManager.IMPORTANCE_DEFAULT; | |
//build the actual notification channel, giving it a unique ID and name | |
NotificationChannel channel = | |
new NotificationChannel(manasia_notification_channel, manasia_notification_channel, importance); | |
//we can optionally add a description for the channel | |
String description = "A channel which shows notifications about events at Manasia"; | |
channel.setDescription(description); | |
//we can optionally set notification LED colour | |
channel.setLightColor(Color.MAGENTA); | |
// Register the channel with the system | |
NotificationManager notificationManager = (NotificationManager) getApplicationContext(). | |
getSystemService(Context.NOTIFICATION_SERVICE); | |
if (notificationManager != null) { | |
notificationManager.createNotificationChannel(channel); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment