I'm using RxPermissions to handle permissions inside my project.
'com.github.tbruyelle:rxpermissions:0.12'
'io.reactivex.rxjava3:rxjava:3.0.4'
This is my code for handling the CAMERA
permission:
new RxPermissions((FragmentActivity) context).request(Manifest.permission.CAMERA)
.subscribe(granted -> {
if(granted){
Intent packageReceiveIntent = new Intent(context, ReceivePackageActivity.class);
context.startActivity(packageReceiveIntent);
}
});
This gets called onClick
event.
For some reason the code inside the Consumer
is not called after the permission
is granted
and I have to tap on the button twice to open the activity.
I've used the same code in a different part of the application and it works fine, I don't get it why in a Fragment it works fine and in another it doesn't.
I also tried it like this but was unsuccessful:
new RxPermissions(requireActivity()).request(Manifest.permission.CAMERA)
.subscribeOn(Schedulers.newThread())
.observeOn(Schedulers.computation())
.subscribe(aBoolean -> {
if (aBoolean) {
Intent packageReceiveIntent = new Intent(requireActivity(), ReceivePackageActivity.class);
requireActivity().startActivity(packageReceiveIntent);
}
});