Class CameraPermissionHelper
-
- All Implemented Interfaces:
public class CameraPermissionHelper
Helper class to handle Android 6 (API >23) Runtime Camera Permissions. For Android API levels <23, this helper class will return the permission as granted. This is because the permissions are given at installation time on this API levels.
-
-
Field Summary
Fields Modifier and Type Field Description public final static int
REQUEST_CODE_CAMERA_PERMISSIONS
-
Constructor Summary
Constructors Constructor Description CameraPermissionHelper(Activity activity)
-
Method Summary
Modifier and Type Method Description void
requestPermissions()
Sends a permission request to the user. boolean
hasPermissions()
Checks if the Camera Permission was already granted by the user boolean
onRequestPermissionsResult(int requestCode, Array<String> permissions, Array<int> grantResults)
Takes the result from onRequestPermissionsResult and evaluates if the Camera Permission was given by the user. void
showPermissionMessage(@Nullable() String message)
Displays an AlertDialog to the user, informing him about the necessity of granting the Camera Permission. -
-
Constructor Detail
-
CameraPermissionHelper
CameraPermissionHelper(Activity activity)
-
-
Method Detail
-
requestPermissions
void requestPermissions()
Sends a permission request to the user. The result will be given in onRequestPermissionsResult. The result should be forwarded to onRequestPermissionsResult, which will evaluate the parameters and return the result.
-
hasPermissions
boolean hasPermissions()
Checks if the Camera Permission was already granted by the user
- Returns:
a boolean indicating if the permission was already granted.
-
onRequestPermissionsResult
boolean onRequestPermissionsResult(int requestCode, Array<String> permissions, Array<int> grantResults)
Takes the result from onRequestPermissionsResult and evaluates if the Camera Permission was given by the user. If the provided permissions are not the ones requested with this helper, this method will also return false.
- Parameters:
requestCode
- the code of the request (should be REQUEST_CODE_CAMERA_PERMISSIONS)permissions
- the requested permissionsgrantResults
- the results of the request- Returns:
a boolean indicating if the Camera Permissions were granted.
-
showPermissionMessage
@UiThread() void showPermissionMessage(@Nullable() String message)
Displays an AlertDialog to the user, informing him about the necessity of granting the Camera Permission. If no message is given, a default message is displayed.
- Parameters:
message
- the message to display to the user.
-
-
-
-