Check marshmallow permission easily
Clone or download
rebus007 version 3.0.0
- update libs
Latest commit 0e8048f Sep 20, 2018
Permalink
Failed to load latest commit information.
.github add ISSUE_TEMPLATE.md Nov 16, 2016
docs version 2.0.7 Apr 16, 2018
img/social add copyright Jul 17, 2016
library version 3.0.0 Sep 20, 2018
sample version 3.0.0 Sep 20, 2018
.gitignore first commit Jul 16, 2016
LICENSE version 2.0.0 BETA 1 May 25, 2017
README.md version 2.0.7 Apr 16, 2018
build.gradle version 3.0.0 Sep 20, 2018
gradle.properties first commit Jul 16, 2016
settings.gradle first commit Jul 16, 2016

README.md

Permission Utils

Download API GitHub issues GitHub forks GitHub stars GitHub license Android Arsenal

Logo

Check marshmallow permission easily

Import

At the moment the library is in my personal maven repo

repositories {
    maven {
        url 'http://dl.bintray.com/raphaelbussa/maven'
    }
}
dependencies {
    compile 'rebus:permission-utils:2.0.7'
}

How to use

Request a permission

First, override onRequestPermissionsResult and call PermissionManager.handleResult(requestCode, permissions, grantResults);

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
    super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    PermissionManager.handleResult(this, requestCode, permissions, grantResults);
}

Now you can ask permission :D

PermissionManager.Builder()
        .permission(PermissionEnum.WRITE_EXTERNAL_STORAGE)
        .askAgain(true)
        .askAgainCallback(new AskAgainCallback() {
            @Override
            public void showRequestPermission(UserResponse response) {
                    showDialog(response);
                }
            })
        .callback(new FullCallback() {
            @Override
            public void result(ArrayList<PermissionEnum> permissionsGranted, ArrayList<PermissionEnum> permissionsDenied, ArrayList<PermissionEnum> permissionsDeniedForever, ArrayList<PermissionEnum> permissionsAsked) {
                }
            })
        .ask(this);

or more permission

.permission(PermissionEnum.GET_ACCOUNTS, PermissionEnum.ACCESS_FINE_LOCATION, PermissionEnum.READ_SMS)

or

ArrayList<PermissionEnum> permissionEnumArrayList = new ArrayList<>();
permissionEnumArrayList.add(PermissionEnum.ACCESS_FINE_LOCATION);
permissionEnumArrayList.add(PermissionEnum.GET_ACCOUNTS);
permissionEnumArrayList.add(PermissionEnum.READ_CONTACTS);

.permissions(permissionEnumArrayList)

if you need to simply check a permission, just call utils

PermissionEnum permissionEnum = PermissionEnum.WRITE_EXTERNAL_STORAGE;
boolean granted = PermissionUtils.isGranted(MainActivity.this, PermissionEnum.WRITE_EXTERNAL_STORAGE);
Toast.makeText(MainActivity.this, permissionEnum.toString() + " isGranted [" + granted + "]", Toast.LENGTH_SHORT).show()

Callbacks

You can use three different callback, it depends of your needs.

  • FullCallback: gives you all the information on permission requested by you
  • SimpleCallback: returns a boolean that says if all permission requests were permitted
  • SmartCallback: returns a boolean that says if all permission requests were permitted and a boolean that says if some permissions are denied forever

Little extra

If user answer "Never ask again" to a request for permission, you can redirect user to app settings, with an utils

PermissionUtils.openApplicationSettings(MainActivity.this, R.class.getPackage().getName());

That's all folks!

Sample

Browse the sample code here

Javadoc

Browse Javadoc here

App using Permission Utils

If you use this lib contact me and I will add it to the list below:

Developed By

Raphaël Bussa - raphaelbussa@gmail.com

Twitter Google Plus Linkedin

License

The MIT License (MIT)

Copyright (c) 2017 Raphaël Bussa

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.