如果您想一次请求多个权限,可以使用以下方法link
compile 'com.kishan.askpermission:askpermission:1.0.3'
如果您在支持库中遇到冲突,请执行以下操作:
compile('com.kishan.askpermission:askpermission:1.0.3', {
exclude group: 'com.android.support'
})
现在请求权限
new AskPermission.Builder(this)
.setPermissions(Manifest.permission.READ_CONTACTS, Manifest.permission.WRITE_EXTERNAL_STORAGE)
.setCallback()
.setErrorCallback()
.request();
授权回调
public void onPermissionsGranted(int requestCode) {
权限被拒绝的回调
public void onPermissionsDenied(int requestCode) {
// your code}
错误回调函数
public void onShowRationalDialog(PermissionInterface permissionInterface, int requestCode) {
permissionInterface.onDialogShown();
}
public void onShowSettings(PermissionInterface permissionInterface, int requestCode) {
permissionInterface.onSettingsShown();
}