only setting notification channel for supported android versions

This commit is contained in:
Adam Brown 2022-03-17 19:41:02 +00:00
parent 7e82cf1569
commit 50f0ba4e3c
1 changed files with 10 additions and 7 deletions

View File

@ -2,6 +2,7 @@ package app.dapk.st.notifications
import android.app.NotificationChannel
import android.app.NotificationManager
import android.os.Build
private const val channelId = "message"
@ -10,14 +11,16 @@ class NotificationChannels(
) {
fun initChannels() {
if (notificationManager.getNotificationChannel(channelId) == null) {
notificationManager.createNotificationChannel(
NotificationChannel(
channelId,
"messages",
NotificationManager.IMPORTANCE_HIGH,
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
if (notificationManager.getNotificationChannel(channelId) == null) {
notificationManager.createNotificationChannel(
NotificationChannel(
channelId,
"messages",
NotificationManager.IMPORTANCE_HIGH,
)
)
)
}
}
}