Last active
August 22, 2018 13:15
-
-
Save karthiks/ce08c8701145a107d4ba43b877a594f0 to your computer and use it in GitHub Desktop.
Create NotificationChannel object per Channel, with the desired options
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
public class NotificationUtils extends ContextWrapper { | |
public static final String ANDROID_CHANNEL_ID = "com.androidstuff.tutsplustalerts.ANDROID"; | |
public static final String IOS_CHANNEL_ID = "com.androidstuff.tutsplustalerts.IOS"; | |
public static final String ANDROID_CHANNEL_NAME = "ANDROID CHANNEL"; | |
public static final String IOS_CHANNEL_NAME = "IOS CHANNEL"; | |
private NotificationManager notificationManager; | |
//.. | |
public NotificationUtils(Context base) { | |
super(base); | |
createChannels(); | |
} | |
private void createChannels() { | |
getNotificationManager().createNotificationChannel(channelA()); | |
getNotificationManager().createNotificationChannel(channelB()); | |
//Alternatively, we can create multiple notification channels all at once, like below: | |
//getNotificationManager().createNotificationChannels(channelListContainingAandBInstances); | |
} | |
private NotificationChannel channelB() { | |
// create ios channel | |
NotificationChannel iosChannel = | |
new NotificationChannel(IOS_CHANNEL_ID, | |
IOS_CHANNEL_NAME, | |
NotificationManager.IMPORTANCE_HIGH); | |
iosChannel.enableLights(true); | |
iosChannel.enableVibration(true); | |
iosChannel.setLightColor(Color.GRAY); | |
iosChannel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC); | |
return iosChannel; | |
} | |
private NotificationChannel channelA() { | |
// create android channel | |
NotificationChannel androidChannel = | |
new NotificationChannel(ANDROID_CHANNEL_ID, | |
ANDROID_CHANNEL_NAME, | |
NotificationManager.IMPORTANCE_DEFAULT); | |
// Sets whether notifications posted to this channel should display notification lights | |
androidChannel.enableLights(true); | |
// Sets whether notification posted to this channel should vibrate. | |
androidChannel.enableVibration(true); | |
// Sets the notification light color for notifications posted to this channel | |
androidChannel.setLightColor(Color.GREEN); | |
// Sets whether notifications posted to this channel appear on the lockscreen or not | |
androidChannel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC); | |
return androidChannel; | |
} | |
//.. | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment