com.tbruyelle.rxpermissions2.RxPermissions Java Examples

The following examples show how to use com.tbruyelle.rxpermissions2.RxPermissions. 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: MainActivity.java    From Pixiv-Shaft with MIT License 6 votes vote down vote up
@Override
protected void initData() {
    if (sUserModel != null && sUserModel.getResponse().getUser().isIs_login()) {
        final RxPermissions rxPermissions = new RxPermissions(mActivity);
        Disposable disposable = rxPermissions
                .requestEachCombined(
                        Manifest.permission.WRITE_EXTERNAL_STORAGE
                )
                .subscribe(permission -> {
                    if (permission.granted) {
                        initFragment();
                    } else {
                        Common.showToast(mActivity.getString(R.string.access_denied));
                        finish();
                    }
                });
    } else {
        Intent intent = new Intent(mContext, TemplateActivity.class);
        intent.putExtra(TemplateActivity.EXTRA_FRAGMENT, "登录注册");
        startActivity(intent);
        finish();
    }
}
 
Example #3
Source File: ZeroFiveNewsDetailPresenter.java    From AcgClub with MIT License 6 votes vote down vote up
public void start2Share(RxPermissions rxPermissions) {
  rxPermissions.request(
      Manifest.permission.WRITE_EXTERNAL_STORAGE,
      Manifest.permission.ACCESS_FINE_LOCATION,
      Manifest.permission.WRITE_EXTERNAL_STORAGE)
      .subscribe(new Consumer<Boolean>() {
        @Override
        public void accept(@NonNull Boolean aBoolean) throws Exception {
          if (aBoolean) {
            mView.showShareView();
          } else {
            mView.showError(R.string.msg_error_check_permission);
          }
        }
      });
}
 
Example #4
Source File: ISHNewsDetailPresenter.java    From AcgClub with MIT License 6 votes vote down vote up
public void start2Share(RxPermissions rxPermissions) {
  rxPermissions.request(
      Manifest.permission.WRITE_EXTERNAL_STORAGE,
      Manifest.permission.ACCESS_FINE_LOCATION,
      Manifest.permission.WRITE_EXTERNAL_STORAGE)
      .subscribe(new Consumer<Boolean>() {
        @Override
        public void accept(@NonNull Boolean aBoolean) throws Exception {
          if (aBoolean) {
            mView.showShareView();
          } else {
            mView.showError(R.string.msg_error_check_permission);
          }
        }
      });
}
 
Example #5
Source File: PermissionUtils.java    From YCCustomText with Apache License 2.0 6 votes vote down vote up
/**
 * 检测电话权限
 * @param activity                          activity
 * @param callBack                          回调callBack
 */
@SuppressLint("CheckResult")
public static void checkPhonePermissions(final FragmentActivity activity,
                                         final PermissionCallBack callBack) {
    RxPermissions rxPermissions = new RxPermissions(activity);
    //request    不支持返回权限名,返回的权限结果:全部同意时值true,否则值为false
    rxPermissions
            .request(PHONE)
            .subscribe(new Consumer<Boolean>() {
                @Override
                public void accept(Boolean aBoolean) throws Exception {
                    if (aBoolean) {
                        //已经获得权限
                        callBack.onPermissionGranted(activity);
                    } else {
                        //用户拒绝开启权限,且选了不再提示时,才会走这里,否则会一直请求开启
                        callBack.onPermissionDenied(activity, PermissionCallBack.REFUSE);
                    }
                }
            });
}
 
Example #6
Source File: ScheduleDetailActivity.java    From AcgClub with MIT License 6 votes vote down vote up
@Override
protected void initData() {
  initPageStatus();
  setToolBar(mToolBar, "");
  collapsingToolbarLayout.setTitleEnabled(false);
  rxPermissions = new RxPermissions(this);

  String scheduleUrl = getIntent().getStringExtra(IntentConstant.SCHEDULE_DETAIL_URL);
  if (TextUtils.isEmpty(scheduleUrl)) {
    showError(R.string.msg_error_url_null);
    return;
  }
  btnScheduleDetailLike.setTag(false);
  mPresenter.setCurrentScheduleUrl(scheduleUrl);
  mPresenter.getScheduleDetail();
  mPresenter.getCurrentScheduleCache(rxPermissions, false);
}
 
