diff --git a/README.md b/README.md index 7d194e1..74fa6d6 100644 --- a/README.md +++ b/README.md @@ -112,6 +112,12 @@ permissionFragmentHelper .request(isSingle ? SINGLE_PERMISSION : MULTIPLE_PERMISSIONS); ``` +To request a permission without ask for explanation message even if the user press decline: +```java +permissionHelper + .setSkipExplanation(true)// true if you don't want to show expalanation message + .request(CAMERA_PERMISSION); + and finally in your `Activity/Fragment` ```java diff --git a/permission/src/main/java/com/fastaccess/permission/base/PermissionFragmentHelper.java b/permission/src/main/java/com/fastaccess/permission/base/PermissionFragmentHelper.java index 7a27fe3..66ce00a 100644 --- a/permission/src/main/java/com/fastaccess/permission/base/PermissionFragmentHelper.java +++ b/permission/src/main/java/com/fastaccess/permission/base/PermissionFragmentHelper.java @@ -27,6 +27,7 @@ public class PermissionFragmentHelper implements OnActivityPermissionCallback { @NonNull private final OnPermissionCallback permissionCallback; @NonNull private final Fragment context; private boolean forceAccepting; + private boolean skipExplanation; private PermissionFragmentHelper(@NonNull Fragment context) { this.context = context; @@ -146,7 +147,7 @@ private void handleSingle(@NonNull String permissionName) { // run time permission that does not exists in AndroidManifest. if (!permissionName.equalsIgnoreCase(Manifest.permission.SYSTEM_ALERT_WINDOW)) { if (isPermissionDeclined(permissionName)) { - if (isExplanationNeeded(permissionName)) { + if (isExplanationNeeded(permissionName) && !skipExplanation) { permissionCallback.onPermissionNeedExplanation(permissionName); } else { context.requestPermissions(new String[]{permissionName}, REQUEST_PERMISSIONS); @@ -420,4 +421,8 @@ public static void removeGrantedPermissions(@NonNull Fragment context, @NonNull models.removeAll(granted); } } + + public void setSkipExplanation(boolean skipExplanation) { + this.skipExplanation = skipExplanation; + } } diff --git a/permission/src/main/java/com/fastaccess/permission/base/PermissionHelper.java b/permission/src/main/java/com/fastaccess/permission/base/PermissionHelper.java index 84ed1c3..ecaa444 100644 --- a/permission/src/main/java/com/fastaccess/permission/base/PermissionHelper.java +++ b/permission/src/main/java/com/fastaccess/permission/base/PermissionHelper.java @@ -27,6 +27,7 @@ public class PermissionHelper implements OnActivityPermissionCallback { @NonNull private final OnPermissionCallback permissionCallback; @NonNull private final Activity context; private boolean forceAccepting; + private boolean skipExplanation; private PermissionHelper(@NonNull Activity context) { this.context = context; @@ -145,7 +146,7 @@ private void handleSingle(@NonNull String permissionName) { // run time permission that does not exists in AndroidManifest. if (!permissionName.equalsIgnoreCase(Manifest.permission.SYSTEM_ALERT_WINDOW)) { if (isPermissionDeclined(permissionName)) { - if (isExplanationNeeded(permissionName)) { + if (isExplanationNeeded(permissionName) && !skipExplanation) { permissionCallback.onPermissionNeedExplanation(permissionName); } else { ActivityCompat.requestPermissions(context, new String[]{permissionName}, REQUEST_PERMISSIONS); @@ -417,4 +418,8 @@ public static void removeGrantedPermissions(@NonNull Context context, @NonNull L models.removeAll(granted); } } + + public void setSkipExplanation(boolean skipExplanation) { + this.skipExplanation = skipExplanation; + } }