需要导入库
implementation 'com.github.tbruyelle:rxpermissions:0.10.2'
implementation 'io.reactivex.rxjava2:rxjava:2.1.16'
下面是java kotlin用法
new RxPermissions(this).request(Manifest.permission.CAMERA)
.subscribe(new Consumer<Boolean>() {
@Override
public void accept(Boolean aBoolean) throws Exception {
if (aBoolean) {
LogUtils.d("Debug","权限通过");
initCamera();
} else {
LogUtils.d("Debug","权限拒绝/多次拒绝 不弹系统弹窗也会走这里");
ToastUtils.showShort("请手动开启相机权限");
//跳转到系统界面
Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
intent.setData(Uri.fromParts("package", getActivity().getPackageName(), null));
startActivity(intent);
}
}
});
RxPermissions(this@checkPermisssion)
.requestEachCombined(Manifest.permission.CAMERA)
.subscribe {
if (it.granted) {
println("权限通过")
} else {
println("权限拒绝/多次拒绝 不弹系统弹窗也会走这里")
ToastUtils.showShort("请手动开启相机权限")
val intent = Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS)
val uri = Uri.fromParts("package", packageName, null)
intent.data = uri
startActivity(intent)
}
}