From 21ab5a47a3217e48368e10232b53e0991e3356c3 Mon Sep 17 00:00:00 2001 From: jacquarg Date: Thu, 13 Nov 2025 12:22:27 +0100 Subject: [PATCH] fix:3720:service notification re-show on reboot. --- .../io/heckel/ntfy/service/SubscriberService.kt | 4 ++-- .../androidinterfaces/NotificationChannelHider.kt | 15 +++++++++++---- 2 files changed, 13 insertions(+), 6 deletions(-) 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 852ebcbb..0579f3b7 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 0497006b..dc13cef9 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 -- GitLab