Skip to content

Instantly share code, notes, and snippets.

@ParkSangGwon
Last active July 5, 2018 03:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ParkSangGwon/3fd55511de2b9f192ed58a227b08507e to your computer and use it in GitHub Desktop.
Save ParkSangGwon/3fd55511de2b9f192ed58a227b08507e to your computer and use it in GitHub Desktop.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
NotificationChannel notificationChannel = new NotificationChannel("channel_id", "channel_name", NotificationManager.IMPORTANCE_DEFAULT);
notificationChannel.setDescription("channel description");
notificationChannel.enableLights(true);
notificationChannel.setLightColor(Color.GREEN);
notificationChannel.enableVibration(true);
notificationChannel.setVibrationPattern(new long[]{100, 200, 100, 200});
notificationChannel.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
notificationManager.createNotificationChannel(notificationChannel);
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
NotificationChannelGroup group1 = new NotificationChannelGroup("channel_group_id", "channel_group_name");
notificationManager.createNotificationChannelGroup(group1);
NotificationChannel notificationChannel = new NotificationChannel("channel_id", "channel_name", NotificationManager.IMPORTANCE_DEFAULT);
notificationChannel.setDescription("channel description");
notificationChannel.setGroup("channel_group_id");
notificationChannel.enableLights(true);
notificationChannel.setLightColor(Color.GREEN);
notificationChannel.enableVibration(true);
notificationChannel.setVibrationPattern(new long[]{100, 200, 100, 200});
notificationChannel.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
notificationManager.createNotificationChannel(notificationChannel);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment