5.0动态权限

一 :声明常量
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;
}
}
 
posted @ 2018-04-14 14:13  dub  阅读(116)  评论(0编辑  收藏  举报