diff --git a/libs/sdk-bindings/bindings-android/lib/src/main/kotlin/breez_sdk_notification/ForegroundService.kt b/libs/sdk-bindings/bindings-android/lib/src/main/kotlin/breez_sdk_notification/ForegroundService.kt index e9df6ff07..c28bcd833 100644 --- a/libs/sdk-bindings/bindings-android/lib/src/main/kotlin/breez_sdk_notification/ForegroundService.kt +++ b/libs/sdk-bindings/bindings-android/lib/src/main/kotlin/breez_sdk_notification/ForegroundService.kt @@ -37,7 +37,7 @@ abstract class ForegroundService : SdkForegroundService, EventListener, Service( private var breezSDK: BlockingBreezServices? = null @Suppress("MemberVisibilityCanBePrivate") val serviceScope = CoroutineScope(Dispatchers.Main.immediate + SupervisorJob()) - private var logger: ServiceLogger = ServiceLogger() + protected var logger: ServiceLogger = ServiceLogger() private var config: ServiceConfig = ServiceConfig.default() private var jobs: MutableList = arrayListOf() diff --git a/libs/sdk-bindings/bindings-android/lib/src/main/kotlin/breez_sdk_notification/NotificationHelper.kt b/libs/sdk-bindings/bindings-android/lib/src/main/kotlin/breez_sdk_notification/NotificationHelper.kt index cceb6da16..72d66e728 100644 --- a/libs/sdk-bindings/bindings-android/lib/src/main/kotlin/breez_sdk_notification/NotificationHelper.kt +++ b/libs/sdk-bindings/bindings-android/lib/src/main/kotlin/breez_sdk_notification/NotificationHelper.kt @@ -72,17 +72,70 @@ class NotificationHelper { private const val TAG = "NotificationHelper" private var defaultClickAction: String? = null - fun registerNotificationChannels(context: Context, defaultClickAction: String? = null) { - this.defaultClickAction = defaultClickAction - + private fun getNotificationManager(context: Context): NotificationManager? { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager if (notificationManager.areNotificationsEnabled()) { - createNotificationChannelGroup(context, notificationManager) - createNotificationChannels(context, notificationManager) + return notificationManager + } + } + return null + } + + @SuppressLint("NewApi") + private fun createNotificationChannelGroup( + context: Context, + groupId: String, + groupName: String, + groupDescription: String, + ) { + getNotificationManager(context)?.also { manager -> + val channelGroup = NotificationChannelGroup( + groupId, + groupName, + ) + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { + channelGroup.description = groupDescription + } + + manager.createNotificationChannelGroup(channelGroup) + } + } + + @SuppressLint("NewApi") + fun createNotificationChannel( + context: Context, + channelId: String, + channelName: String, + channelDescription: String, + groupId: String, + importance: Int = NotificationManager.IMPORTANCE_DEFAULT, + ) { + getNotificationManager(context)?.also { manager -> + val applicationId = context.applicationContext.packageName + val notificationChannel = NotificationChannel( + "${applicationId}.${channelId}", + channelName, + importance + ).apply { + description = channelDescription + group = groupId } + + manager.createNotificationChannel(notificationChannel) + } + } + + @SuppressLint("NewApi") + fun registerNotificationChannels(context: Context, defaultClickAction: String? = null) { + this.defaultClickAction = defaultClickAction + + getNotificationManager(context)?.also { manager -> + createNotificationChannelGroups(context, manager) + createNotificationChannels(context, manager) Log.d(TAG, "Registered notification channels") } } @@ -167,7 +220,7 @@ class NotificationHelper { } @RequiresApi(Build.VERSION_CODES.O) - private fun createNotificationChannelGroup( + private fun createNotificationChannelGroups( context: Context, notificationManager: NotificationManager, ) {