- PERMISSIONS_STORAGE 可以加入其他权限
- 我这里只写了读和写的权限,根据自己需求添加即可
private static String[] PERMISSIONS_STORAGE = {android.Manifest.permission.READ_EXTERNAL_STORAGE,//读取外部存储
android.Manifest.permission.WRITE_EXTERNAL_STORAGE};//写入外部存储
private static int REQUEST_PERMISSION_CODE = 3;
public void getPermission(Activity obj){
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) {
for (int i = 0 ; i < PERMISSIONS_STORAGE.length ; i++){
if (ActivityCompat.checkSelfPermission(obj,
PERMISSIONS_STORAGE[i])!= PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(obj, PERMISSIONS_STORAGE, REQUEST_PERMISSION_CODE);
}
}
}
}
|