PermissionUtils类权限问题
Opened this issue · 0 comments
YuJunKui1995 commented
`package edu.wuwang.codec.utils;
import android.app.Activity;
import android.content.pm.PackageManager;
import android.os.Build;
import android.support.v4.app.ActivityCompat;
/**
-
Description:
*/
public class PermissionUtils {public static void askPermission(Activity context, String[] permissions, int req, Runnable
runnable) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {boolean isGetPermission = true; for (String permission : permissions) { int result = ActivityCompat.checkSelfPermission(context, permission); if (result != PackageManager.PERMISSION_GRANTED) { isGetPermission = false; break; } } if (isGetPermission) { runnable.run(); } else { ActivityCompat.requestPermissions(context, permissions, req); } } else { runnable.run(); }
}
public static void onRequestPermissionsResult(boolean isReq, int[] grantResults, Runnable
okRun, Runnable deniRun) {
if (isReq) {boolean isGetPermission = true; for (int grantResult : grantResults) { if (grantResult != PackageManager.PERMISSION_GRANTED) { isGetPermission = false; break; } } if (isGetPermission) { okRun.run(); } else { deniRun.run(); } }
}
}
`