android 11 cannot open camera in Foreground Service when APP in background

业务需求要在前台service中使用Camera

在三星Android 11(One UI 3.0,到目前还未正式发布)上报 错:
an error occurred while connecting to camera 0: status(-8, ex_service_specific): '6: validateclientpermissionslocked ...cannot open camera from background

在Android测试机上报:
An error occurred while connecting to camera 0: Status(-8, EX_SERVICE_SPECIFIC): '6: connectHelper:1735: Camera "0" disabled by policy'

  1. 且在两种设备上,即便APP target为29 也报错;
  2. 三星的设备上即便应用在前台打开foregroudservice后APP再退到后台也也报错;
    测试机上还会继续跑;

查文档关于foreground service在Android 11上的限制,说是
If your app starts a foreground service while running in the background, the foreground service cannot access the microphone or camera. Additionally, the service cannot access location unless your app has background location access.

While-in-use restrictions

On Android 11 (API level 30) and higher, if your app starts a foreground service while running in the background, the service has the following access restrictions:

  • Unless the user has granted the ACCESS_BACKGROUND_LOCATION permission to your app, the service cannot access location.
  • The service cannot access the microphone or camera.

If, on the other hand, your app starts a foreground service while running in the foreground, the service has the following access allowances:

  • If the user has granted the ACCESS_BACKGROUND_LOCATION permission to your app, the service can access location all the time. Otherwise, if the user has granted the ACCESS_FINE_LOCATION or ACCESS_COARSE_LOCATION permission to your app, the service has while-in-use access to location.
  • If the user has granted the CAMERA permission to your app, the service has while-in-use access to the camera.
  • If the user has granted the RECORD_AUDIO permission to your app, the service has while-in-use access to the microphone.

当然, 我的 target Api是29,在三星的One UI 3.0上也是不行了

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容