diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 601aa422..4048c2df 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -7,6 +7,7 @@ + diff --git a/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt b/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt index 3e815b40..137a1d4e 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt @@ -11,6 +11,7 @@ import android.content.Context import android.content.Intent import android.content.IntentFilter import android.content.pm.PackageManager +import android.content.pm.ServiceInfo.FOREGROUND_SERVICE_TYPE_MICROPHONE import android.content.pm.ServiceInfo.FOREGROUND_SERVICE_TYPE_PHONE_CALL import android.database.ContentObserver import android.media.* @@ -1161,10 +1162,20 @@ class BaresipService: Service() { .setCustomContentView(notificationLayout) if (VERSION.SDK_INT >= 31) snb.foregroundServiceBehavior = Notification.FOREGROUND_SERVICE_DEFAULT - if (VERSION.SDK_INT >= 29) - startForeground(STATUS_NOTIFICATION_ID, snb.build(), FOREGROUND_SERVICE_TYPE_PHONE_CALL) - else - startForeground(STATUS_NOTIFICATION_ID, snb.build()) + try { + if (VERSION.SDK_INT >= 29) + startForeground( + STATUS_NOTIFICATION_ID, snb.build(), + if (VERSION.SDK_INT >= 30) + FOREGROUND_SERVICE_TYPE_PHONE_CALL or FOREGROUND_SERVICE_TYPE_MICROPHONE + else + FOREGROUND_SERVICE_TYPE_PHONE_CALL + ) + else + startForeground(STATUS_NOTIFICATION_ID, snb.build()) + } catch (e: Exception) { + Log.e(TAG, "Failed to start foreground service") + } } private fun updateStatusNotification() {