Example #7
Source File: NoteTakingActivity.java    From science-journal with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  permissions = new RxPermissions(this);
  setContentView(R.layout.activity_experiment_layout);

  Resources resources = getResources();
  boolean isTablet = resources.getBoolean(R.bool.is_tablet);
  if (!isTablet) {
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
  }
  boolean isLandscape =
      resources.getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE;
  isTwoPane = isTablet && isLandscape;

  appAccount = WhistlePunkApplication.getAccount(this, getIntent(), EXTRA_ACCOUNT_KEY);
  experimentId = getIntent().getStringExtra(EXTRA_EXPERIMENT_ID);
  exp = whenSelectedExperiment(experimentId, getDataController());

  AppSingleton.getInstance(this)
      .whenLabelsAdded(appAccount)
      .takeUntil(destroyed.happens())
      .subscribe(event -> onLabelAdded(event.getTrialId(), event.getLabel()));
}
 
Example #8
Source File: ScheduleMainPresenter.java    From AcgClub with MIT License 6 votes vote down vote up
/**
 * 视频观看权限申请
 */
public void checkPermission2ScheduleVideo(RxPermissions rxPermissions, final String videoUrl) {
  if (TextUtils.isEmpty(videoUrl)) {
    mView.showError(R.string.msg_error_url_null);
    return;
  }
  rxPermissions.request(permission.WRITE_EXTERNAL_STORAGE,
      permission.READ_PHONE_STATE,
      permission.ACCESS_NETWORK_STATE,
      permission.ACCESS_WIFI_STATE)
      .subscribe(new Consumer<Boolean>() {
        @Override
        public void accept(@NonNull Boolean aBoolean) throws Exception {
          if (aBoolean) {
            mView.start2ScheduleVideo(videoUrl);
          } else {
            mView.showError(R.string.msg_error_check_permission);
          }
        }
      });
}
 
Example #9
Source File: PermissionUtils.java    From YCCustomText with Apache License 2.0 6 votes vote down vote up
/**
 * 定位权限
 * @param activity                          activity
 * @param callBack                          回调callBack
 */
@SuppressLint("CheckResult")
public static void checkLocationPermission(final FragmentActivity activity,
                                           final PermissionCallBack callBack) {
    RxPermissions rxPermissions = new RxPermissions(activity);
    //request    不支持返回权限名,返回的权限结果:全部同意时值true,否则值为false
    rxPermissions
            .request(LOCATION)
            .subscribe(new Consumer<Boolean>() {
                @Override
                public void accept(Boolean aBoolean) throws Exception {
                    if (aBoolean) {
                        //已经获得权限
                        callBack.onPermissionGranted(activity);
                    } else {
                        //用户拒绝开启权限,且选了不再提示时,才会走这里,否则会一直请求开启
                        callBack.onPermissionDenied(activity, PermissionCallBack.REFUSE);
                    }
                }
            });
}
 
Example #10
Source File: ArticleDetailActivity.java    From Awesome-WanAndroid with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case R.id.item_share:
            mPresenter.shareEventPermissionVerify(new RxPermissions(this));
            break;
        case R.id.item_collect:
            collectEvent();
            break;
        case R.id.item_system_browser:
            startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(articleLink)));
            break;
        default:
            break;
    }
    return super.onOptionsItemSelected(item);
}
 
