我試圖打開相機,但錯誤關閉了應用程序。昨天的代碼工作,由於某種原因,現在沒有物理的手機上運行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