Code Monkey home page Code Monkey logo

easygrant's Introduction

EasyGrant

EasyGrant is yet another Android Library to ease the process of asking Runtime Permissions. Quoting Android official site -- Beginning in Android 6.0 (API level 23), users grant permissions to apps while the app is running, not when they install the app. This approach streamlines the app install process, since the user does not need to grant permissions when they install or update the app. It also gives the user more control over the app's functionality; for example, a user could choose to give a camera app access to the camera but not to the device location. The user can revoke the permissions at any time, by going to the app's Settings screen.

Actual code for seeking permissions, showing rationale and handling disabled permissions is little complex and tightly coupled with Activity.

HOW IT WORKS

Firstly, create PermissionRequest

private var cameraPermission = PermissionRequest(Manifest.permission.CAMERA,
            "I need camera permission to show you world", 1)

Secondly, call the method like this for single permission

private fun askCamPermission() {
        EasyGrant.Builder()
                .withActivity(this)
                .withPermission(cameraPermission)
                .setCallback(this)
                .seek()
    }

EasyGrant will provide simple callback of GrantCallbacks like

interface GrantCallbacks {
   
    fun onPermissionDenied(deniedPermissions: ArrayList<PermissionRequest>)

    fun onPermissionDisabled(disabledPermissions: ArrayList<PermissionRequest>)

    fun onPermissionGranted(grantedPermissions: ArrayList<PermissionRequest>)
}

EasyGrant seeks either a single permission or seeks multiple permissions in one go. To seek a single permission you must call withPermission(permissionRequest: PermissionRequest), To seek multiple permission you must call withPermissions(permissionsRequest: List<PermissionRequest>)

PermissionRequest takes permission name, rationale message to be shown and id.

EasyGrant throws IllegalEasyGrantBuilderException if with(activity: Activity)not called or called with a null value. If setCallback(callback: GrantCallbacks) is not called or called with null value. If none of the permissions are requested.

Multiple permission

EasyGrant.Builder()
        .withActivity(this)
        .withPermissions(permissionsList)
        .setCallback(this)
        .seek()

Usage

Dependency

Include the library in your app level build.gradle

dependencies{
    compile 'com.abhinavsharma:easygrant:0.0.5'
}

Do you want to contribute?

Feel free to add or suggest any useful feature to the library, I would be glad to improve it with your help.

Proudly ๐Ÿ’ช made in Kotlin

License

Copyright 2017 Abhinav Sharma

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.

easygrant's People

Contributors

abhinav272 avatar pine avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.