Java Code Examples for com.tbruyelle.rxpermissions2.RxPermissions#isGranted()

The following examples show how to use com.tbruyelle.rxpermissions2.RxPermissions#isGranted() . 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: Utils.java    From AndroidDemo with MIT License 6 votes vote down vote up
public static Disposable checkPermission(Activity activity, String permission, String permissionZh) {
    RxPermissions rxPermissions = new RxPermissions(activity);
    Disposable disposable = null;
    if (!rxPermissions.isGranted(permission)) {
        disposable = rxPermissions.shouldShowRequestPermissionRationale(activity, permission)
                .flatMap(b -> {
                    if (b) {
                        return rxPermissions.request(permission);
                    } else {
                        return Observable.just(false);
                    }
                }).subscribe(b -> {
                    if (!b) {
                        showPermissionRequestAlertDialog(activity, permissionZh);
                    }
                });
    }
    return disposable;
}
 
Example 2
Source File: PermissionUtil.java    From AndroidBase with Apache License 2.0 6 votes vote down vote up
/**
 * 请求外部存储的权限
 */
public static void externalStorage(final RequestPermission requestPermission, RxPermissions rxPermissions, final IView view, RxErrorHandler errorHandler) {
    //先确保是否已经申请过摄像头,和写入外部存储的权限
    boolean isPermissionsGranted =
            rxPermissions
                    .isGranted(Manifest.permission.WRITE_EXTERNAL_STORAGE);

    if (isPermissionsGranted) {//已经申请过,直接执行操作
        requestPermission.onRequestPermissionSuccess();
    } else {//没有申请过,则申请
        rxPermissions
                .request(Manifest.permission.WRITE_EXTERNAL_STORAGE)
                .compose(RxUtils.<Boolean>bindToLifecycle(view))
                .subscribe(new ErrorHandleSubscriber<Boolean>(errorHandler) {
                    @Override
                    public void onNext(Boolean granted) {
                        if (granted) {
                            Timber.tag(TAG).d("request WRITE_EXTERNAL_STORAGE and CAMERA success");
                            requestPermission.onRequestPermissionSuccess();
                        } else {
                            view.showMessage("request permissons failure");
                        }
                    }
                });
    }
}
 
Example 3
Source File: PermissionUtil.java    From AndroidBase with Apache License 2.0 6 votes vote down vote up
/**
     * 请求发送短信权限
     */
    public static void sendSms(final RequestPermission requestPermission, RxPermissions rxPermissions, final IView view, RxErrorHandler errorHandler) {
//先确保是否已经申请过权限
        boolean isPermissionsGranted =
                rxPermissions
                        .isGranted(Manifest.permission.SEND_SMS);

        if (isPermissionsGranted) {//已经申请过,直接执行操作
            requestPermission.onRequestPermissionSuccess();
        } else {//没有申请过,则申请
            rxPermissions
                    .request(Manifest.permission.SEND_SMS)
                    .compose(RxUtils.<Boolean>bindToLifecycle(view))
                    .subscribe(new ErrorHandleSubscriber<Boolean>(errorHandler) {
                        @Override
                        public void onNext(Boolean granted) {
                            if (granted) {
                                Timber.tag(TAG).d("request SEND_SMS success");
                                requestPermission.onRequestPermissionSuccess();
                            } else {
                                view.showMessage("request permissons failure");
                            }
                        }
                    });
        }
    }
 
Example 4
Source File: PermissionUtil.java    From AndroidBase with Apache License 2.0 6 votes vote down vote up
/**
     * 请求打电话权限
     */
    public static void callPhone(final RequestPermission requestPermission, RxPermissions rxPermissions, final IView view, RxErrorHandler errorHandler) {
//先确保是否已经申请过权限
        boolean isPermissionsGranted =
                rxPermissions
                        .isGranted(Manifest.permission.CALL_PHONE);

        if (isPermissionsGranted) {//已经申请过,直接执行操作
            requestPermission.onRequestPermissionSuccess();
        } else {//没有申请过,则申请
            rxPermissions
                    .request(Manifest.permission.CALL_PHONE)
                    .compose(RxUtils.<Boolean>bindToLifecycle(view))
                    .subscribe(new ErrorHandleSubscriber<Boolean>(errorHandler) {
                        @Override
                        public void onNext(Boolean granted) {
                            if (granted) {
                                Timber.tag(TAG).d("request SEND_SMS success");
                                requestPermission.onRequestPermissionSuccess();
                            } else {
                                view.showMessage("request permissons failure");
                            }
                        }
                    });
        }
    }
 
