private static final int REQUEST_EXTERNAL_STORAGE = 0; private static final int REQUEST_CAMERA = 2; private static String[] PERMISSIONS_STORAGE = { Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE,Manifest.permission.CAMERA};
// TODO: 2016/10/6 选择图片前,为6.0动态添加权限 int permission = ActivityCompat.checkSelfPermission(SubmitCompleteActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE); int permission2 = ActivityCompat.checkSelfPermission(SubmitCompleteActivity.this, Manifest.permission.CAMERA); if (permission != PackageManager.PERMISSION_GRANTED) { // 没有权限,加权限 ActivityCompat.requestPermissions(SubmitCompleteActivity.this, PERMISSIONS_STORAGE, REQUEST_EXTERNAL_STORAGE); } else if (permission2 != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions(SubmitCompleteActivity.this, PERMISSIONS_STORAGE, REQUEST_CAMERA); } else {//加了权限 //打开相册页面 PhotoPicker.builder() .setPhotoCount(photoNumber) .setGridColumnCount(PHOTO_MAX_ROW_NUM) .start(SubmitCompleteActivity.this); }
Android6.0手动加权限
最新推荐文章于 2022-12-12 11:17:06 发布