直接上代码,大家应该能看懂
private static List<String> permissionList;
public static void getPermission(Activity context,String... permission) {
permissionList = new ArrayList<>();
for (int i = 0;i<permission.length;i++){
if (ContextCompat.checkSelfPermission(context,permission[i])
!= PackageManager.PERMISSION_GRANTED){
permissionList.add(permission[i]);
}
}
if (permissionList.size()>0){
String[] permissions = new String[permissionList.size()];
for (int i = 0;i<permissionList.size();i++){
permissions[i] = permissionList.get(i);
}
ActivityCompat.requestPermissions(context, permissions,1);
}
}
把上面的代码复制到自己的工具类里面然后调用就行了,调用方式
BaseTool.getPermission(this, android.Manifest.permission.CAMERA,
android.Manifest.permission.WRITE_EXTERNAL_STORAGE,
android.Manifest.permission.ACCESS_FINE_LOCATION);
如果有什么问题希望大家共同探讨