Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add shouldShowRequestPermissionRationale method #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions library/src/main/java/com/anthonycr/grant/PermissionsManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,18 @@ public static boolean hasAllPermissions(@Nullable Context context, @NonNull Stri
return hasAllPermissions;
}

/**
* This static method can be used to check whether or not you should show request permission rational.
* If you pass in a null Activity object, it will return true
* @param activity the Activity necessary to check the permission
* @param permission the permission to check
* @return false if user selected never ask permission again, true otherwise
*/
@SuppressWarnings("unused")
public static boolean shouldShowRequestPermissionRationale(@Nullable Activity activity, @NonNull String permission) {
return activity == null || ActivityCompat.shouldShowRequestPermissionRationale(activity, permission);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be activity != null && ActivityCompat... because if the activity is null (let's assume we are in a Fragment detached from its parent activity), then actually requesting the permission will fail as it also requires an activity, which means we don't care about showing the rationale because we won't be able to show the permissions request dialog.

}

/**
* This method will request all the permissions declared in your application manifest
* for the specified {@link PermissionsResultAction}. The purpose of this method is to enable
Expand Down