Skip to content

Instantly share code, notes, and snippets.

@molidev8
Last active June 13, 2022 17:16
Show Gist options
  • Save molidev8/66d2eed25e0576b2301c006e46dd127c to your computer and use it in GitHub Desktop.
Save molidev8/66d2eed25e0576b2301c006e46dd127c to your computer and use it in GitHub Desktop.
A function to create a notification channel
fun createChannel(
context: Context,
channelId = CHANNEL_ID,
@StringRes channelName: Int,
@StringRes channelDescription: Int,
importanceLevel: Int = NotificationManager.IMPORTANCE_HIGH
) {
val channel = NotificationChannel(
context.getString(channelId),
context.getString(channelName),
importanceLevel
).apply {
description = context.getString(channelDescription)
}
val notificationManager =
context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
notificationManager.createNotificationChannel(channel)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment