diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/system/NotificationExtensions.kt b/app/src/main/java/eu/kanade/tachiyomi/util/system/NotificationExtensions.kt index 3958d0cdf..5a37d6615 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/system/NotificationExtensions.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/system/NotificationExtensions.kt @@ -1,14 +1,16 @@ package eu.kanade.tachiyomi.util.system -import android.annotation.SuppressLint +import android.Manifest import android.app.Notification import android.app.NotificationManager import android.content.Context +import android.os.Build import androidx.core.app.NotificationChannelCompat import androidx.core.app.NotificationChannelGroupCompat import androidx.core.app.NotificationCompat import androidx.core.app.NotificationManagerCompat import androidx.core.app.NotificationManagerCompat.NotificationWithIdAndTag +import androidx.core.content.PermissionChecker import androidx.core.content.getSystemService import eu.kanade.tachiyomi.R @@ -20,22 +22,18 @@ fun Context.notify(id: Int, channelId: String, block: (NotificationCompat.Builde this.notify(id, notification) } -@SuppressLint("MissingPermission") fun Context.notify(id: Int, notification: Notification) { - // TODO: check for permission once targeting SDK 33+ -// if (PermissionChecker.checkSelfPermission(this, Manifest.permission.POST_NOTIFICATIONS) != PermissionChecker.PERMISSION_GRANTED) { -// return -// } + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU && PermissionChecker.checkSelfPermission(this, Manifest.permission.POST_NOTIFICATIONS) != PermissionChecker.PERMISSION_GRANTED) { + return + } NotificationManagerCompat.from(this).notify(id, notification) } -@SuppressLint("MissingPermission") fun Context.notify(notificationWithIdAndTags: List) { - // TODO: check for permission once targeting SDK 33+ -// if (PermissionChecker.checkSelfPermission(this, Manifest.permission.POST_NOTIFICATIONS) != PermissionChecker.PERMISSION_GRANTED) { -// return -// } + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU && PermissionChecker.checkSelfPermission(this, Manifest.permission.POST_NOTIFICATIONS) != PermissionChecker.PERMISSION_GRANTED) { + return + } NotificationManagerCompat.from(this).notify(notificationWithIdAndTags) }