动态申请权限
RxPermissions permissions = new RxPermissions(this);
boolean isGranted = permissions.isGranted(Manifest.permission.WRITE_EXTERNAL_STORAGE);
RxPermissions permissions = new RxPermissions(this);
Disposable disposable = permissions.request(Manifest.permission.WRITE_EXTERNAL_STORAGE)
.subscribe(new Consumer<Boolean>() {
@Override
public void accept(Boolean granted) throws Exception {
if (granted) {
//权限被允许
} else {
//权限被拒绝
}
}
});
RxPermissions rxPermissions = new RxPermissions(activity);
Disposable disposable = RxView.clicks(findViewById(R.id.tv_temp2))
.compose(rxPermissions.ensure(Manifest.permission.WRITE_EXTERNAL_STORAGE))
.subscribe(new Consumer<Boolean>() {
@Override
public void accept(Boolean granted) throws Exception {
Logger.e(granted + "!");
}
});
- 多个权限:依次申请-同时返回且不知道有没有勾选“禁止后不再询问”
RxPermissions rxPermissions = new RxPermissions(activity);
Disposable disposable = rxPermissions.request(
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.CAMERA,
Manifest.permission.RECORD_AUDIO,
Manifest.permission.READ_PHONE_STATE)
.subscribe(new Consumer<Boolean>() {
@Override
public void accept(Boolean granted) throws Exception {
}
});
RxPermissions rxPermissions = new RxPermissions(activity);
Disposable disposable = rxPermissions.requestEach(
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.CAMERA,
Manifest.permission.RECORD_AUDIO,
Manifest.permission.READ_PHONE_STATE)
.subscribe(new Consumer<Permission>() {
@Override
public void accept(Permission permission) throws Exception {
if (permission.granted) {
//权限被允许
Logger.e(permission.name + " is granted!");
} else if (permission.shouldShowRequestPermissionRationale) {
//权限被拒绝,未勾选“禁止后不再询问”
Logger.e(permission.name + " is denied without ask never again");
} else {
//权限被拒绝,勾选了“禁止后不再询问”
Logger.e(permission.name + " is denied with ask never again");
}
}
});
RxPermissions rxPermissions = new RxPermissions(activity);
Disposable disposable = rxPermissions.requestEachCombined(
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.CAMERA,
Manifest.permission.RECORD_AUDIO,
Manifest.permission.READ_PHONE_STATE)
.subscribe(new Consumer<Permission>() {
@Override
public void accept(Permission permission) throws Exception {
if (permission.granted) {
//所有权限被允许
} else if (permission.shouldShowRequestPermissionRationale) {
//至少一个权限被拒绝,且未勾选“禁止后不再询问”
Logger.e(permission.name + " is denied without ask never again");
} else {
//至少一个权限被拒绝,勾选了“禁止后不再询问”
Logger.e(permission.name + " is denied with ask never again");
}
}
});