Permissionmanager is a small wrapper for handling permission requests.

Overview

Permissionmanager

AndroidStudio 3.1.4 minSDK 16 targetSDK 27

Permissionmanager is a small wrapper for handling permission requests.

Installation

Add jitpack to your repositories in Project build.gradle :

allprojects {
    repositories {
        ...
        maven { url "https://jitpack.io" }
    }
    ...
}

Add dependency to your app build.gradle :

implementation 'com.github.grumpyshoe:android-module-permissionmanager:1.2.0'

Usage

Get instance of Permissionmanager :

val permissionManager: PermissionManager = PermissionManagerImpl

To handle the users decision you have to delegate the response of onRequestPermissionsResult in your activity to the library like this:

override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) {
    permissionManager.onRequestPermissionsResult(requestCode, permissions, grantResults)
            ?: super.onRequestPermissionsResult(requestCode, permissions, grantResults)

}

Check permission

Check permission grant state by calling checkPermissions.

permissionManager.checkPermissions(
    activity = this,
    permissions = <array-of-permissions>,
    onPermissionResult = { permissionResult ->
        // handle permission result
    })

It's best practise to inform the user about why permission are needed before requesting them so you can define a PermissionRequestExplanation at permissionRequestPreExecuteExplanation with information that explains this request. When adding this parameter a AlertDialog will be shown before requesting permissions.

If the user denies a permission first but another action requests this again because it's needed to do the job, then that's where shouldShowRequestPermissionRationale takes place.

You can also define which titel should be shown by adding a PermissionRequestExplanation to the attribute permissionRequestRetryExplanation.

Last but not least you can define which requestCode should be used on permission requests. The default is 8102.

Example implementation with all available attributes:

permissionManager.checkPermissions(
    activity = this,
    permissions = arrayOf(Manifest.permission.ACCESS_FINE_LOCATION),
    onPermissionResult = { permissionResult ->
        // handle permission result
    },
    permissionRequestPreExecuteExplanation = PermissionRequestExplanation(
            title = "Pre Custom Permission Hint",
            message = "The App will request the permissions ..."),
    permissionRequestRetryExplanation = PermissionRequestExplanation(
            title = "Retry Custom Permission Hint",
            message = "You denied the permissions previously but this permissions are needed because ..."),
    requestCode = 123)

If you want to customize the button labels that are shown on shouldShowRequestPermissionRationale = true just add a translation for the following string to your strings.xml:

  • permission_request_explanation_btn_grant_text ("grant" by default)
  • permission_request_explanation_btn_deny_text ("deny" by default)

Troubleshooting

  • Please make sure you have added corresponding permissions to yout Manifest, otherwise you get this response in Logcat without anythins noticable on UI-Screen:

PermissionManager: Permissions denied: [...]

Need Help or something missing?

Please submit an issue on GitHub.

License

This project is licensed under the terms of the MIT license. See the LICENSE file.

Build Environment

Android Studio 3.1.4
Build #AI-173.4907809, built on July 23, 2018
JRE: 1.8.0_152-release-1024-b01 x86_64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Mac OS X 10.13.4
You might also like...
Netflix inspired OTT Home Screen, Contains implementation in Reactjs, Kotlin React Wrapper, Jetpack Compose Web

Netflix-Clone-React Practising React by building Netflix Clone Requirements TMDB api key : Add TMDB API key to AppApi.kt Learning Resourcce Build Netf

Dependency Injection library for Compose Multiplatform, Koin wrapper.

🥥 Cokoin Injection library for Compose (Multiplatform and Jetpack), Koin wrapper. It uses @Composable functions to configure KoinContext and Scopes.

This library is a set of simple wrapper classes that are aimed to help you easily access android device information.
This library is a set of simple wrapper classes that are aimed to help you easily access android device information.

SysInfo Simple, single class wrapper to get device information from an android device. This library provides an easy way to access all the device info

Wrapper of FusedLocationProviderClient for Android to support modern usage like LiveData and Flow

FancyLocationProvider Wrapper of FusedLocationProviderClient for Android to support modern usage like LiveData or Flow. Install Add Jitpack repository

A Kotlin coroutines wrapper for IndexedDB.

