一.自己封装的原生请求方法
1.主要使用方法
(1)申请权限组方法
public static void requestGroupPermission(final Context context, int requestCode, PermissionGrant grant)
requestCode的值
// 摄像头权限
public static final int CODE_CAMERA = 0;
// 传感器权限
public static final int CODE_SENSORS = 1;
// 录制音频权限
public static final int CODE_MICROPHONE = 2;
// 日历权限
public static final int CODE_CALENDAR = 3;
// 定位权限
public static final int CODE_LOCATION = 4;
// 存储权限
public static final int CODE_STORAGE = 5;
// 通讯录权限
public static final int CODE_CONTACTS = 6;
// 短信权限
public static final int CODE_SMS = 7;
// 电话权限
public static final int CODE_PHONE = 8;
(2)最终结果回调函数
public interface PermissionGrant
(3)onRequestPermissionsResult的请求结果回调
public static void requestGroupResult(@NonNull Context context, final int requestCode, String[] permissions, int[] grantResults, PermissionGrant permissionGrant)
2.PermissionHelper里面具有的方法
(1)检查权限版本
public static int checkSelfPermission(Context context, String requestPermission)
(2)从权限组中循环获取没有同意的权限
public static ArrayList<String> getNoGrantedPermission(Context context, int requestCode, boolean isShouldRationale)
(3)拒绝获取权限的对话框信息
private static void shouldShowRationale(final Context context, final int requestCode, final String[] requestPermission)
(4)对话框页面封装
private static void showMessageOKCancel(final Context context, String message, DialogInterface.OnClickListener okListener)
(5)跳转设置
private static void openSettingActivity(final Context context, String message)
网友评论