PermissionsDispatcher
A declarative API to handle Android runtime permissions.
Android library that cuts out the repetitive code required to ask users for permissions by letting you declare all the handling logic with simple annotations on your methods.
PermissionsDispatcher is a library for Android app developers that reduces the amount of repetitive code needed to ask users for permissions. Android apps need to request certain permissions at runtime before accessing things like the camera, microphone, or location. Without a helper library, handling all the possible outcomes (user grants, user denies, user checks "never ask again") requires a lot of manual checks scattered throughout the code.
This library uses annotations, which are small tags you add to your methods, to declare how each permission scenario should be handled. You mark a method with @NeedsPermission to say it requires a particular permission, add @OnPermissionDenied to specify what happens if the user refuses, and optionally add @OnShowRationale to provide an explanation before the system dialog appears. The library then generates the necessary boilerplate code automatically at build time.
Because the code is generated at compile time rather than looked up at runtime, the library does not use reflection, which keeps it fast and avoids potential compatibility issues on certain Android versions.
The library works with both Kotlin and Java. Kotlin users can also use a separate ktx extension that offers a more idiomatic API. Installation involves adding two lines to the app build configuration file: one for the library itself and one for the annotation processor that generates the boilerplate.
It requires the Jetpack version of Android support libraries (version 4.x and later). The code is released under the Apache License 2.0.
Where it fits
- Replace messy permission-handling if-else blocks in your Android app with clean method annotations.
- Handle camera, microphone, or location permissions in a Kotlin app by adding three annotations instead of writing boilerplate callbacks.
- Show a rationale dialog before the system permission prompt appears, using the @OnShowRationale annotation.