Permissiongrantor

一行代码搞定Android6.0动态权限授权、权限管理 || Android permission grantor util
Alternatives To Permissiongrantor
Project NameStarsDownloadsRepos Using ThisPackages Using ThisMost Recent CommitTotal ReleasesLatest ReleaseOpen IssuesLicenseLanguage
Easypermissions9,6731a month ago3August 13, 201928apache-2.0Java
Simplify Android M system permissions
Permissionskit5,213
2a month ago67November 01, 20215mitSwift
Universal API for request permission and get its statuses.
Dexter5,00374192 years ago34July 02, 202134apache-2.0Java
Android library that simplifies the process of requesting permissions at runtime.
Permissionx2,659
8 months ago10September 18, 20222apache-2.0Kotlin
An open source Android library that makes handling runtime permissions extremely easy.
Tedpermission1,572
a year ago8October 27, 202122Java
Easy check permission library for Android Marshmallow
Quickpermissions432
5 years ago5apache-2.0Kotlin
The most easiest way to handle Android Runtime Permissions
Fcpermissions404
7 years ago5Java
Fuck the permissions in Android M
Permissify373
7 years ago1mitJava
Simplifying Android Permissions
Locus Android306
16 days ago1January 11, 202210apache-2.0Kotlin
An Awesome Kotlin Location library to retrieve location merely in 3 lines of code
Permissiongrantor286
4 years ago1Java
一行代码搞定Android6.0动态权限授权、权限管理 || Android permission grantor util
Alternatives To Permissiongrantor
Select To Compare


Alternative Project Comparisons
Readme

update 2017-07-31

fix bug on XiaoMi device

update 2017-08-08

update dialog style

update 2017-08-29

set minSdkVersion to 14

update 2017-11-15

申请授权不依赖于Activity对象

Grantor

An Android permission grant util which is concise and easy to use. Normally you need to request permission in an Activity or Fragment and get the result by inheriting its method:

 public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
            @NonNull int[] grantResults) {
        /* callback - no nothing */
    }

If you request permissions in other Class(for example in a widget), things will become complicated. Grantor handle permission in alone Activity and simplify the work, when user deny permission, by default it's can show a dialog to explain why you need the permission, of course you can config it not to show the explaining dialog.

How to use

  • 1 add to module's dependencies.
dependencies {
      compile 'com.github.dfqin:grantor:2.5'
}
  • 2 use in your code.
PermissionsUtil.requestPermission(Context context, PermissionListener listener, String[] permissions);
  • 3 some demo.
private void requestCemera() {
        PermissionsUtil.requestPermission(getApplication(), new PermissionListener() {
            @Override
            public void permissionGranted(@NonNull String[] permissions) {
                Toast.makeText(MainActivity.this, "访问摄像头", Toast.LENGTH_LONG).show();
            }

            @Override
            public void permissionDenied(@NonNull String[] permissions) {
                Toast.makeText(MainActivity.this, "用户拒绝了访问摄像头", Toast.LENGTH_LONG).show();
            }
        }, Manifest.permission.CAMERA);
    }


    private void requestReadContact() {
        PermissionsUtil.TipInfo tip = new PermissionsUtil.TipInfo("注意:", "我就是想看下你的通讯录", "不让看", "打开权限");
        PermissionsUtil.requestPermission(this, new PermissionListener() {
            @Override
            public void permissionGranted(@NonNull String[] permissions) {
                JSONArray arr = null;
                try {
                    arr = getContactInfo(MainActivity.this);
                    if (arr.length() == 0) {
                        Toast.makeText(MainActivity.this, "请确认通讯录不为空且有访问权限", Toast.LENGTH_LONG).show();
                    } else {
                        Toast.makeText(MainActivity.this, arr.toString(), Toast.LENGTH_LONG).show();
                    }

                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void permissionDenied(@NonNull String[] permissions) {
                Toast.makeText(MainActivity.this, "用户拒绝了读取通讯录权限", Toast.LENGTH_LONG).show();
            }
        }, new String[]{Manifest.permission.READ_CONTACTS}, true, tip);
    }

    private void requestSms() {

        PermissionsUtil.requestPermission(this, new PermissionListener() {
            @Override
            public void permissionGranted(@NonNull String[] permissions) {
                Toast.makeText(MainActivity.this, "访问消息", Toast.LENGTH_LONG).show();
            }

            @Override
            public void permissionDenied(@NonNull String[] permissions) {
                Toast.makeText(MainActivity.this, "用户拒绝了读取消息权限", Toast.LENGTH_LONG).show();
            }
        }, new String[]{Manifest.permission.READ_SMS}, false, null);
    }

  • 4 the demo image.

默认

授权拒绝时自定义Dialog

授权拒绝时不显示Dialog

License

The MIT License (MIT) Copyright (c) 2017, dfqin

Popular Permission Projects
Popular Dialog Projects
Popular Security Categories

Get A Weekly Email With Trending Projects For These Categories
No Spam. Unsubscribe easily at any time.
Java
Permissions
Dialog