https://github.com/fondesa/kpermissions
A Kotlin library which helps to request runtime permissions in Android.
https://github.com/fondesa/kpermissions
android android-library android-permissions androidx coroutines flow kotlin livedata permissions runtime-permissions rxjava rxjava2 rxjava3
Last synced: about 2 months ago
JSON representation
A Kotlin library which helps to request runtime permissions in Android.
- Host: GitHub
- URL: https://github.com/fondesa/kpermissions
- Owner: fondesa
- License: apache-2.0
- Created: 2018-01-05T18:07:15.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2025-12-11T05:49:16.000Z (3 months ago)
- Last Synced: 2025-12-12T00:42:29.120Z (3 months ago)
- Topics: android, android-library, android-permissions, androidx, coroutines, flow, kotlin, livedata, permissions, runtime-permissions, rxjava, rxjava2, rxjava3
- Language: Kotlin
- Homepage:
- Size: 1.03 MB
- Stars: 526
- Watchers: 4
- Forks: 32
- Open Issues: 13
-
Metadata Files:
- Readme: README.md
- Contributing: .github/CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Code of conduct: .github/CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
KPermissions
===============
[](https://github.com/fondesa/kpermissions/actions)
[](https://www.appbrain.com/stats/libraries/details/kpermissions/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](https://github.com/fondesa/kpermissions/wiki). It contains some useful notes and advanced features not explained in the ```README```.
For further samples, check the [sample](https://github.com/fondesa/kpermissions/tree/master/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()```:
```kotlin
// 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:
```kotlin
launch {
val result = permissionsBuilder(Manifest.permission.CAMERA).build().sendSuspend()
// Handle the result.
}
```
It also supports the Kotlin coroutines `Flow` API:
```kotlin
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:
```kotlin
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`:
```kotlin
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](https://github.com/fondesa/kpermissions/releases) or grab it from ```mavenCentral()```.
### Gradle ###
[](https://maven-badges.herokuapp.com/maven-central/com.github.fondesa/kpermissions)
```gradle
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](https://github.com/fondesa/kpermissions/blob/master/.github/CONTRIBUTING.md).