赞
踩
com.guolindev.permissionx:permissionx:1.7.1
public static void requestPermisions(Fragment fragment, String[] permissions, RequestCallback callback) { PermissionX.init(fragment) .permissions(permissions) .explainReasonBeforeRequest() .onExplainRequestReason(new ExplainReasonCallback() { @Override public void onExplainReason(ExplainScope scope, List<String> deniedList) { scope.showRequestReasonDialog(deniedList, "需要您同意以下权限才能正常使用", "确定", "取消"); } }) .onForwardToSettings(new ForwardToSettingsCallback() { @Override public void onForwardToSettings(ForwardScope scope, List<String> deniedList) { scope.showForwardToSettingsDialog(deniedList, "去设置开启权限", "去设置", "取消"); } }) .request(callback); }
public interface RequestCallback {
/**
* Callback for the request result.
* @param allGranted
* Indicate if all permissions that are granted.
* @param grantedList
* All permissions that granted by user.
* @param deniedList
* All permissions that denied by user.
*/
void onResult(boolean allGranted, @NonNull List<String> grantedList, @NonNull List<String> deniedList);
}
public static String[] getPermissionArray() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
return new String[]{Manifest.permission.READ_MEDIA_IMAGES};
} else {
return new String[]{Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE};
}
}
PermissionUtil.requestPermisions(
this,
PermissionUtil.getPermissionArray()
) { allGranted, _, _ ->
if (allGranted) {
showAdDialogOrJumpToPaint(type)
} else {
ToastUtils.showShort(R.string.permission_tips)
}
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。