Example 5
Source File: PermissionUtil.java    From AndroidBase with Apache License 2.0 6 votes vote down vote up
/**
     * 请求获取手机状态的权限
     */
    public static void readPhonestate(final RequestPermission requestPermission, RxPermissions rxPermissions, IView view, RxErrorHandler errorHandler) {
//先确保是否已经申请过权限
        boolean isPermissionsGranted =
                rxPermissions
                        .isGranted(Manifest.permission.READ_PHONE_STATE);

        if (isPermissionsGranted) {//已经申请过,直接执行操作
            requestPermission.onRequestPermissionSuccess();
        } else {//没有申请过,则申请
            rxPermissions
                    .request(Manifest.permission.READ_PHONE_STATE)
                    .compose(RxUtils.<Boolean>bindToLifecycle(view))
                    .subscribe(new ErrorHandleSubscriber<Boolean>(errorHandler) {
                        @Override
                        public void onNext(Boolean granted) {
                            if (granted) {
                                Timber.tag(TAG).d("request SEND_SMS success");
                                requestPermission.onRequestPermissionSuccess();
                            } else {
                                Timber.tag(TAG).e("request permissons failure");
                            }
                        }
                    });
        }
    }
 
Example 6
Source File: PermissionUtil.java    From AndroidBase with Apache License 2.0 5 votes vote down vote up
/**
 * 请求摄像头权限
 */
public static void launchCamera(final RequestPermission requestPermission, RxPermissions rxPermissions, final IView view, RxErrorHandler errorHandler) {
    //先确保是否已经申请过摄像头,和写入外部存储的权限
    boolean isPermissionsGranted =
            rxPermissions
                    .isGranted(Manifest.permission.WRITE_EXTERNAL_STORAGE) &&
                    rxPermissions
                            .isGranted(Manifest.permission.CAMERA);

    if (isPermissionsGranted) {//已经申请过,直接执行操作
        requestPermission.onRequestPermissionSuccess();
    } else {//没有申请过,则申请
        rxPermissions
                .request(Manifest.permission.WRITE_EXTERNAL_STORAGE
                        , Manifest.permission.CAMERA)
                .compose(RxUtils.<Boolean>bindToLifecycle(view))
                .subscribe(new ErrorHandleSubscriber<Boolean>(errorHandler) {
                    @Override
                    public void onNext(Boolean granted) {
                        if (granted) {
                            Timber.tag(TAG).d("request WRITE_EXTERNAL_STORAGE and CAMERA success");
                            requestPermission.onRequestPermissionSuccess();
                        } else {
                            view.showMessage("request permissons failure");
                        }
                    }
                });
    }
}
 
Example 7
Source File: VideoSelectActivity.java    From Android-Video-Trimmer with Apache License 2.0 4 votes vote down vote up
@SuppressLint("CheckResult")
@Override public void initUI() {
  mVideoLoadManager = new VideoLoadManager();
  mVideoLoadManager.setLoader(new VideoCursorLoader());
  mBinding = DataBindingUtil.setContentView(this, R.layout.activity_video_select);
  mCameraSurfaceViewLy = findViewById(R.id.layout_surface_view);
  mBinding.mBtnBack.setOnClickListener(this);
  RxPermissions rxPermissions = new RxPermissions(this);
  rxPermissions.request(Manifest.permission.READ_EXTERNAL_STORAGE).subscribe(granted -> {
    if (granted) { // Always true pre-M
      mVideoLoadManager.load(this, new SimpleCallback() {
        @Override public void success(Object obj) {
          if (mVideoSelectAdapter == null) {
            mVideoSelectAdapter = new VideoSelectAdapter(VideoSelectActivity.this, (Cursor) obj);
          } else {
            mVideoSelectAdapter.swapCursor((Cursor) obj);
          }
          if (mBinding.videoGridview.getAdapter() == null) {
            mBinding.videoGridview.setAdapter(mVideoSelectAdapter);
          }
          mVideoSelectAdapter.notifyDataSetChanged();
        }
      });
    } else {
      finish();
    }
  });
  if (rxPermissions.isGranted(Manifest.permission.CAMERA)) {
    initCameraPreview();
  } else {
    mBinding.cameraPreviewLy.setVisibility(View.GONE);
    mBinding.openCameraPermissionLy.setVisibility(View.VISIBLE);
    mBinding.mOpenCameraPermission.setOnClickListener(new View.OnClickListener() {
      @Override public void onClick(View v) {
        rxPermissions.request(Manifest.permission.CAMERA).subscribe(granted -> {
          if (granted) {
            initCameraPreview();
          }
        });
      }
    });
  }
}