代码片段分享

android 11 cannot open camera i

2020-11-25  本文已影响0人  花艺荣

业务需求要在前台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:

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

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

上一篇下一篇

猜你喜欢

热点阅读