MultiplePermissionsListener REQUEST_ONGOING
andro-jedi opened this issue ยท 20 comments
Expected behaviour
Call onPermissionsChecked with already granted permissions
Actual behaviour
when I ask for permissions it call onError(DexterError error) with REQUEST_ONGOING error
Activity was closed and opened several times using startActivityForResult setResult(OK) or CANCEL before this happened.
Steps to reproduce
Dexter.withActivity(getActivity())
.withPermissions(
Manifest.permission.CAMERA,
Manifest.permission.READ_EXTERNAL_STORAGE
).withListener(new MultiplePermissionsListener() {
@Override
public void onPermissionsChecked(MultiplePermissionsReport report) {
if (report.areAllPermissionsGranted()) {
openCamera();
} else {
requestMultiplePermissions();
}
}
@Override
public void onPermissionRationaleShouldBeShown(List<PermissionRequest> permissions, PermissionToken token) {
token.continuePermissionRequest();
}
}).withErrorListener(new PermissionRequestErrorListener() {
@Override
public void onError(DexterError error) {
int y = 0;
}
}).check();
Version of the library
3.0.0
Hi @PingForward
I'm wondering, are you following the README section about screen rotations? When the requesting activity dies due to a rotation or any other reason, we have to rebind the permission listeners by calling continueRequestingPendingPermissions
instead of asking for those permissions again.
Got to say though that you are not the first person having this issue so we will probably need to do a smarter checking when requesting the same permissions more than once.
Hope that link helps, let us know if you still have problems with the library.
Hi, I also have this issue with PermissionListener. My activity open and close normally, without any rotation or other reason to kill the activity unexpectly, several times later, this exception happens.
Version is 3.0.0
@Serchinastico No rotation, regular open close.
I can confirm. Also happens with PermissionListener
(not Multiple* that is). Can't reproduce consistently, but most of the times when I start a permission request and deny it and then close the app (back-button, not simple pause/resume) and come back, it says REQUEST_ONGOING
. Tested with/without rationale dialog and with/without continueRequestingPendingPermissions
. It only seems to start working again once I kill the app process entirely.
The reason is when we create Dexter instance, the Context in DexterInstance become null.
I have sent a pull request.
We've got the same bug. Please, review this pull request.
Fixed in the PR #108. We are about to publish a new version :) Thanks everyone for your help!
Hi guys!
This problem can still be encountered in version 4.1.0.
@ovitrif we can't reproduce it. Could you create a sample project public on github with the code needed to reproduce it?
@pedrovgs
Unfortunately not, it is for a complete application that it happens.
I can give a few details.
I'm using the multiplePermissions listener, using dagger, so I initialize dexter in the module.
The app has language changing capabilities, and the bug was usually seen in that case.
It failed when trying to get information about location permissions.
Basically, we had a screen which asks for GPS coordinates to order a list of items based on their distance to the user.
It was very difficult to reproduce the bug, but it seemed to appear randomly and the testers (not surprisingly) saw it quite often.
I was able one time to reproduce the issue, and had the debugger attached. Not sure if it was the REQUEST_ONGOING
issue, but the code did stop at doing the .check()
method.
No breakpoint was hit afterwards, and I had breakpoints in both methods of the multiple permissions listener.
In the end I fixed the issue by adding an error listener, where I run the code to check the permissions manually using Android code.
Having discussed this with my colleague, we wanted initially to check the permissions manually first, and only when they are not granted would we use Dexter.
I wonder why you guys stop in case of REQUEST_ONGOING
always.
I can't say I know the code very well, but so far I didn't think of an error when doing it manually.
The problem with your approach, I think, is that you do all the complex code to ensure the user is asked to grant permissions.
But most of the time, the app will have the permissions granted, and by doing things the way they are now done in dexter, is like letting a door open for errors.
Could the logic be switched around, and check permissions first, if ok just go on?
Otherwise I find dexter unreliable, since I'll always have to wrap it with my own implementation for checking permissions.
I'm not sure it is intended to be used like that, but I would find it very useful if it was always reliable and you could just do the normal check for permissions before, for example, trying to get the user location.
Guys! same problem in version 5 also. How to fix once we get this
I'm getting the same issue here with the version 5.0.0
I'm getting the same issue here with the version 6.0.0
com.karumi:dexter:6.0.0
Dexter.withActivity(this@MainActivity)
.withPermissions(
Manifest.permission.ACCESS_COARSE_LOCATION
,Manifest.permission.ACCESS_FINE_LOCATION)
.withListener(object:MultiplePermissionsListener{
override fun onPermissionsChecked(report: MultiplePermissionsReport?) {
report?.let {
if(report.areAllPermissionsGranted()){
searchBar.show()
replaceScreen(Screen.MAP)
}
}
}
override fun onPermissionRationaleShouldBeShown(
permissions: MutableList<PermissionRequest>?,
token: PermissionToken?
) {
}
})
.withErrorListener {
println(it.name)
}
.check()
Devices: Nokia
OS: 9.0 - P
Hi @chihung93 we can't reproduce it. Could you create a sample project public on github with the code needed to reproduce it?
Good morning @pedrovgs
This is my beta library.
https://github.com/chihung93/Space-Navigation-V2
You can download it and try to these step :
Step 1: Click on Centre button => Popup request permission show up
Step 2: Click Deny
Step 3: Tap on the Centre button 2- 3 times again.
Step 4: see the Toast Request_ongoing
Ok, I know what's going on. It's a wrongly configured listener what we have here and a missing documentation part from our side. I'm going to update the project readme with some information about this scenario and explain here what's going on.
If you don't configure the token you receive onPermissionRationaleShouldBeShown
properly Dexter will not let you ask for the permission again because the library understands you are showing your own rationale and you don't want to show the OS one again. This is why you have to modify your code to do the following:
spaceNavigationView.setSpaceOnClickListener(object : SpaceOnClickListener {
override fun onCentreButtonClick() {
Dexter.withActivity(this@MainActivity)
.withPermissions(
Manifest.permission.ACCESS_COARSE_LOCATION
,Manifest.permission.ACCESS_FINE_LOCATION)
.withListener(object: MultiplePermissionsListener {
override fun onPermissionsChecked(report: MultiplePermissionsReport?) {
report?.let {
if(report.areAllPermissionsGranted()){
toast("OK")
}
}
}
override fun onPermissionRationaleShouldBeShown(
permissions: MutableList<PermissionRequest>?,
token: PermissionToken?
) {
token?.continuePermissionRequest()
}
})
.withErrorListener {
toast(it.name)
}
.check()
}
override fun onItemClick(itemIndex: Int, itemName: String) {
toast("${itemIndex} ${itemName}")
}
override fun onItemReselected(itemIndex: Int, itemName: String) {
}
})
Look closer here:
override fun onPermissionRationaleShouldBeShown(
permissions: MutableList<PermissionRequest>?,
token: PermissionToken?
) {
token?.continuePermissionRequest()
}
token?.continuePermissionRequest()
is the key to use Dexter properly.
@chihung93, can you please check this out?
This thing took my 4 hours, update it there asap for saving time of others..
OK great, work like a charm :)))
Good work!
if any previous activity is open and dialog is still showing at that time error will occcured