android 11 cannot open camera i
业务需求要在前台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'
- 且在两种设备上,即便APP target为29 也报错;
- 三星的设备上即便应用在前台打开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 theACCESS_FINE_LOCATION
orACCESS_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上也是不行了