前言
Android 6.0以上动态权限申请框架,方便权限申请
GitHub
https://github.com/tbruyelle/RxPermissions
adding dependencies
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
implementation 'com.github.tbruyelle:rxpermissions:0.10.2'
使用方式单个权限申请
RxPermissions rxPermissions = new RxPermissions(this);
rxPermissions.request(Manifest.permission.CAMERA)
.subscribe(new Observer<Boolean>() {
@Override
public void onSubscribe(Disposable d) {
}
@Override
public void onNext(Boolean aBoolean) {
Log.e("GAO", "onNext-" + aBoolean);
if (aBoolean) {
} else {
}
}
@Override
public void onError(Throwable e) {
}
@Override
public void onComplete() {
}
});
使用方式多个权限申请
rxPermissions.requestEach(Manifest.permission.CAMERA,Manifest.permission.CAMERA).subscribe(new Observer<Permission>() {
@Override
public void onSubscribe(Disposable d) {
}
@Override
public void onNext(Permission permission) {
}
@Override
public void onError(Throwable e) {
}
@Override
public void onComplete() {
}
});