Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/albert-gao/permissionk
Opinionated Android permission handling done right with Kotlin.
https://github.com/albert-gao/permissionk
android kotlin library permission-android permissions
Last synced: about 1 month ago
JSON representation
Opinionated Android permission handling done right with Kotlin.
- Host: GitHub
- URL: https://github.com/albert-gao/permissionk
- Owner: Albert-Gao
- Created: 2018-04-30T09:26:35.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-04-30T09:31:26.000Z (over 6 years ago)
- Last Synced: 2024-10-15T21:21:34.255Z (3 months ago)
- Topics: android, kotlin, library, permission-android, permissions
- Language: Kotlin
- Homepage:
- Size: 7.81 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# PermissionK
Opinionated permission handling done right with Kotlin.
Check more details in my [blog](http://www.albertgao.xyz/2018/04/23/android-permission-handling-done-right-with-kotlin/)
## Why use it
- The whole flow has been sorted out.
- Multiple permissions supported.
- Nice DSL for better code.
- Written in Kotlin## What is the handling flow
1. Show an explanation to the user why we need those permissions.
2. If the user press ok, then we will request for the permissions.
3. After getting the request result, we will handling 3 cases:
- When everything is fine
- When permissions not accepted
- When user checks the `Never Ask again` option, we will route the user to the application settings to enable the permission there.
> No `shouldShowRationale`? Yes, this is such a confusing method depends on its name. In our flow, user always gets the explanation first, which should be a design which you always follow. But underneath, we use it to check the `NeverAskAgain` option.## How to use it
1. Install (Not yet published)
```groovy
implementation 'xyz.albertgao:permissionk:1.0.0'
```2. Trigger the explanation step to invoking this function inside your activity, properly a onClickHandler
```groovy
startToRequestPermission {
permissions = listOf(SEND_SMS, READ_PHONE_STATE)
requestCode = [email protected]ifSuccess {
// Your handling logic
}elseShowDialogToRequestPermission{
message = "Hi, We need these permissions because we want to make the user experiences better, please grant them!"
}
}
```3. Inside the onRequestPermissionResult method, by using the following DSL:
```kotlin
override fun onRequestPermissionsResult(
theRequestCode: Int,
thePermissions: Array,
theGrantResults: IntArray
) {
onRequestPermissionResultHandler {
actualRequestCode = theRequestCode
expectRequestCode = [email protected]
permissions = thePermissions
grantResultsParam = theGrantResultsonSuccess {
// Do what you want
}onFailure {
// You don't get the permission, do something
}onNeverAskAgain {
message = "We noticed you have disabled some permissions . We will take you to the Application settings, you can re-enable the permission there."
}
}
}
```