Android-easy-permissions-kt - EasyPermissionsKt - A lightweight Android library that abstracts all runtime permission boilerplate code to simplify the system permissions managemen

Overview

Easy Permissions Kt

Language License JitPack ktlint

EasyPermissionsKt is a lightweight Android library that abstracts all runtime permission boilerplate code to simplify the system permissions management. The lib is lifecycle aware and uses the new recommended way to get results from activities (https://developer.android.com/training/basics/intents/result?hl=pt-br)

How to add

Step 1. Add the JitPack repository to your build file

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

Step 2. Add the dependency

Gradle:

dependencies {
    implementation 'com.github.wellingtoncabral:android-easy-permissions-kt:<LATEST-VERSION>'
}

Kotlin:

dependencies {
    implementation ("com.github.wellingtoncabral:android-easy-permissions-kt:$LATEST_VERSION")
}

How to use

Register the EasyPermissionKt and implement the result callback. The result can be handled in 3 states as described below:

Using from Activities

class MyActivity : AppCompatActivity() {
    ...
    private val easyPermission = registerForPermissionsResult {
        whenPermissionGranted {
            // All permissions granted
            TODO()
        }
        whenPermissionShouldShowRationale { permissions ->
            // Permissions denied but not permanently.
            // The app should show a rationale to the user in
            // a UI element.
            // @see [https://developer.android.com/training/permissions/requesting#explain]
            TODO()
        }
        whenPermissionDeniedPermanently { permissions ->
            // Permission denied permanently
            TODO()
        }
    }   
}

Using from Fragments

// Using from Fragment
class MyFragment : Fragment() {
    
    private lateinit var easyPermission: EasyPermissionKt

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
    
        easyPermission = registerForPermissionsResult {
            whenPermissionGranted {
                TODO()
            }
            whenPermissionShouldShowRationale { permissions ->
                TODO()
            }
            whenPermissionDeniedPermanently { permissions ->
                TODO()
            }
        }
    }
}

To request permissions, just call the requestPermissions function passing one or more permissions as shown below:

// Requesting permission or permissions
easyPermission.requestPermissions(
    Manifest.permission.CAMERA,
    Manifest.permission.WRITE_EXTERNAL_STORAGE
)

It is also possible to create an explanatory UI for the user before asking for permission. The implementation below uses WithDialog which creates a native AlertDialog.

// Requesting permission with an explain why dialog
easyPermission
    .explainWhy( 
        WithDialog(
            title = "Permission Request",
            description = "To easily connect with family and friends, allow the app access to your contacts",
            positiveButtonText = "Continue",
            negativeButtonText = "Not now"
        )
    )
    .requestPermissions(Manifest.permission.READ_CONTACTS)

However, you can create any UI. Just create a class and implement the ExplainWhyUI interface. In the show() method use the lambda continuation parameter to decide if the API continues with the request or cancels.

Features

The EasyPermissionKt library supports the following features:

fun requestPermissions(vararg permissions: String)
fun hasPermissionFor(vararg permissions: String): Boolean
fun shouldShowRequestPermissionRationale(permission: String): Boolean
fun explainWhy(explainWhyUI: ExplainWhyUI): EasyPermissionKt

Demo

You might also like...
Android Mobile Application for Movie Reservation System.
Android Mobile Application for Movie Reservation System.

Movie-Reservation-Android-App Android Mobile Application for Movie Reservation System Brief Description of the Project 👇 “BlueSky Cinema” is an onlin

Android app with a simple NFC payment system to manage visitor consumption at short-duration events and festivals. (Research project)
Android app with a simple NFC payment system to manage visitor consumption at short-duration events and festivals. (Research project)

Clevent Também disponível em Português Clevent is an Android application developed for a Undergraduate Research that uses NFC technology to create a p

A semi-official port of the open source Anki spaced repetition flashcard system to Android
A semi-official port of the open source Anki spaced repetition flashcard system to Android

