RxPermissions
RxPermissions copied to clipboard
repeated subscribe
hello,I find a problem.When I requested permission for twice or more time, the accept call back may execute repeated.For example,when execute the code below:
RxPermissions rxPermissions = new RxPermissions(MainActivity.this);
rxPermissions.request(Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.CAMERA)
.subscribe(new Consumer<Boolean>() {
@Override
public void accept(Boolean aBoolean) throws Exception {
Log.d(TAG, "first request");
}
});
rxPermissions.request(Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.CAMERA)
.subscribe(new Consumer<Boolean>() {
@Override
public void accept(Boolean aBoolean) throws Exception {
Log.d(TAG, "second request");
}
});
I thought the result should be like this: first request second request
but the result is: second request first request second request
The "second request" is printed twice.Then I read the code and find out the problem is caused by the "oneOf(trigger, pending(permissions))",it merge the original trigger and pending ,but when requesting the same permission, the pending will return a non-empty Observable.So I modified code like this:
private Observable<Permission> request(final Observable<?> trigger, final String... permissions) {
if (permissions == null || permissions.length == 0) {
throw new IllegalArgumentException("RxPermissions.request/requestEach requires at least one input permission");
}
return trigger//oneOf(trigger, pending(permissions))
.flatMap(new Function<Object, Observable<Permission>>() {
@Override
public Observable<Permission> apply(Object o) throws Exception {
return requestImplementation(permissions);
}
});
}
and the result become right. So why use “oneOf”?What did it use for? Looking forward to your reply!!
I find the same issue.
@codeCacher @AsiamCn I couldn't reproduce this issue, I tried it out but I'm having the expected behavior
com.tbruyelle.rxpermissions.sample D/RxPermissionsSample: first request
second request
could you please create a demo project where it's reproducible and share it here please?
EDIT: Nvm, I was able to reproduce, I'll fix this soon.
I also encountered this problem, has the library been fixed?
I encountered the same problem
I also cannot understand what the "pending" method means. The result I got is : if request one permission, like camera
first request
second request
second request
if request two or more permissions, like location and camera
second request
first request
second request
@codeCacher @AsiamCn I couldn't reproduce this issue, I tried it out but I'm having the expected behavior
com.tbruyelle.rxpermissions.sample D/RxPermissionsSample: first request second request
could you please create a demo project where it's reproducible and share it here please?
EDIT: Nvm, I was able to reproduce, I'll fix this soon.
can you explan what "pending" method means, please? I am very confused.