Why is audio and video capture ineffective on Android 9 when the app is locked or switched to the background?
To enhance user privacy, Android 9 updated some permission restrictions and applied strong restrictions on background access. The relevant information is as follows:
Limited access to sensors in background
Android 9 limits the ability for background apps to access user input and sensor data. If your app is running in the background on a device running Android 9, the system applies the following restrictions to your app:
- Your app cannot access the microphone or camera.
- Sensors that use the continuous reporting mode, such as accelerometers and gyroscopes, don't receive events.
- Sensors that use the on-change or one-shot reporting modes don't receive events.
If your app needs to detect sensor events on devices running Android 9, use a foreground service.
For details, see Android Behavior Changes.
Currently, Android officially has not clearly stated how to handle background audio or video capture. It only states that using a foreground service allows the app to work normally.
If Android 9 device users need to capture audio or video after locking the screen or switching to the background, you can start a Service before locking the screen or switching to the background, and terminate the Service before exiting the lock screen or returning to the foreground. For related operations on starting a Service, refer to Service.