Example #11
Source File: MainActivity.java    From RxGallery with MIT License 6 votes vote down vote up
private void takePhoto(final Uri outputUri) {
    Observable<Boolean> permissionObservable = Observable.just(true);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        permissionObservable = new RxPermissions(this).request(Manifest.permission.WRITE_EXTERNAL_STORAGE);
    }

    disposable =  permissionObservable.flatMap(new Function<Boolean, ObservableSource<Uri>>() {
        @Override
        public ObservableSource<Uri> apply(@NonNull Boolean granted) throws Exception {
            if (!granted) {
                return Observable.empty();
            }
            return RxGallery.photoCapture(MainActivity.this, outputUri).toObservable();
        }
    }).subscribe(new Consumer<Uri>() {
        @Override
        public void accept(Uri uri) throws Exception {
            Toast.makeText(MainActivity.this, uri.toString(), Toast.LENGTH_LONG).show();
        }
    }, new Consumer<Throwable>() {
        @Override
        public void accept(Throwable throwable) throws Exception {
            Toast.makeText(MainActivity.this, throwable.getMessage(), Toast.LENGTH_LONG).show();
        }
    });
}
 
Example #12
Source File: ScreenCaptureActivity.java    From AndroidAnimationExercise with Apache License 2.0 6 votes vote down vote up
private void saveBitmap(Bitmap bitmap) {
    RxPermissions rxPermissions = new RxPermissions(this);
    mDisposable = rxPermissions.request(Manifest.permission.WRITE_EXTERNAL_STORAGE)
            .subscribe(aBoolean -> {
                if (aBoolean) {
                    String path = FileUtil.savaBitmap2SDcard(ScreenCaptureActivity.this, bitmap, "myfile");
                    if (!TextUtils.isEmpty(path)) {
                        Toast.makeText(ScreenCaptureActivity.this, "success path is " + path, Toast.LENGTH_SHORT).show();
                        Intent intent = new Intent(ScreenCaptureActivity.this, FullscreenActivity.class);
                        intent.putExtra("path", path);
                        startActivity(intent);
                    } else {
                        Toast.makeText(ScreenCaptureActivity.this, "fail", Toast.LENGTH_SHORT).show();
                    }
                }
            }, Throwable::printStackTrace);
}
 
Example #13
Source File: PermissionUtils.java    From YCCustomText with Apache License 2.0 6 votes vote down vote up
/**
 * 读写权限
 * @param activity                          activity
 * @param callBack                          回调callBack
 */
@SuppressLint("CheckResult")
public static void checkWritePermissionsRequest(final FragmentActivity activity,
                                                final PermissionCallBack callBack) {
    RxPermissions rxPermissions = new RxPermissions(activity);
    //request    不支持返回权限名,返回的权限结果:全部同意时值true,否则值为false
    rxPermissions
            .request(WRITE)
            .subscribe(new Consumer<Boolean>() {
                @Override
                public void accept(Boolean aBoolean) throws Exception {
                    if (aBoolean) {
                        //已经获得权限
                        callBack.onPermissionGranted(activity);
                    } else {
                        //用户拒绝开启权限,且选了不再提示时,才会走这里,否则会一直请求开启
                        callBack.onPermissionDenied(activity, PermissionCallBack.REFUSE);
                    }
                }
            });
}
 
Example #14
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 #15
Source File: ISHNewsDetailActivity.java    From AcgClub with MIT License 6 votes vote down vote up
@Override
protected void initData() {
  setToolBar(mToolBar, "");
  tvAcgDetailLabels.setVisibility(android.view.View.GONE);
  mSHNewsPostItem = getIntent().getParcelableExtra(IntentConstant.ISH_NEWS_ITEM);
  if (mSHNewsPostItem == null) {
    showError(R.string.msg_error_unknown);
    return;
  }

  mToolBar.setOnMenuItemClickListener(new OnMenuItemClickListener() {
    @Override
    public boolean onMenuItemClick(MenuItem item) {
      if (item.getItemId() == R.id.acginfo_share) {
        mPresenter.start2Share(new RxPermissions(ISHNewsDetailActivity.this));
      }
      return false;
    }
  });

  mPresenter.getNewsDetail(mSHNewsPostItem.getId());
}
 
