Java源码示例:com.mylhyl.acp.AcpOptions

示例1
/**
 * 初始化SDCard缓存目录
 * @param dirName 根目录名称
 * @return
 */
public BasicConfig initDir(@NonNull final String dirName){
    Acp.getInstance(mContext).request(new AcpOptions.Builder()
                    .setPermissions(Manifest.permission.WRITE_EXTERNAL_STORAGE)
                    .build(),
            new AcpListener() {
                @Override
                public void onGranted() {
                    SDcardUtil.setRootDirName(dirName);
                    SDcardUtil.initDir();
                }

                @Override
                public void onDenied(List<String> permissions) {
                    Print.e(permissions.toString() + "权限拒绝");
                }
            });
    return this;
}
 
示例2
/**
 * 获取权限
 */
private void requestPermission() {
    Acp.getInstance(root).request(new AcpOptions.Builder().setPermissions(maniFests).build(), new AcpListener() {
        @Override
        public void onGranted() {
        }

        @Override
        public void onDenied(List<String> permissions) {
        }
    });
}
 
示例3
/**
     *  compile 'com.mylhyl:acp:1.0.0'
     * @param listener
     * @param permission
     */
    private static void askPermission(final PermissionListener listener,String... permission){
        if (Build.VERSION.SDK_INT >= 23) {
            // Marshmallow+
            Acp.getInstance(PhotoUtil.context).request(new AcpOptions.Builder()
                            .setPermissions(permission)
//                .setDeniedMessage()
//                .setDeniedCloseBtn()
//                .setDeniedSettingBtn()
//                .setRationalMessage()
//                .setRationalBtn()
                            .build(),
                    new AcpListener() {
                        @Override
                        public void onGranted() {
                            listener.onGranted();
                        }

                        @Override
                        public void onDenied(List<String> permissions) {
                            listener.onDenied(permissions);
                           // MyToast.showFailToast("权限已经被拒绝");
                        }
                    });
        } else {
            // Pre-Marshmallow
            listener.onGranted();
        }
    }