Coder Social home page Coder Social logo

android-easy-permissions's Introduction

EasyPermissions

API Mavenn Central Compose Version Github License

EasyPermissions is created to make the runtime permissions easier.

๐Ÿšง Note: The project is almost completed and waiting for feedbacks and issues. You are most welcome to test it and generate issue or feedback๐Ÿ™‚.

๐Ÿ‘‰ Setup Guide | Report new issue

Download

Mention dependency in build.gradle(app)

For Groovy:

implementation 'io.github.rumitpatel:easy-permissions:1.0.5'

For Kotlin DSL:

implementation("io.github.rumitpatel:easy-permissions:1.0.5")

Declear permissions in menifest

For example. If you want to request Camera, Coarse-location and Storage permissions, first, declare them in the AndroidManifest.xml.

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.permissionx.app">

    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
</manifest>

How do I use EasyPermissions?

Step:1 Create an object of EasyPermission.

private var easyPermissions: EasyPermissions? = null

Step:2 Initiate permission obj in obCreate() method. Also handle callback here.

private fun initializePermissionObj() {
    easyPermissions = EasyPermissions.Builder(this@PermissionDemoActivity)
        .setPermissionType(EasyPermissions.PermissionType.PERMISSION_CAMERA_AND_STORAGE)
        .setOnPermissionListener(object : OnPermissionsListener {
            override fun onGranted() {
                toast(getString(R.string.permission_granted))
            }

            override fun onDeclined(shouldRequestAgain: Boolean) {
                toast(getString(R.string.permission_declined))
                if (shouldRequestAgain) {
                    // You can request again by calling "easyPermissions?.launch()" here.
                } else {
                    //Never ask again selected, dismissed the dialog, or device policy prohibits the app from having that permission
                    // For example, Settings dialog opened here.
                    showSettingsDialog()
                }
            }
        })
        .build()
}

Step:3 Simply launch the launcher.

buttonTest.setOnClickListener {
    easyPermissions?.launch()
}

Note: Please make sure the required permissions are added in Androidmanifest.xml too.

PermissionType examples

  1. PermissionType.PERMISSION_CAMERA_AND_STORAGE: It will open the dialog with permissions required for capture and retrieve image.

  2. PermissionType.PERMISSION_STORAGE: It will open the dialog with permissions required for storage.

  3. PermissionType.PERMISSION_LOCATION: It will open the dialog with permissions required for ACCESS_COARSE_LOCATION and ACCESS_FINE_LOCATION.

  4. PermissionType.PERMISSION_SPECIFIC: You can open the permission dialog for single permission too.

Output:

easy-permissions-demo-gif-2

Thanks:

Build and Publish multi-module Android library to Maven Central by Jayesh Seth.

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.