diff --git a/stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/notifications/internal/service/CallService.kt b/stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/notifications/internal/service/CallService.kt index 82c46753cf..f8e69537d8 100644 --- a/stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/notifications/internal/service/CallService.kt +++ b/stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/notifications/internal/service/CallService.kt @@ -481,19 +481,21 @@ internal class CallService : Service() { } private fun registerToggleCameraBroadcastReceiver() { - if (!isToggleCameraBroadcastReceiverRegistered) { - try { - registerReceiver( - toggleCameraBroadcastReceiver, - IntentFilter().apply { - addAction(Intent.ACTION_SCREEN_ON) - addAction(Intent.ACTION_SCREEN_OFF) - addAction(Intent.ACTION_USER_PRESENT) - }, - ) - isToggleCameraBroadcastReceiverRegistered = true - } catch (e: Exception) { - logger.d { "Unable to register ToggleCameraBroadcastReceiver." } + serviceScope.launch { + if (!isToggleCameraBroadcastReceiverRegistered) { + try { + registerReceiver( + toggleCameraBroadcastReceiver, + IntentFilter().apply { + addAction(Intent.ACTION_SCREEN_ON) + addAction(Intent.ACTION_SCREEN_OFF) + addAction(Intent.ACTION_USER_PRESENT) + }, + ) + isToggleCameraBroadcastReceiverRegistered = true + } catch (e: Exception) { + logger.d { "Unable to register ToggleCameraBroadcastReceiver." } + } } } } @@ -563,6 +565,11 @@ internal class CallService : Service() { super.onDestroy() } + override fun stopService(name: Intent?): Boolean { + stopService() + return super.stopService(name) + } + /** * Handle all aspects of stopping the service. */