com.tbruyelle.rxpermissions2.Permission Java Examples

The following examples show how to use com.tbruyelle.rxpermissions2.Permission. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PermissionUtils.java    From YCCustomText with Apache License 2.0 5 votes vote down vote up
/**
 * 相机权限
 * @param activity                          activity
 * @param callBack                          回调callBack
 */
@SuppressLint("CheckResult")
public static void checkCameraPermissions(final FragmentActivity activity,
                                          final PermissionCallBack callBack) {
    RxPermissions rxPermissions = new RxPermissions(activity);
    //requestEachCombined
    //返回的权限名称:将多个权限名合并成一个
    //返回的权限结果:全部同意时值true,否则值为false
    rxPermissions
            .requestEachCombined(CAMERA)
            .subscribe(new Consumer<Permission>() {
                @Override
                public void accept(Permission permission) throws Exception {
                    boolean shouldShowRequestPermissionRationale =
                            permission.shouldShowRequestPermissionRationale;
                    if (permission.granted) {
                        // 用户已经同意该权限
                        callBack.onPermissionGranted(activity);
                    } else if (shouldShowRequestPermissionRationale) {
                        // 用户拒绝了该权限,没有选中『不再询问』(Never ask again)
                        // 那么下次再次启动时。还会提示请求权限的对话框
                        callBack.onPermissionDenied(activity, PermissionCallBack.DEFEATED);
                    } else {
                        // 用户拒绝了该权限,而且选中『不再询问』那么下次启动时,就不会提示出来了,
                        callBack.onPermissionDenied(activity, PermissionCallBack.REFUSE);
                    }
                }
            });
}
 
Example #2
Source File: PermissionUtils.java    From YCCustomText with Apache License 2.0 5 votes vote down vote up
/**
 * 检测短信息权限
 * @param activity                          activity
 * @param callBack                          回调callBack
 */
@SuppressLint("CheckResult")
public static void checkSmsPermissions(final FragmentActivity activity,
                                       final PermissionCallBack callBack) {
    RxPermissions rxPermissions = new RxPermissions(activity);
    //requestEach   把每一个权限的名称和申请结果都列出来
    rxPermissions
            .requestEach(SMS)
            .subscribe(new Consumer<Permission>() {
                @Override
                public void accept(Permission permission) throws Exception {
                    boolean shouldShowRequestPermissionRationale =
                            permission.shouldShowRequestPermissionRationale;
                    if (permission.granted) {
                        // 用户已经同意该权限
                        callBack.onPermissionGranted(activity);
                    } else if (shouldShowRequestPermissionRationale) {
                        // 用户拒绝了该权限,没有选中『不再询问』(Never ask again)
                        // 那么下次再次启动时。还会提示请求权限的对话框
                        callBack.onPermissionDenied(activity, PermissionCallBack.DEFEATED);
                    } else {
                        // 用户拒绝了该权限,而且选中『不再询问』那么下次启动时,就不会提示出来了,
                        callBack.onPermissionDenied(activity, PermissionCallBack.REFUSE);
                    }
                }
            });
}
 
Example #3
Source File: ActivityResultAndPermissionResult.java    From MiPushFramework with GNU General Public License v3.0 4 votes vote down vote up
public ActivityResultAndPermissionResult(boolean removeDozeResult, Permission permissionResult) {
    this.removeDozeResult = removeDozeResult;
    this.permissionResult = permissionResult;
}
 
Example #4
Source File: PermissionUtils.java    From NGA-CLIENT-VER-OPEN-SOURCE with GNU General Public License v2.0 4 votes vote down vote up
public static void requestCombined(AppCompatActivity activity, @Nullable Consumer<? super Permission> consumer, String... permissions) {
    consumer = createIfNull(consumer);
    new RxPermissions(activity).requestEachCombined(permissions).subscribe(consumer);
}
 
Example #5
Source File: PermissionUtils.java    From NGA-CLIENT-VER-OPEN-SOURCE with GNU General Public License v2.0 4 votes vote down vote up
public static void requestEach(AppCompatActivity activity, @Nullable Consumer<? super Permission> consumer, String... permissions) {
    consumer = createIfNull(consumer);
    new RxPermissions(activity).requestEach(permissions).subscribe(consumer);
}
 
Example #6
Source File: PermissionUtils.java    From NGA-CLIENT-VER-OPEN-SOURCE with GNU General Public License v2.0 4 votes vote down vote up
public static void requestCombined(Fragment fragment, @Nullable Consumer<? super Permission> consumer, String... permissions) {
    consumer = createIfNull(consumer);
    new RxPermissions(fragment).requestEachCombined(permissions).subscribe(consumer);
}
 
Example #7
Source File: PermissionUtils.java    From NGA-CLIENT-VER-OPEN-SOURCE with GNU General Public License v2.0 4 votes vote down vote up
public static void requestEach(Fragment fragment, @Nullable Consumer<? super Permission> consumer, String... permissions) {
    consumer = createIfNull(consumer);
    new RxPermissions(fragment).requestEach(permissions).subscribe(consumer);
}