+ * rationaleTitle and rationaleMessage can be invalid @StringRes. If the value is -1 then no + * permission rationale will be displayed and permission would be requested + *
* Sample usage: - * - * PermissionUtils.checkPermissionsAndPerformAction(activity, - * Manifest.permission.WRITE_EXTERNAL_STORAGE, - * () -> initiateCameraUpload(activity), - * R.string.storage_permission_title, - * R.string.write_storage_permission_rationale); - * + *
+ * PermissionUtils.checkPermissionsAndPerformAction(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE, + * () -> initiateCameraUpload(activity), R.string.storage_permission_title, + * R.string.write_storage_permission_rationale); + *
* If you don't want the permission rationale to be shown then use: + *
+ * PermissionUtils.checkPermissionsAndPerformAction(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE, + * () -> initiateCameraUpload(activity), - 1, -1); * - * PermissionUtils.checkPermissionsAndPerformAction(activity, - * Manifest.permission.WRITE_EXTERNAL_STORAGE, - * () -> initiateCameraUpload(activity), - * - 1, -1); - * - * - * - * @param activity activity requesting permissions - * @param permission the permission being requests + * @param activity activity requesting permissions + * @param permissions the permissions array being requests * @param onPermissionGranted the runnable to be executed when the permission is granted - * @param rationaleTitle rationale title to be displayed when permission was denied. It can be an invalid @StringRes - * @param rationaleMessage rationale message to be displayed when permission was denied. It can be an invalid @StringRes + * @param rationaleTitle rationale title to be displayed when permission was denied. It can + * be an invalid @StringRes + * @param rationaleMessage rationale message to be displayed when permission was denied. It + * can be an invalid @StringRes */ - public static void checkPermissionsAndPerformAction(Activity activity, String permission, + public static void checkPermissionsAndPerformAction(Activity activity, String[] permissions, Runnable onPermissionGranted, @StringRes int rationaleTitle, @StringRes int rationaleMessage) { - checkPermissionsAndPerformAction(activity, permission, onPermissionGranted, null, + checkPermissionsAndPerformAction(activity, permissions, onPermissionGranted, null, rationaleTitle, rationaleMessage); } /** - * Checks for a particular permission and runs the corresponding runnables to perform an action when the permission is granted/denied - * Also, it shows a rationale if needed - * + * Checks for a particular permission and runs the corresponding runnables to perform an action + * when the permission is granted/denied Also, it shows a rationale if needed + *
* Sample usage: + *
+ * PermissionUtils.checkPermissionsAndPerformAction(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE,
+ * () -> initiateCameraUpload(activity), () -> showMessage(), R.string.storage_permission_title,
+ * R.string.write_storage_permission_rationale);
*
- * PermissionUtils.checkPermissionsAndPerformAction(activity,
- * Manifest.permission.WRITE_EXTERNAL_STORAGE,
- * () -> initiateCameraUpload(activity),
- * () -> showMessage(),
- * R.string.storage_permission_title,
- * R.string.write_storage_permission_rationale);
- *
- *
- * @param activity activity requesting permissions
- * @param permission the permission being requests
+ * @param activity activity requesting permissions
+ * @param permissions the permissions array being requested
* @param onPermissionGranted the runnable to be executed when the permission is granted
- * @param onPermissionDenied the runnable to be executed when the permission is denied(but not permanently)
- * @param rationaleTitle rationale title to be displayed when permission was denied
- * @param rationaleMessage rationale message to be displayed when permission was denied
+ * @param onPermissionDenied the runnable to be executed when the permission is denied(but not
+ * permanently)
+ * @param rationaleTitle rationale title to be displayed when permission was denied
+ * @param rationaleMessage rationale message to be displayed when permission was denied
*/
- public static void checkPermissionsAndPerformAction(Activity activity, String permission,
+ public static void checkPermissionsAndPerformAction(Activity activity, String[] permissions,
Runnable onPermissionGranted, Runnable onPermissionDenied, @StringRes int rationaleTitle,
@StringRes int rationaleMessage) {
Dexter.withActivity(activity)
- .withPermission(permission)
- .withListener(new BasePermissionListener() {
- @Override public void onPermissionGranted(PermissionGrantedResponse response) {
- onPermissionGranted.run();
- }
-
- @Override public void onPermissionDenied(PermissionDeniedResponse response) {
- if (response.isPermanentlyDenied()) {
+ .withPermissions(permissions)
+ .withListener(new MultiplePermissionsListener() {
+ @Override
+ public void onPermissionsChecked(MultiplePermissionsReport report) {
+ if (report.areAllPermissionsGranted()) {
+ onPermissionGranted.run();
+ }
+ if (report.isAnyPermissionPermanentlyDenied()) {
+ // permission is denied permanently, we will show user a dialog message.
DialogUtil.showAlertDialog(activity, activity.getString(rationaleTitle),
activity.getString(rationaleMessage),
activity.getString(R.string.navigation_item_settings), null,
@@ -125,7 +147,7 @@ public static void checkPermissionsAndPerformAction(Activity activity, String pe
}
@Override
- public void onPermissionRationaleShouldBeShown(PermissionRequest permission,
+ public void onPermissionRationaleShouldBeShown(List