diff --git a/pil/src/main/java/org/openvoipalliance/androidphoneintegration/service/NotificationButtonReceiver.kt b/pil/src/main/java/org/openvoipalliance/androidphoneintegration/service/NotificationButtonReceiver.kt index b900aa0..afed2f7 100644 --- a/pil/src/main/java/org/openvoipalliance/androidphoneintegration/service/NotificationButtonReceiver.kt +++ b/pil/src/main/java/org/openvoipalliance/androidphoneintegration/service/NotificationButtonReceiver.kt @@ -20,6 +20,10 @@ internal class NotificationButtonReceiver : BroadcastReceiver() { pil.notifications.dismissStale() + // We need to start the VoIP service here, or we don't have access to the microphone. + // See: https://developer.android.com/guide/components/foreground-services#bg-access-restriction-exemptions + context.startService(Intent(context, VoIPService::class.java)) + try { val action = valueOf(intent.action ?: "") diff --git a/pil/src/main/java/org/openvoipalliance/androidphoneintegration/service/VoIPService.kt b/pil/src/main/java/org/openvoipalliance/androidphoneintegration/service/VoIPService.kt index 5c846e1..9d7123a 100644 --- a/pil/src/main/java/org/openvoipalliance/androidphoneintegration/service/VoIPService.kt +++ b/pil/src/main/java/org/openvoipalliance/androidphoneintegration/service/VoIPService.kt @@ -9,6 +9,7 @@ import android.os.Build import android.os.Handler import android.os.Looper import android.os.PowerManager +import org.linphone.core.tools.Log import org.linphone.core.tools.service.CoreService import org.openvoipalliance.androidphoneintegration.PIL import org.openvoipalliance.androidphoneintegration.call.CallDirection @@ -62,7 +63,12 @@ internal class VoIPService : CoreService(), PILEventListener { FOREGROUND_SERVICE_TYPE_PHONE_CALL } - startForeground(id, notification, types) + try { + startForeground(id, notification, types) + } catch (e: Exception) { + pil.writeLog("Can't start service as foreground! $e") + } + } else { startForeground(id, notification) }