Skip to content

Instantly share code, notes, and snippets.

@markchristopherng
Last active October 13, 2018 02:05
Show Gist options
  • Save markchristopherng/f744e53d65cbbcf5922b6b6e7dbede15 to your computer and use it in GitHub Desktop.
Save markchristopherng/f744e53d65cbbcf5922b6b6e7dbede15 to your computer and use it in GitHub Desktop.
@TargetApi(Build.VERSION_CODES.O)
private void createNotificationChannels(AppConfig config) {
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.O &&
config.getChannelGroups()!= null) {
for (AppConfig.ChannelGroup cg: config.getChannelGroups()) {
NotificationChannelGroup ncg =
new NotificationChannelGroup(cg.groupId, cg.groupName);
notificationManager.createNotificationChannelGroup(ncg);
for (AppConfig.Channel channel : cg.channels) {
NotificationChannel notificationChannel =
new NotificationChannel(channel.channelId, channel.channelName, channel.importance);
notificationChannel.setGroup(ncg.getId());
notificationManager.createNotificationChannel(notificationChannel);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment