diff --git a/app/src/main/java/io/heckel/ntfy/service/SubscriberService.kt b/app/src/main/java/io/heckel/ntfy/service/SubscriberService.kt index 852ebcbbab0cc84babbc525795e9517c7af70eb9..0579f3b76123fb14e139debae2313149f5e385fc 100644 --- a/app/src/main/java/io/heckel/ntfy/service/SubscriberService.kt +++ b/app/src/main/java/io/heckel/ntfy/service/SubscriberService.kt @@ -257,8 +257,8 @@ class SubscriberService : Service() { it.setShowBadge(false) // Don't show long-press badge it } - notificationManager.createNotificationChannel(channel) - NotificationChannelHider(this, GlobalScope).hideChannel(NOTIFICATION_CHANNEL_ID) + + NotificationChannelHider(this, GlobalScope).createAndHideChannel(channel) return notificationManager } return null diff --git a/notificationsreceiver/src/main/java/foundation/e/notificationsreceiver/bridges/androidinterfaces/NotificationChannelHider.kt b/notificationsreceiver/src/main/java/foundation/e/notificationsreceiver/bridges/androidinterfaces/NotificationChannelHider.kt index 0497006b4a650feaab63fbd8774f65f1c1c6b7df..dc13cef929fd77d4af76f47af083a760229638d8 100644 --- a/notificationsreceiver/src/main/java/foundation/e/notificationsreceiver/bridges/androidinterfaces/NotificationChannelHider.kt +++ b/notificationsreceiver/src/main/java/foundation/e/notificationsreceiver/bridges/androidinterfaces/NotificationChannelHider.kt @@ -36,7 +36,17 @@ class NotificationChannelHider( private const val UPDATE_CHANNEL_DELAY = 30000L } - fun hideChannel(channelId: String) { + private val notificationManager: NotificationManager by lazy { + context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager + } + + fun createAndHideChannel(notificationsChannel: NotificationChannel) { + // Set blockable before create the channel, otherwise it will re-show on each create call. + NotificationChannelHiddenMethods.setBlockable(notificationsChannel, true) + + notificationManager.createNotificationChannel(notificationsChannel) + + val channelId = notificationsChannel.id // Hide works if updating importance is called after the notification is // used as the ForegroundService notification. This may take a few seconds sometimes, so // we wait a few seconds. @@ -47,9 +57,6 @@ class NotificationChannelHider( } private fun setImportanceToNone(channelId: String) { - val notificationManager: NotificationManager by lazy { - context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager - } val notificationsChannel: NotificationChannel = notificationManager.getNotificationChannel(channelId) NotificationChannelHiddenMethods.setBlockable(notificationsChannel, true) notificationsChannel.importance = NotificationManager.IMPORTANCE_NONE