The second Android 11 Developer Preview is now available, test it out and share your feedback.

Foreground service types in Android 11

Since Android 9, apps are limited to access the camera and microphone in the foreground only. Android 11 further protects users by introducing changes to how foreground services can access data related to the camera and microphone. If your app targets Android 11 and accesses these types of data in a foreground service, you need to include the new camera and microphone types in the foregroundServiceType attribute of that foreground service's declaration.

Example using location and camera

If a foreground service in your app needs to access data related to the device's location and camera, declare the service as shown in the following snippet:

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

Example using location, camera, and microphone

If a foreground service needs to access location, the camera, and the microphone, declare the service as shown in the following snippet:

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