Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access Microphone / Camera in background in Android 11

Access to the Microphone in the background is stopped in Android 11. There are only 3 options, Allow when in-use, Allow once, and Deny.

How to make the app get access to the microphone in the background all the time in Android 11? Is there any workaround?

like image 387
Srihari Karanth Avatar asked Aug 31 '25 20:08

Srihari Karanth


2 Answers

Now we have to specify a type for our foreground service (https://developer.android.com/guide/components/foreground-services#types):

<manifest>
    ...
    <service ...
        android:foregroundServiceType="camera|microphone" />
</manifest>

But in some cases our foreground service can't still access camera or microphone even if we specified android:foregroundServiceType:

If a foreground service was started while app was in background (wasn't visible to a user - no visible activities), for example on device boot (BOOT_COMPLETED) broadcast, then such service can't start using camera, microphone

If a foreground service was started while app was in foreground (was visible to a user - some visible activity) then such service can start using camera, microphone

Info from: https://developer.android.com/guide/components/foreground-services#bg-access-restrictions

My issue Camera2 cameraManager.openCamera exception from time to time on some devices

like image 154
user924 Avatar answered Sep 06 '25 23:09

user924


The new Android Developer Policy restricts access to Microphone and Camera in the background.

Using Accessibility Service one can still use the feature in the background. However, the notification will always be on.

like image 23
Srihari Karanth Avatar answered Sep 06 '25 23:09

Srihari Karanth