注:仅作为个人笔记,如浏览有疑问,可评论、私信或参考他人文章
整个类
/**
* 动态获取权限的类
* 所有类都是静态类可以直接调用
* 传入Activity即可
*/
public class PermissionUtils{
/**
* 存储
* @param act Activity
*/
public static void sdCard(Activity act) {
ActivityCompat.requestPermissions(act, new String[]{
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE
},1);
}
/**
* 网络
* @param act Activity
*/
public static void internet(Activity act) {
ActivityCompat.requestPermissions(act, new String[]{
Manifest.permission.INTERNET,
Manifest.permission.ACCESS_NETWORK_STATE
},1);
}
/**
* 位置
* @param act Activity
*/
public static void location(Activity act){
ActivityCompat.requestPermissions(act, new String[]{
Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.ACCESS_COARSE_LOCATION
},1);
}
}
SD卡
/**
* 存储
* @param act
*/
public static void sdCard(Activity act) {
ActivityCompat.requestPermissions(act, new String[]{
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE
},1);
}
网络
/**
* 网络及判断网络
* @param act
*/
public static void internet(Activity act) {
ActivityCompat.requestPermissions(act, new String[]{
Manifest.permission.INTERNET,
Manifest.permission.ACCESS_NETWORK_STATE
},1);
}
位置
/**
* 位置
* @param act
*/
public static void location(Activity act){
ActivityCompat.requestPermissions(act, new String[]{
Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.ACCESS_COARSE_LOCATION
},1);
}