AnkiDroid A semi-official port of the open source Anki spaced repetition flashcard system to Android. Memorize anything with AnkiDroid! Features night

AVTS App - S.I.T Global PBL 2021 - Automatic Visitor Tracking System Android Application

S.I.T Global PBL 2021 - Automatic Visitor Tracking System Android Application De

MyTraining - Application project for Android system using Kotlin
MyTraining - Application project for Android system using Kotlin

MyTraining Projeto de aplicação para sistema Android utilizando linguagem Kotlin

weiV(pronounced the same as wave), a new declarative UI development framework based on the Android View system.

weiV(pronounced the same as wave) 简体中文 if ("weiV" == "View".reversed()) { Log.d( "weiV", "It means Inversion of Control, you shoul

Xposed module to set the Signature Scheme for Android 30 = to 1. This allows system apps to be modified

SetSignatureSchemeV1 Xposed module to set the Signature Scheme for Android 30+ to 1. This allows system apps to be modified. This module makes the met

Space recommendation system and augmenting informations with ARCore SDK
Space recommendation system and augmenting informations with ARCore SDK

Space recommendation system and augmenting informations with ARCore SDK

An unofficial companion app for DJI's Digital FPV System.
An unofficial companion app for DJI's Digital FPV System.

fpv-dvca An unofficial companion app for DJI's Digital FPV System for Android devices. Plug your Android device into your Googles and watch a live fee

Releases(1.0.5)
Owner
Wellington Cabral da Silva
Wellington Cabral da Silva
Tiny app to monitor permission changes.

Catcher Permission monitor. Tiny app to monitor permission changes. If any app will get INTERNET permission after an update you will get a notificatio

lucky 9 Oct 9, 2022
An android app that lists all planets in our solar system and brings some information about them.

SolarSystem This application was developed in Android Studio and uses Kotlin as programming language. In short, it is an app that lists all the planet

Dayon Oliveira 0 Nov 3, 2021
Android Studio project wrapper around the Elixir TodoApp Desktop app to run on Android including the Erlang runtime

TodoApp Android: An Android Sample App This Android Studio project wraps the Desktop Sample App to run on an Android phone. How to build & run Install

elixir-desktop 78 Dec 10, 2022
KotlinSample - Template project for building a GTK3 Kotlin/Native app against the elementary Flatpak runtime

GTK3 Kotlin/Native Sample This is a working example of how to write and build a

David Hewitt 10 Dec 5, 2022
React-native-user-interface - Change React Native userinterface at runtime

react-native-user-interface change RN userinterface at runtime. Installation npm

Ahmed Eid 0 Jan 11, 2022
ArchGuard is a architecture governance tool which can analysis architecture in container, component, code level, create architecure fitness functions, and anaysis system dependencies..

ArchGuard backend ArchGuard is a architecture governance tool which can analysis architecture in container, component, code level, database, create ar

ArchGuard 446 Dec 20, 2022
A Android app Permissions with Kotlin Flow APIs

Know about real-time state of a Android app Permissions with Kotlin Flow APIs. Made with ❤️ for Android Developers.

Shreyas Patil 281 Dec 30, 2022
FairEmail is easy to set up and works with virtually all email providers, including Gmail, Outlook and Yahoo!

Downloads • Privacy • Support • License FairEmail Fully featured, open source, privacy oriented email app for Android FairEmail is easy to set up and

Marcel Bokhorst 1.5k Jan 2, 2023
A music picker library for React Native. Provides access to the system's UI for selecting songs from the phone's music library.

Expo Music Picker A music picker library for React Native. Provides access to the system's UI for selecting songs from the phone's music library. Supp

Bartłomiej Klocek 60 Dec 29, 2022
Easy-Note - Easy Note Application will help user to add and update their important notes

Easy-Note ??️ Easy Note App helps you to create your notes. You can ?? edit and

Ade Amit 0 Jan 30, 2022