Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
P

PermissionsDispatcher

> 编程语言
Open source

A declarative API to handle Android runtime permissions.

11.2K stars0 likes2 views
WebsiteGitHub

About

A declarative API to handle Android runtime permissions.

PermissionsDispatcher

  • Fully Kotlin/Java support
  • Special permissions support
  • 100% reflection-free

PermissionsDispatcher provides a simple annotation-based API to handle runtime permissions.

This library lifts the burden that comes with writing a bunch of check statements whether a permission has been granted or not from you, in order to keep your code clean and safe.

Usage

  • Kotlin: You can pick either of ktx or kapt.
  • Java: apt

Here's a minimum example, in which you register a MainActivity which requires Manifest.permission.CAMERA.

0. Prepare AndroidManifest

Add the following line to AndroidManifest.xml:

<uses-permission android:name="android.permission.CAMERA" />

1. Attach annotations

PermissionsDispatcher introduces only a few annotations, keeping its general API concise:

NOTE: Annotated methods must not be private.

Annotation Required Description
@RuntimePermissions ✓ Register an Activity or Fragment to handle permissions
@NeedsPermission ✓ Annotate a method which performs the action that requires one or more permissions
@OnShowRationale Annotate a method which explains why the permissions are needed. It passes in a PermissionRequest object which can be used to continue or abort the current permission request upon user input. If you don't specify any argument for the method compiler will generate process${NeedsPermissionMethodName}ProcessRequest and cancel${NeedsPermissionMethodName}ProcessRequest. You can use those methods in place of PermissionRequest(ex: with DialogFragment)
@OnPermissionDenied Annotate a method which is invoked if the user doesn't grant the permissions
@OnNeverAskAgain Annotate a method which is invoked if the user chose to have the device "never ask again" about a permission
…

2. Delegate to generated functions

Now generated functions become much more concise and intuitive than Java version!

…

Check out the sample for more details.

Other features/plugins

  • Getting Special Permissions
  • maxSdkVersion
  • IntelliJ plugin
  • AndroidAnnotations plugin

Installation

NOTE:

  • If you're using jCenter we've moved on to MavenCentral, see migration guide.
  • 4.x only supports Jetpack. If you still use appcompat 3.x is the way to go.

To add PermissionsDispatcher to your project, include the following in your app module build.gradle file:

${latest.version} is

groovy
dependencies {
  implementation "com.github.permissions-dispatcher:permissionsdispatcher:${latest.version}"
  annotationProcessor "com.github.permissions-dispatcher:permissionsdispatcher-processor:${latest.version}"
}

With Kotlin:

groovy
apply plugin: 'kotlin-kapt'

dependencies {
  implementation "com.github.permissions-dispatcher:permissionsdispatcher:${latest.version}"
  kapt "com.github.permissions-dispatcher:permissionsdispatcher-processor:${latest.version}"
}

License

Copyright 2016 Shintaro Katafuchi, Marcel Schnelle, Yoshinori Isogai

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Issues· 31 open

View all issuesOpen on GitHub
  • #790

    The annotation processor dependency seems to be missing from JitPack, no way to use 3.x then

    Updated Mar 26, 2025
  • #781

    Android 13 storage permission in @NeedsPermission

    Updated Jan 23, 2025
  • #789

    Unable to import the processor libray

    Updated Sep 27, 2024
  • #785

    `This library is no longer maintained.`

    Updated Mar 30, 2024
  • #784

    Add support for ksp

    Updated Mar 18, 2024
  • #755

    We can't have multiple constructPermissionsRequest within the same fragment

    bugcontributionwelcomeUpdated Nov 13, 2023
  • #783

    fhun

    Updated Nov 10, 2023
  • #779

    kotlin 1.8 Modifiers [PRIVATE] are not allowed on Kotlin parameters. Allowed modifiers: [VARARG, NOINLINE, CROSSINLINE]

    Updated Nov 10, 2023
  • #775

    Kotlin 1.7 Support

    Updated Sep 12, 2023
  • #763

    Doesn’t support Android 12 data access auditing

    Updated Nov 5, 2022

> Tags

Javaandroidjavakotlinpermission

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 28, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言