public class PermissionsManager
extends java.lang.Object
| Modifier and Type | Method and Description |
|---|---|
static PermissionsManager |
getInstance() |
boolean |
hasAllPermissions(android.content.Context context,
java.lang.String[] permissions)
This static method can be used to check whether or not you have several specific permissions.
|
boolean |
hasPermission(android.content.Context context,
java.lang.String permission)
This static method can be used to check whether or not you have a specific permission.
|
void |
notifyPermissionsChange(java.lang.String[] permissions,
int[] results)
This method notifies the PermissionsManager that the permissions have change.
|
void |
requestAllManifestPermissionsIfNecessary(android.app.Activity activity,
PermissionsResultAction action)
This method will request all the permissions declared in your application manifest
for the specified
PermissionsResultAction. |
void |
requestPermissionsIfNecessaryForResult(android.app.Activity activity,
java.lang.String[] permissions,
PermissionsResultAction action)
This method should be used to execute a
PermissionsResultAction for the array
of permissions passed to this method. |
void |
requestPermissionsIfNecessaryForResult(Fragment fragment,
java.lang.String[] permissions,
PermissionsResultAction action)
This method should be used to execute a
PermissionsResultAction for the array
of permissions passed to this method. |
public static PermissionsManager getInstance()
public boolean hasPermission(android.content.Context context,
java.lang.String permission)
ActivityCompat#checkSelfPermission(Context, String)
and will simply return a boolean whether or not you have the permission. If you pass
in a null Context object, it will return false as otherwise it cannot check the permission.
However, the Activity parameter is nullable so that you can pass in a reference that you
are not always sure will be valid or not (e.g. getActivity() from Fragment).context - the Context necessary to check the permissionpermission - the permission to checkpublic boolean hasAllPermissions(android.content.Context context,
java.lang.String[] permissions)
ActivityCompat#checkSelfPermission(Context, String)
for each permission and will simply return a boolean whether or not you have all the permissions.
If you pass in a null Context object, it will return false as otherwise it cannot check the
permission. However, the Activity parameter is nullable so that you can pass in a reference
that you are not always sure will be valid or not (e.g. getActivity() from Fragment).context - the Context necessary to check the permissionpermissions - the permissions to checkpublic void requestAllManifestPermissionsIfNecessary(android.app.Activity activity,
PermissionsResultAction action)
PermissionsResultAction. The purpose of this method is to enable
all permissions to be requested at one shot. The PermissionsResultAction is used to notify
you of the user allowing or denying each permission. The Activity and PermissionsResultAction
parameters are both annotated Nullable, but this method will not work if the Activity
is null. It is only annotated Nullable as a courtesy to prevent crashes in the case
that you call this from a Fragment where Fragment#getActivity() could yield
null. Additionally, you will not receive any notification of permissions being granted
if you provide a null PermissionsResultAction.activity - the Activity necessary to request and check permissions.action - the PermissionsResultAction used to notify you of permissions being accepted.public void requestPermissionsIfNecessaryForResult(android.app.Activity activity,
java.lang.String[] permissions,
PermissionsResultAction action)
PermissionsResultAction for the array
of permissions passed to this method. This method will request the permissions if
they need to be requested (i.e. we don't have permission yet) and will add the
PermissionsResultAction to the queue to be notified of permissions being granted or
denied. In the case of pre-Android Marshmallow, permissions will be granted immediately.
The Activity variable is nullable, but if it is null, the method will fail to execute.
This is only nullable as a courtesy for Fragments where getActivity() may yeild null
if the Fragment is not currently added to its parent Activity.activity - the activity necessary to request the permissions.permissions - the list of permissions to request for the PermissionsResultAction.action - the PermissionsResultAction to notify when the permissions are granted or denied.public void requestPermissionsIfNecessaryForResult(Fragment fragment,
java.lang.String[] permissions,
PermissionsResultAction action)
PermissionsResultAction for the array
of permissions passed to this method. This method will request the permissions if
they need to be requested (i.e. we don't have permission yet) and will add the
PermissionsResultAction to the queue to be notified of permissions being granted or
denied. In the case of pre-Android Marshmallow, permissions will be granted immediately.
The Fragment variable is used, but if Fragment#getActivity() returns null, this method
will fail to work as the activity reference is necessary to check for permissions.fragment - the fragment necessary to request the permissions.permissions - the list of permissions to request for the PermissionsResultAction.action - the PermissionsResultAction to notify when the permissions are granted or denied.public void notifyPermissionsChange(java.lang.String[] permissions,
int[] results)
Fragment#onRequestPermissionsResult(int, String[], int[]) method.
It will notify all the pending PermissionsResultAction objects currently
in the queue, and will remove the permissions request from the list of pending requests.permissions - the permissions that have changed.results - the values for each permission.