業(yè)務(wù)需求要在前臺service中使用Camera
在三星Android 11(One UI 3.0谣膳,到目前還未正式發(fā)布)上報 錯:
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'
- 且在兩種設(shè)備上,即便APP target為29 也報錯铅乡;
- 三星的設(shè)備上即便應用在前臺打開foregroudservice后APP再退到后臺也也報錯继谚;
測試機上還會繼續(xù)跑;
查文檔關(guān)于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上也是不行了