GithubHelp home page GithubHelp logo

nayan-dhabarde / permissionactivity Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 136 KB

Easily manage permissions in your Android app via a single callback and eliminate boilerplate code

Kotlin 100.00%

permissionactivity's Introduction

Permission Activity

The current way of handling runtime permissions in Android is error prone and needs a lot of boilerplate code. Permission Activity makes it easy to handle runtime permissions using Higher order functions and by maintaining a map of your permissions to actions. To use it, all you need to do is to inherit the PermissionActivity class and then call requestPermission(permission = permission in form of array, action = { }). The library contains a single Activity and nothing else and hence, it will add almost negligible amount of size to your app.

How to use:

  1. Add jitpack io to project level build.gradle file:
    allprojects {
		repositories {
			...
			maven { url 'https://jitpack.io' }
		}
    }
  1. Add Permission activity dependency in app level build.gradle file:
    implementation 'com.github.ndhabrde11:PersmissionActivity:1.0.0'

Sample code:

class MainActivity : PermissionActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        requestPermission(arrayOf(android.Manifest.permission.CAMERA)) { status ->
            when(status) {
                Status.REQUESTING -> {}
                Status.GRANTED -> {
                    // do your stuff
                }
                Status.DENIED -> {
                    // show message
                }
            }
        }
    }
}

That's it!

Logging

Following are the logs provided by the library:

 D/PermissionActivity: CAMERA: Requesting permission 
 D/PermissionActivity: CAMERA: Permission granted 
 D/PermissionActivity: CAMERA: Permission denied

permissionactivity's People

Contributors

nayan-dhabarde 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.