转载

Android 运行时权限库

AndroidPermissionX

中文文档

Android Developer

Setup

in your application's build.gradle

allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}

in your app's build.gradle

dependencies {
        compile 'com.github.fccaikai:AndroidPermissionX:0.1.0'
 }

Usage

create a PermissionCompat.Builder instance

PermissionCompat.Builder builder = new PermissionCompat.Builder(Context);

add Permissions Array

builder.addPermissions(new String[]{Manifest.permission.CAMERA});

to show Rationale Dialog when shouldShowRequestPermissionRationale() retuen true , to explain why need the permission

builder.addPermissionRationale("say why need the permission");

add OnRequestPermissionsCallBack ,like:

builder.addRequestPermissionsCallBack(new OnRequestPermissionsCallBack() {
                    @Override
                    public void onResult(String[] permissions, int[] grantResults) {
                        if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                            Log.d(TAG, "success");
                            //do something
                        } else {
                            Log.d(TAG, "falied");
                        }
                    }

                    @Override
                    public void onAuthorized() {
                        Log.d(TAG, "Authorized");
                        //do something
                    }
                })

request permission

builder.build().request();
原文  https://github.com/fccaikai/AndroidPermissionX
正文到此结束
Loading...