产品 / 解决方案
平台 / 框架

为什么 Android 9 应用锁屏或切后台后采集音视频无效?

产品 / 插件:实时音视频 / 实时语音 / 低延迟直播 / 超低延迟直播

平台 / 框架:Android

更新时间:2022-11-15 14:39


为了增强用户隐私,Android 9 更新了一些权限限制,系统对后台访问做了强限制,相关信息如下:

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.

详见 Android 行为变更

目前,Android 官方没有明确说明后台采集声音或视频应如何处理,仅说明了使用前台服务可以让应用正常工作。

如果 Android 9 设备用户有锁屏或切后台后采集音频或视频的需求,可以在锁屏或退至后台前起一个 Service,并在退出锁屏或返回前台前终止 Service。起 Service 的相关操作可参考 Service

本篇目录
下载 PDF