动态权限

//权限的数组
private static String[] PERMISSIONS_STORAGE = {
//读取内存权限
        Manifest.permission.READ_EXTERNAL_STORAGE,
//写入内存权限
        Manifest.permission.WRITE_EXTERNAL_STORAGE
};
private static int REQUEST_PERMISSION_CODE = 1;

 

//动态权限的方法
private void getQuanxian() {
    if (Build.VERSION.SDK_INT>Build.VERSION_CODES.LOLLIPOP){
        if (ActivityCompat.checkSelfPermission(getActivity(),Manifest.permission.WRITE_EXTERNAL_STORAGE)!=PackageManager.PERMISSION_GRANTED){
            ActivityCompat.requestPermissions(getActivity(),PERMISSIONS_STORAGE,REQUEST_PERMISSION_CODE);
        }
    }

}

你可能感兴趣的:(动态权限)