Kotlin IndexedDB A wrapper around IndexedDB which allows for access from Kotlin/JS code using suspend blocks and linear, non-callback based control fl

Yaspeller-kt - Asynchronous Yandex.Speller API wrapper for Kotlin/JVM.

yaspeller-kt Asynchronous Yandex.Speller API wrapper for Kotlin/JVM. Installation repositories { maven { url 'https://jitpack.io' }

⏰ A powerful and simple-to-use guilded wrapper made in Kotlin.
⏰ A powerful and simple-to-use guilded wrapper made in Kotlin.

⏰ guilded-kt [WIP] A powerful yet simple-to-use guilded wrapper made entirely in Kotlin with supporting multiplatform. Take a look at an example of th

SavedStateFlow - A Kotlin StateFlow wrapper around SavedStateHandle
SavedStateFlow - A Kotlin StateFlow wrapper around SavedStateHandle

SavedStateFlow SavedStateFlow is a Kotlin StateFlow wrapper around SavedStateHan

🎲 A powerful and simple-to-use guilded wrapper made in Kotlin.

🎲 deck [WIP] Deck is a powerful yet simple-to-use guilded wrapper made entirely in Kotlin with support to multiplatform. Implementating In case you'r

Comments
  • Multiple concurrent permissions

    Multiple concurrent permissions

    Asking for multiple permissions separately and concurrently leads to some onPermissionResult callbacks not being called. Changing the requestCode and onPermissionResult member variables in PermissionManagerImpl to a HashMap would fix this.

    opened by dan-drewes 0
Owner
Thomas Cirksena
Passionate android developer since Android 1.5 ..... and still happy with it ;)
Thomas Cirksena
Joker-App - List application tha make requests to a Chuck Norris Api

Joker App About • Technologies • Features • Author • License ?? About the Projec

Miguel S. da Silva 1 Feb 4, 2022
A lightweight and simple Kotlin library for deep link handling on Android 🔗.

A lightweight and simple Kotlin library for deep link handling on Android ??.

Jeziel Lago 101 Aug 14, 2022
A simple solution to handling persistent data storage in your Minecraft server.

Modern Data Stores A simple solution to handling persistent data storage in your Minecraft server. This plugin will be used throughout the Modern Plug

Modern Plugins 2 Nov 7, 2022
A simple solution to handling persistent data storage in your Minecraft server.

Modern Data Stores A simple solution to handling persistent data storage in your Minecraft server. This plugin will be used throughout the Modern Plug

Modern Plugins 2 Nov 7, 2022
:closed_umbrella: An easy way to implement modern permission instructions popup.

Needs An easy way to implement modern permission instructions popup. Needs can be fully customized and showing with animations. Download Gradle Add be

Jaewoong Eum 609 Dec 8, 2022
A Kotlin DSL wrapper around the mikepenz/MaterialDrawer library.

MaterialDrawerKt Create navigation drawers in your Activities and Fragments without having to write any XML, in pure Kotlin code, with access to all t

Márton Braun 517 Nov 19, 2022
🔓 Kotlin version of the popular google/easypermissions wrapper library to simplify basic system permissions logic on Android M or higher.

EasyPermissions-ktx Kotlin version of the popular googlesample/easypermissions wrapper library to simplify basic system permissions logic on Android M

Madalin Valceleanu 326 Dec 23, 2022
A simple Kotlin wrapper around Anvil.

AnvilKotlin A simple Kotlin wrapper around Anvil. The only purpose of this library is to provide type safety to Anvil through Kotlin. Nothing more, no

Andre Artus 15 Oct 3, 2022
Android AsyncTask wrapper library, written in Kotlin

KillerTask This is a Kotlin Android library to create async background tasks. Inspired by TinyTask, but more beautiful and easy to use for Kotlin Andr

Inaka 26 Oct 3, 2022
A lightweight Kotlin friendly wrapper around Couchbase lite for Android.

CouchBaseKtx ?? Work In-Progress ?? A lightweight Kotlin friendly wrapper around Couchbase-lite for Android Read up a little bit of documentation abou

Jaya Surya Thotapalli 5 Feb 15, 2022