*Creating a notification channel*
- Creating notification channels are done creating a [NotificationChannel| https://developer.android.com/reference/android/app/NotificationChannel.html#enableLights%28boolean%29] instance, configuring it, and passing it into createNotificationChannel() from the Notification manager:
``` {code: java } NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
String channelId = "some_channel_id"; CharSequence channelName = "Some Channel"; int importance = NotificationManager.IMPORTANCE_LOW; NotificationChannel notificationChannel = new NotificationChannel(channelId, channelName, importance); notificationChannel.enableLights(true); notificationChannel.setLightColor(Color.RED); notificationChannel.enableVibration(true); notificationChannel.setVibrationPattern(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400}); notificationManager.createNotificationChannel(notificationChannel); ``` {code}
_+Some [NotificationChannel|https://developer.android.com/reference/android/app/NotificationChannel.html#enableLights%28boolean%29] methods available to us:+_ - `getId()` — Retrieve the ID of the given channel - `enableLights() `— If the device in use supports notification lights, then this states whether or not this notification channel should show a light - `setLightColor() `— If we decide that our channel supports notification lights, then this allows use to pass an int value that defines the color to be used for the notification light - `enableVibration() `— State whether or not notifications from this channel should vibrate when shown on the device - `setVibrationPattern()` — Set the vibration pattern to be used (long[]) if vibration is enabled for this notification channel - `setImportance()` — Set the level of interruption for the given notification channel. This can be one of these importance values. - `getImportance() `— Retrieve the importance value for the given notification channel - `setSound() `— Provide a Uri for a sound to be played when a notification is posted to this channel - `getSound() `— Retrieve the sound assigned to this notification - `setGroup() `— Set the group in which the notification is assigned to - `getGroup()` — Retrieve the group in which the notification has been assigned to - `setBypassDnd() `— Set whether or not the notification should bypass Do Not Disturb mode (the INTERRUPTION_FILTER_PRIORITY value) - `canBypassDnd()` — Retrieve whether or not the notification can bypass Do Not Disturb mode - `getName() `— Retrieve the user visible name for the specified channel - `setLockScreenVisibility()` — Set whether or not notifications from this channel should be displayed on the lock screen - `getLockscreenVisibility() `— Retrieve whether or not notifications from this channel will appear on the lockscreen - `getAudioAttributes() `— Retrieve the audio attributes for the sound which has been assigned to the corresponding notification channel - `canShowBadge()` — Retrieve whether or not notifications from this channel are able to appear as badges within a launcher application |
|