1***@qq.com
1***@qq.com
  • 发布:2024-01-21 11:35
  • 更新:2024-01-24 17:04
  • 阅读:274

uni-app uts获取不到摄像头数量

分类:uni-app x

import { UTSAndroid } from "io.dcloud.uts";
import Context from "android.content.Context"
import CameraManager from "android.hardware.camera2.CameraManager"
import CameraAccessException from "android.hardware.camera2.CameraAccessException"

export const queryCameraCount = () => {
let permission = ["android.permission.CAMERA"]

let denied = UTSAndroid.checkSystemPermissionGranted(UTSAndroid.getUniActivity()!, permission)  
if (!denied) {  
    UTSAndroid.requestSystemPermission(UTSAndroid.getUniActivity()!, permission, function (allRight : boolean, grantedList : string[]) {  
        if (allRight) {  
            const d = UTSAndroid.getAppContext()  
            const e = d?.getSystemService(Context.CAMERA_SERVICE) as CameraManager;  
            console.log(e.getCameraIdList())  
        } else {  
            // 用户仅同意了 grantedList中的权限  
        }  
    }, function (doNotAskAgain : boolean, grantedList : string[]) {  
        // 用户拒绝了部分权限,仅允许了grantedList中的权限  
        if (doNotAskAgain) {  
            // 用户拒绝了权限,并且选择不再询问  
        }  
    })  
}else{  
    const d = UTSAndroid.getAppContext()  
    const e = d?.getSystemService(Context.CAMERA_SERVICE) as CameraManager;  

    let a = e.getCameraIdList();  
    console.log(a)  
}  

}

2024-01-21 11:35 负责人:无 分享
已邀请:
DCloud_Android_DQQ

DCloud_Android_DQQ

报错信息是什么

即时通讯开发

即时通讯开发

老铁你解决了吗 我的也是获取不到

  • DCloud_Android_DQQ

    修改后的可运行代码,贴出来了。 https://ask.dcloud.net.cn/question/185768

    2024-01-24 17:28

即时通讯开发

即时通讯开发

简单示例,打印的为空

  • 木四

    请问这个问题你解决了吗,同样遇到 了

    2024-02-18 17:42

要回复问题请先登录注册