Example #16
Source File: VideoListFragment.java    From Aurora with Apache License 2.0 5 votes vote down vote up
@Override
public void setupFragmentComponent(AppComponent appComponent) {
    this.mRxPermissions = new RxPermissions(getActivity());
    DaggerVideoComponent //如找不到该类,请编译一下项目
            .builder()
            .appComponent(appComponent)
            .videoModule(new VideoModule(this))
            .build()
            .inject(this);
}
 
Example #17
Source File: CategoryFragment.java    From Aurora with Apache License 2.0 5 votes vote down vote up
@Override
public void setupFragmentComponent(AppComponent appComponent) {
    mRxPermissions = new RxPermissions(getActivity());
    DaggerCategoryComponent //如找不到该类,请编译一下项目
            .builder()
            .appComponent(appComponent)
            .categoryModule(new CategoryModule(this))
            .build()
            .inject(this);
}
 
Example #18
Source File: SplashActivity.java    From Aurora with Apache License 2.0 5 votes vote down vote up
@Override
public void setupActivityComponent(AppComponent appComponent) {
    this.mRxPermissions = new RxPermissions(this);
    DaggerSplashComponent.builder()
            .appComponent(appComponent)
            .splashModule(new SplashModule(this))
            .build()
            .inject(this);
}
 
Example #19
Source File: FlutterVideoDetailActivity.java    From Aurora with Apache License 2.0 5 votes vote down vote up
@Override
public void setupActivityComponent(AppComponent appComponent) {
    this.mRxPermissions = new RxPermissions(this);
    mAppComponent = appComponent;
    gson = mAppComponent.gson();
    DaggerFlutterVideoDetailComponent
            .builder()
            .videoDetailModule(new VideoDetailModule(this))
            .appComponent(appComponent)
            .build()
            .inject(this);
}
 
Example #20
Source File: MainPresenter.java    From Ency with Apache License 2.0 5 votes vote down vote up
@Inject
public MainPresenter(WeatherApi weatherApi, UpdateApi updateApi, RxPermissions rxPermissions, Context context) {
    this.weatherApi = weatherApi;
    this.updateApi = updateApi;
    this.rxPermissions = rxPermissions;
    this.context = context;
}
 
Example #21
Source File: CheckPermissionsUtils.java    From MiPushFramework with GNU General Public License v3.0 5 votes vote down vote up
public static Disposable checkPermissionsAndStartAsync (@NonNull FragmentActivity context,
                                                        @NonNull Consumer<ActivityResultAndPermissionResult> onNext,
                                                        @NonNull Consumer<Throwable> onError) {
    return Observable.zip(buildRemoveDozeObservable(context)
            , new RxPermissions(context)
                    .requestEachCombined(Constants.permissions.WRITE_SETTINGS),
            ActivityResultAndPermissionResult::new)
            .subscribe(onNext, onError);
}
 
Example #22
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 #23
Source File: SampleActivity.java    From Matisse with Apache License 2.0 5 votes vote down vote up
@SuppressLint("CheckResult")
@Override
public void onClick(final View v) {
    RxPermissions rxPermissions = new RxPermissions(this);
    rxPermissions.request(Manifest.permission.WRITE_EXTERNAL_STORAGE)
            .subscribe(aBoolean -> {
                if (aBoolean) {
                    startAction(v);
                } else {
                    Toast.makeText(SampleActivity.this, R.string.permission_request_denied, Toast.LENGTH_LONG)
                            .show();
                }
            }, Throwable::printStackTrace);
}
 
Example #24
Source File: HotFragment.java    From Aurora with Apache License 2.0 5 votes vote down vote up
@Override
public void setupFragmentComponent(AppComponent appComponent) {
    this.mRxPermissions = new RxPermissions(getActivity());
    DaggerHotComponent //如找不到该类,请编译一下项目
            .builder()
            .appComponent(appComponent)
            .hotModule(new HotModule(this))
            .build()
            .inject(this);
}
 
