发布网友 发布时间:2022-04-24 18:41
共1个回答
热心网友 时间:2023-11-03 00:07
//动态开启权限,在manifest中也要配置
private static final int REQUEST_EXTERNAL_STORAGE = 1;
private static String[] PERMISSIONS_STORAGE = {//读写权限集合
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE };
private void verifyStoragmissions(Activity activity) {
int permission = ActivityCompat.checkSelfPermission(activity,
"android.permission.WRITE_EXTERNAL_STORAGE");
int permission1 = ActivityCompat.checkSelfPermission(activity,
"android.permission.READ_EXTERNAL_STORAGE");
if (permission != PackageManager.PERMISSION_GRANTED || permission1 != PackageManager.PERMISSION_GRANTED) {
//判断读写权限是否存在,不在就打开权限
ActivityCompat.requestPermissions(activity, PERMISSIONS_STORAGE, REQUEST_EXTERNAL_STORAGE);
}
}