我试图打开相机,但错误关闭了应用程序。昨天的代码工作,由于某种原因,现在没有物理的手机上运行CameraManager.openCamera缺少所需权限:android.permission.CAMERA
私人无效connectCamera(){
CameraManager cameraManager = (CameraManager) context.getSystemService(Context.CAMERA_SERVICE);
try {
if (!mCameraOpenCloseLock.tryAcquire(2500, TimeUnit.MILLISECONDS)) {
throw new RuntimeException("Time out waiting to lock camera opening.");
}
int permissionCheck = ActivityCompat.checkSelfPermission(context, Manifest.permission.CAMERA);
if (permissionCheck != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions((Activity)context, PERMISSIONS, PERMISSION_ALL);
//java.lang.SecurityException: Lacking privileges to access camera service
}
cameraManager.openCamera("0", mCameraDeviceStateCallback,null);
} catch (CameraAccessException e) {
e.printStackTrace();
} catch (InterruptedException e) {
throw new RuntimeException("Interrupted while trying to lock camera opening.", e);
}
}
java.lang.SecurityException: Lacking privileges to access camera service