美文网首页代码片段分享
android 11 cannot open camera i

android 11 cannot open camera i

作者: 花艺荣 | 来源:发表于2020-11-25 10:59 被阅读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:

    • 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上也是不行了

    相关文章

      网友评论

        本文标题:android 11 cannot open camera i

        本文链接:https://www.haomeiwen.com/subject/ygggiktx.html