KPermissions
Fondesa
145
Visit GitHub RepoPermissions

KPermissions

Build Status

An Android library totally written in Kotlin that helps to request runtime permissions. This library is compatible also below Android M where runtime permissions doesn't exist, so you haven't to handle them separately.

Usage

To discover all the APIs of this library, check the wiki. It contains some useful notes and advanced features not explained in the README.

Basic usage

You can create a PermissionRequest either from an Activity or a Fragment using the extension method permissionsBuilder():

// Creates the request with the permissions you would like to request.
val request = permissionsBuilder(Manifest.permission.CAMERA, Manifest.permission.SEND_SMS).build()
// Send the request when you want.
request.send() 

To be notified about permissions' events, you can attach some listeners in one of the following ways (you can also combine them in the way you prefer most).

1. DSL

request.listeners {
    
    onAccepted { permissions ->
        // Notified when the permissions are accepted.
    }

    onDenied { permissions ->
        // Notified when the permissions are denied.
    }
    
    onPermanentlyDenied { permissions ->
        // Notified when the permissions are permanently denied.
    }
    
    onShouldShowRationale { permissions, nonce ->
        // Notified when the permissions should show a rationale.
        // The nonce can be used to request the permissions again.
    }
}

2. Builder's extensions

request.onAccepted { permissions ->
    // Notified when the permissions are accepted.
}.onDenied { permissions ->
    // Notified when the permissions are denied.
}.onPermanentlyDenied { permissions ->
    // Notified when the permissions are permanently denied.
}.onShouldShowRationale { permissions, nonce ->
    // Notified when the permissions should show a rationale.
    // The nonce can be used to request the permissions again.
}

3. Normal listeners

// It must implement [PermissionListener.AcceptedListener].
request.acceptedListener(this)
// It must implement [PermissionListener.DeniedListener].
request.deniedListener(this)
// It must implement [PermissionListener.PermanentlyDeniedListener].
request.permanentlyDeniedListener(this)
// It must implement [PermissionListener.RationaleListener].
request.rationaleListener(this)

Compatibility

Android SDK: KPermissions requires a minimum API level of 14 (the same of the latest support libraries).

AndroidX: this library requires AndroidX. To use it in a project without AndroidX, refer to the version 1.x

Integration

You can download a jar from GitHub's releases page or grab it from jcenter() or mavenCentral().

Gradle

dependencies {
    compile 'com.github.fondesa:kpermissions:2.0.1'
}

Maven

<dependency>
  <groupId>com.github.fondesa</groupId>
  <artifactId>kpermissions</artifactId>
  <version>2.0.1</version>
  <type>pom</type>
</dependency>

Contributing

Feel free to contribute to this project following the contributing guidelines.

Become a better Android Developer
Millions of developers are learning at MindOrks

Online Training Program

Featured Blogs

Our Team

MindOrks is Certainly one of the best online blog to stay on top of all the Android development news, coding and design patterns. Finally a blog I can count on to keep myself updated with latest and greatest things happening in Android world.

Vipul Shah
Android Developer
Microsoft

Become Pro in Android by watching videos

OUR LEARNERS WORK AT