GithubHelp home page GithubHelp logo

cybernetics / kpermissions Goto Github PK

View Code? Open in Web Editor NEW

This project forked from fondesa/kpermissions

0.0 1.0 0.0 778 KB

A Kotlin library which helps to request runtime permissions in Android.

License: Apache License 2.0

Kotlin 99.40% Shell 0.60%

kpermissions's Introduction

KPermissions

Build Status KPermissions

An Android library totally written in Kotlin that helps to request runtime permissions. This library is compatible also below Android M (API 23) 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. For further samples, check the sample provided by this library. It shows how to integrate this library and request the permissions from an Activity or a Fragment.

Basic usage

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

// Build the request with the permissions you would like to request and send it.
permissionsBuilder(Manifest.permission.CAMERA, Manifest.permission.SEND_SMS).build().send { result ->
    // Handle the result, for example check if all the requested permissions are granted.
    if (result.allGranted()) {
       // All the permissions are granted.
    }
}

Coroutines

The artifact kpermissions-coroutines adds the integration with the Kotlin coroutines:

launch {
    val result = permissionsBuilder(Manifest.permission.CAMERA).build().sendSuspend()
    // Handle the result.
}

It also supports the Kotlin coroutines Flow API:

val request = permissionsBuilder(Manifest.permission.CAMERA).build()
launch {
    request.flow().collect { result ->
        // Handle the result. 
    }
}
request.send()

RxJava

The artifacts kpermissions-rx2 and kpermissions-rx3 adds the integration with RxJava 2 and RxJava 3 respectively:

val request = permissionsBuilder(Manifest.permission.CAMERA).build()
request.observe().subscribe { result ->
    // Handle the result.
}
request.send()

LiveData

In the core artifact, there's a useful extension on PermissionRequest to get a LiveData:

val request = permissionsBuilder(Manifest.permission.CAMERA).build()
request.liveData().observe(this) { result ->
    // Handle the result.
}
request.send()

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 mavenCentral().

Gradle

Maven Central

dependencies {
    // The core artifact.
    implementation 'com.github.fondesa:kpermissions:x.x.x'
    // If you want the extensions for RxJava 2.
    implementation 'com.github.fondesa:kpermissions-rx2:x.x.x'
    // If you want the extensions for RxJava 3.
    implementation 'com.github.fondesa:kpermissions-rx3:x.x.x'
    // If you want the extensions for the Kotlin coroutines.
    implementation 'com.github.fondesa:kpermissions-coroutines:x.x.x'
}

Contributing

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

kpermissions's People

Contributors

fondesa avatar

Watchers

 avatar

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.