public final class PermissMeUtils extends Object
Modifier and Type | Method and Description |
---|---|
static View.OnClickListener |
createSettingsClickListener(Activity activity)
The onClickListener that takes you to the app's system settings screen
|
static String[] |
getDeniedPermissions(Context context,
String... permissions)
Given a list of permissions, get all the permissions that are denied by the user.
|
static boolean |
hasCameraPermission(Context context)
Common camera permission check.
|
static boolean |
hasReadWriteStoragePermission(Context context)
Common READ/WRITE Storage Permission Check.
|
static boolean |
isAutoDeniedPermission(AppCompatActivity activity,
String permission)
Checks if the permission is auto-denied, i.e.
|
static boolean |
needToRequestPermission(Context context,
String... permissions)
Check if we already have access granted for this permission
|
static void |
runOnUiThread(Runnable runnable)
Helper method to post a
Runnable to the main thread |
static void |
showPermissionDeniedSnackbar(Activity activity,
String customErrorMessage)
Shows the snackbar which is used in the scenario where user auto-denied permissions before.
|
static void |
showSnackBar(View view,
String msg,
int backgroundColor,
String ctaString,
View.OnClickListener ctaClickListener)
Displays a SnackBar message.
|
static boolean |
verifyPermissions(int[] grantResults)
Check that all given permissions have been granted by verifying that each entry in the
given array is of the value
PermissionChecker.PERMISSION_GRANTED . |
public static boolean verifyPermissions(@NonNull int[] grantResults)
PermissionChecker.PERMISSION_GRANTED
.grantResults
- the results to check whether they are grantedActivity.onRequestPermissionsResult(int, String[], int[])
@NonNull public static String[] getDeniedPermissions(@NonNull Context context, @Nullable String... permissions)
context
- Caller contextpermissions
- List of permissions to checkpublic static boolean needToRequestPermission(@NonNull Context context, @NonNull String... permissions)
context
- The caller activitypermissions
- The permissions that needs to be grantedpublic static void showPermissionDeniedSnackbar(@NonNull Activity activity, @Nullable String customErrorMessage)
activity
- the activity with the view to attach the snackbar tocustomErrorMessage
- an optional custom error message. this method uses the default one if the custom one
is nullpublic static boolean hasCameraPermission(Context context)
context
- caller contextpublic static boolean hasReadWriteStoragePermission(Context context)
context
- caller contextpublic static boolean isAutoDeniedPermission(AppCompatActivity activity, @NonNull String permission)
activity
- the activitypermission
- the permission being queriedpublic static View.OnClickListener createSettingsClickListener(Activity activity)
activity
- the caller activity used to start the settings intentView.OnClickListener
public static void showSnackBar(View view, String msg, int backgroundColor, String ctaString, View.OnClickListener ctaClickListener)
view
- the view to find a parent from.msg
- the message to display.backgroundColor
- the background color.ctaString
- the call to action stringctaClickListener
- the call to action click listener.