1. 程式人生 > >5.0動態權限

5.0動態權限

.get ride grant rmi bsp private manifest ret int

一 :聲明常量
private static final int PERMISSIONS_REQUEST_CAMERA = 800;

二:註冊權限
cameraView.getCameraControl().setPermissionCallback(permissionCallback);


三:請求權限
private PermissionCallback permissionCallback = new PermissionCallback() {
@Override
public boolean onRequestPermission() {
ActivityCompat.requestPermissions(BaiduOCRActivity.this,new String[] {Manifest.permission.CAMERA},PERMISSIONS_REQUEST_CAMERA);
return false;
}
};

四:權限執行
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,@NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
switch (requestCode) {
case PERMISSIONS_REQUEST_CAMERA: {
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
cameraView.getCameraControl().refreshPermission();
} else {
Toast.makeText(getApplicationContext(), com.baidu.ocr.ui.R.string.camera_permission_required, Toast.LENGTH_LONG).show();
}
break;
}
default: break;
}
}
 

5.0動態權限