Example #25
Source File: BaseSwipeActivity.java    From C9MJ with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    //6.0权限申请
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        RxPermissions rxPermissions = new RxPermissions(this);
        rxPermissions
                .requestEach(
                        Manifest.permission.CAMERA,
                        Manifest.permission.INTERNET,
                        Manifest.permission.READ_EXTERNAL_STORAGE,
                        Manifest.permission.WRITE_EXTERNAL_STORAGE)
                .subscribe(permission -> {
                    if (permission.granted) {
                        // `permission.name` is granted !
                    } else if (permission.shouldShowRequestPermissionRationale) {
                        // Denied permission without ask never again
                    } else {
                        // Denied permission with ask never again
                        // Need to go to the settings
                        ToastUtils.showShortToast(getString(R.string.error_grant));
                    }

                });
    }
    ;
}
 
Example #26
Source File: ImageZoomActivity.java    From NGA-CLIENT-VER-OPEN-SOURCE with GNU General Public License v2.0 5 votes vote down vote up
private void saveBitmap(OnSimpleHttpCallBack<SaveImageTask.DownloadResult> callBack, String... urls) {
    new RxPermissions(this)
            .request(Manifest.permission.WRITE_EXTERNAL_STORAGE)
            .subscribe(granted -> {
                if (granted) { // Always true pre-M
                    if (mSaveImageTask == null) {
                        mSaveImageTask = new SaveImageTask();
                    }
                    mSaveImageTask.execute(callBack, urls);
                } else {
                    // Oups permission denied
                }
            });
}
 
Example #27
Source File: BaseActivity.java    From APlayer with GNU General Public License v3.0 5 votes vote down vote up
@SuppressLint("CheckResult")
@Override
protected void onResume() {
  super.onResume();
  mIsForeground = true;
  new RxPermissions(this)
      .request(EXTERNAL_STORAGE_PERMISSIONS)
      .subscribe(has -> {
        if (has != mHasPermission) {
          Intent intent = new Intent(MusicService.PERMISSION_CHANGE);
          intent.putExtra(BaseMusicActivity.EXTRA_PERMISSION, has);
          sendLocalBroadcast(intent);
        }
      });
}
 
Example #28
Source File: SearchActivity.java    From YelpQL with MIT License 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_home);

    ButterKnife.bind(this);

    compositeDisposable = new CompositeDisposable();

    rxPermissions = new RxPermissions(this);
    rxLocation = new RxLocation(this);

    LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
    rvNearbyRestaurant.setLayoutManager(linearLayoutManager);

    // get users last known location
    getLastKnownLocation(searchTerm);

    endlessRecyclerViewScrollListener = new EndlessRecyclerViewScrollListener(linearLayoutManager) {
        @Override
        public void onLoadMore(int page, int totalItemsCount, RecyclerView view) {
            offset = totalItemsCount;
            loadData(searchTerm, lastKnownLocation, offset);
        }
    };

    rvNearbyRestaurant.addOnScrollListener(endlessRecyclerViewScrollListener);
}
 
Example #29
Source File: PermissionUtil.java    From screen-share-to-browser with Apache License 2.0 5 votes vote down vote up
public static void requestPermission(final Activity activity, final PermissionsListener listener, final String... permissions) {
    RxPermissions rxPermissions = new RxPermissions(activity);
    rxPermissions.request(permissions)
            .subscribe(new Observer<Boolean>() {
                @Override
                public void onSubscribe(Disposable d) {

                }

                @Override
                public void onNext(Boolean aBoolean) {
                    if (aBoolean) {
                        listener.onGranted();
                    } else {
                        Toast.makeText(activity, R.string.permission_request_denied, Toast.LENGTH_LONG)
                                .show();
                    }
                }

                @Override
                public void onError(Throwable e) {

                }

                @Override
                public void onComplete() {

                }
            });
}
 
Example #30
Source File: MainActivity.java    From android-ponewheel with MIT License 5 votes vote down vote up
private Single<Boolean> getPermissions() {
    // TODO I think this is necessary since changing the target api
    RxPermissions rxPermissions = new RxPermissions(this);
    return rxPermissions
            .request(Manifest.permission.ACCESS_FINE_LOCATION)
            .firstOrError();
}