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.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • 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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • CameraPermissionHelper

        CameraPermissionHelper(Activity activity)
    • Method Detail

      • 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 permissions
        grantResults - 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.