project-image

A simple customizable android library to request and manage runtime permission in Android

Installation

Add it in your root build.gradle at the end of repositories:

allprojects {
	repositories {
		...
		maven { url 'https://jitpack.io' }
	}
}

Add the dependency

dependencies {
	        implementation 'com.github.threshant:permission-runner:v1.0.0'
	}

Example

Code for the above demo

 PermissionRunner(this).apply {
            showDescriptionDialogue = true
            getPermissions(arrayListOf(
                Permission(Manifest.permission.CAMERA,true,"Need camera permission to access QR Scanner"),
                Permission(Manifest.permission.CALL_PHONE,false,"Need phone permission to access Friends"),
                Permission(Manifest.permission.ACCESS_COARSE_LOCATION,true,"Need location permission to access current PinCode"),
            )
            ) { grantedPermissions, deniedPermission ->
                Log.d("Granted", grantedPermissions.toString())
                Log.d("Denied", deniedPermission.toString())
            }
        }

How to use

  1. The permission class: This is used to define custom inputs for each individual permission, it requires three parameters
  • PermissionName:String
  • isMandatory:Boolean
  • description:String (optional)
  Permission(permissionName, isMandatory, description)
  1. showDescriptionDialogue: This option is used to show a buttom sheet of the list of permissions before requesting them
  showDescriptionDialogue = true
  1. getPermissions: This method is used to request the runtime permission, this requires two parameters
  • ArrayList of Permission
  • A callback function

  getPermissions(arrayListOf(
                Permission(Manifest.permission.CAMERA,true,"Need camera permission to access QR Scanner"),
                Permission(Manifest.permission.CALL_PHONE,false,"Need phone permission to access Friends"),
                Permission(Manifest.permission.ACCESS_COARSE_LOCATION,true,"Need location permission to access current PinCode"),
            )
            ) { grantedPermissions, deniedPermission ->
                Log.d("Granted", grantedPermissions.toString())
                Log.d("Denied", deniedPermission.toString())
            }
  1. Putting it all together:

 PermissionRunner(this).apply {
            showDescriptionDialogue = true
            getPermissions(arrayListOf(
                Permission(Manifest.permission.CAMERA,true,"Need camera permission to access QR Scanner"),
                Permission(Manifest.permission.CALL_PHONE,false,"Need phone permission to access Friends"),
                Permission(Manifest.permission.ACCESS_COARSE_LOCATION,true,"Need location permission to access current PinCode"),
            )
            ) { grantedPermissions, deniedPermission ->
                Log.d("Granted", grantedPermissions.toString())
                Log.d("Denied", deniedPermission.toString())
            }
        }

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

License

MIT

GitHub

View Github