Skip to content

Instantly share code, notes, and snippets.

@Lavanyagaur22
Created January 4, 2020 17:09
Show Gist options
  • Save Lavanyagaur22/fb7da125a9561f8d280ed162f0e0a47e to your computer and use it in GitHub Desktop.
Save Lavanyagaur22/fb7da125a9561f8d280ed162f0e0a47e to your computer and use it in GitHub Desktop.
private fun createNotificationChannel() {
// 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) {
val name = getString(R.string.channel_name) //name of the channel
val descriptionText = getString(R.string.channel_description)
val importance = NotificationManager.IMPORTANCE_DEFAULT //importance of the channel
// Create a NotificationChannel
val channel = NotificationChannel(CHANNEL_ID, name, importance).apply {
description = descriptionText
}
// Register the channel with the system, her nm is the NotificationManager object created above.
nm.createNotificationChannel(channel)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment