Code Monkey home page Code Monkey logo

kpermissions's Introduction

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.2'
}

Maven

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

Contributing

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.