Skip to content

Instantly share code, notes, and snippets.

@vreamer
Last active August 25, 2020 04:30
Show Gist options
  • Select an option

  • Save vreamer/979b929a72e3c12785f9b9a8b29b8dd3 to your computer and use it in GitHub Desktop.

Select an option

Save vreamer/979b929a72e3c12785f9b9a8b29b8dd3 to your computer and use it in GitHub Desktop.
Create Notification Channel
package com.example.direct_reply_notification
import android.app.NotificationChannel
import android.app.NotificationManager
import android.content.Context
import android.graphics.Color
import android.os.Build
import androidx.core.app.NotificationManagerCompat
object NotificationHelper {
private const val CHANNEL_ID = "01"
private const val CHANNEL_NAME = "Ideas"
fun createChannel(context: Context) {
val manager = NotificationManagerCompat.from(context)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { // check if build version is later than Android 8.0 (Oreo, API level 26)
val importance = NotificationManager.IMPORTANCE_DEFAULT
val channel = NotificationChannel(CHANNEL_ID, CHANNEL_NAME, importance)
channel.description = "It's a personal channel"
channel.enableVibration(false)
channel.enableLights(true)
channel.lightColor = Color.RED
manager.createNotificationChannel(channel)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment