1、功能简述
用于6.0+运行权限请求
2、gradle接入
implementation 'com.karumi:dexter:5.0.0'
3、使用方法
(1)单个权限
String permission = "...";
Dexter.withActivity(activity)
.withPermission(permission) .withListener(new PermissionListener() { @Override public void onPermissionGranted(PermissionGrantedResponse response) { // 权限通过 } @Override public void onPermissionDenied(PermissionDeniedResponse response) { // 权限拒绝 } @Override public void onPermissionRationaleShouldBeShown(PermissionRequest permission, PermissionToken token) { // 需要重新请求权限 } }).check();(2)多个权限
String[] permissions = new String[]{ ...}; Dexter.withActivity(activity) .withPermissions(permissions) .withListener(new MultiplePermissionsListener() { @Override public void onPermissionsChecked(MultiplePermissionsReport report) { boolean granted = report.areAllPermissionsGranted(); if (granted) { // 权限通过 }else { // 权限拒绝 } } @Override public void onPermissionRationaleShouldBeShown(Listpermissions, PermissionToken token) { // 需要重新请求权限 } }).check();
来源:https://github.com/Karumi/Dexter