PermissionRequest

interface PermissionRequest

Used to check the status of a permission.

The result of the check is notified on the listeners attached to the PermissionRequest. To avoid memory leaks, it's recommended to remove the attached listeners when the instance that holds this PermissionRequest is destroyed or to build the PermissionRequest in a method always executed during the instance's lifecycle.

E.g. considering an Activity that wants to check the status of a permission when an action is done by the user, it's recommended to build the request at Activity.onCreate and send it when the action is done instead of build and send it at the same moment. This could avoid a potential memory leak when the Activity is rotated.

Types

Listener
Link copied to clipboard
fun interface Listener

Listener notified when a permissions request ends.

Functions

addListener
Link copied to clipboard
abstract fun addListener(listener: PermissionRequest.Listener)

Adds a Listener which will be notified when the permissions request sent with send ends.

checkStatus
Link copied to clipboard
abstract fun checkStatus(): List<PermissionStatus>

Checks the status of permissions of this request without sending it. Below API 23, this method and send should have the same behavior since the permissions status can be checked without sending a runtime request. Below API 23, the possible status are:

removeAllListeners
Link copied to clipboard
abstract fun removeAllListeners()

Removes all the listeners added to this request.

removeListener
Link copied to clipboard
abstract fun removeListener(listener: PermissionRequest.Listener)

Removes a Listener added with addListener which should not be notified anymore.

send
Link copied to clipboard
abstract fun send()

Sends the PermissionRequest and performs the checks on its status. The result will be returned to the attached listeners.

Inheritors

BasePermissionRequest
Link copied to clipboard

Extensions

liveData
Link copied to clipboard
fun PermissionRequest.liveData(): LiveData<List<PermissionStatus>>

Observes the PermissionRequest's status. The returned LiveData emits the list of PermissionStatus when the result of PermissionRequest.send is received. The documentation of the possible values of PermissionStatus can be found at PermissionRequest.Listener.onPermissionsResult.

send
Link copied to clipboard
inline fun PermissionRequest.send(crossinline callback: (List<PermissionStatus>) -> Unit)

Sends the PermissionRequest and performs the checks on its status. The result will be returned in the given callback.