私は同じ問題に直面しましたが、以下は私が思いついた回避策です:
public boolean checkForPermission(final String[] permissions, final int permRequestCode, int msgResourceId) {
final List<String> permissionsNeeded = new ArrayList<>();
for (int i = 0; i < permissions.length; i++) {
final String perm = permissions[i];
if (ContextCompat.checkSelfPermission(getActivity(), permissions[i]) != PackageManager.PERMISSION_GRANTED) {
if (shouldShowRequestPermissionRationale(permissions[i])) {
final AlertDialog dialog = AlertDialog.newInstance( getResources().getString(R.string.permission_title), getResources().getString(msgResourceId) );
dialog.setPositiveButton("OK", new View.OnClickListener() {
@Override
public void onClick(View view) {
// add the request.
permissionsNeeded.add(perm);
dialog.dismiss();
}
});
dialog.show( getActivity().getSupportFragmentManager(), "HCFAlertDialog" );
} else {
// add the request.
permissionsNeeded.add(perm);
}
}
}
if (permissionsNeeded.size() > 0) {
// go ahead and request permissions
requestPermissions(permissionsNeeded.toArray(new String[permissionsNeeded.size()]), permRequestCode);
return false;
} else {
// no permission need to be asked so all good...we have them all.
return true;
}
}
そして、上記のメソッドを次のように呼び出します。
if ( checkForPermission( new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.CAMERA}, REQUEST_PERMISSION_EXTERNAL_STORAGE_RESULT, R.string.permission_image) ) {
// DO YOUR STUFF
}