问题:
Can reqeust only one set of permissions at a time
使用场景:
使用PermissionsDispatcher进行动态权限申请,因业务需求,同时初始化了
MainActivityPermissionsDispatcher.doSomeThingOneWithPermissionCheck(this);//申请了读写内存权限
MainActivityPermissionsDispatcher.doSomeThingTwoWithPermissionCheck(this);//申请了相机等权限
问题原因:
找到Activity中相关代码,只能申请完一组等用户同意或者拒绝才能申请下一组;
public final void requestPermissions(@NonNull String[] permissions, int requestCode) {
if (requestCode < 0) {
throw new IllegalArgumentException("requestCode should be >= 0");
}
if (mHasCurrentPermissionsRequest) {
Log.w(TAG, "Can request only one set of permissions at a time");
// Dispatch the callback with empty arrays which means a cancellation.
onRequestPermissionsResult(requestCode, new String[0], new int[0]);
return;
}
Intent intent = getPackageManager().buildRequestPermissionsIntent(permissions);
startActivityForResult(REQUEST_PERMISSIONS_WHO_PREFIX, intent, requestCode, null);
mHasCurrentPermissionsRequest = true;
}
private void restoreHasCurrentPermissionRequest(Bundle bundle) {
if (bundle != null) {
mHasCurrentPermissionsRequest = bundle.getBoolean(
HAS_CURENT_PERMISSIONS_REQUEST_KEY, false);
}
}
解决办法:
合并申请或者嵌套申请