settings().checkAndHandleResolution(..) return true regardless of setting
tonyc10 opened this issue · 2 comments
Hi,
I'm calling rxLocation.settings().checkAndHandleResolution(locationRequest) from my device with my location permission for my app switched off in settings. I'm getting back a result of true, which I thought would indicate I had the proper permissions.
My app then calls rxLocation.location().updates(), which throws a SecurityException ("Client must have ACCESS_FINE_LOCATION permission to request PRIORITY_HIGH_ACCURACY locations.")
I would expect #checkAndHandleResolution to put up a permission dialog in that instance, and to not return true in any event.
Here is what my code looks like:
LocationRequest continuousHighAccuracyRequest = LocationRequest.create()
.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY)
.setInterval(5000);
public Observable<Location> continuousHighAccuracyUpdates() {
return rxLocation.settings().checkAndHandleResolution(continuousHighAccuracyRequest)
.flatMapObservable(this::startUpdatesWithPermissionOtherwiseOnError);
}
private Observable<Location> startUpdatesWithPermissionOtherwiseOnError(
@NonNull Boolean hasPermission) throws Exception {
if (hasPermission) {
//noinspection MissingPermission
return rxLocation.location().updates(continuousHighAccuracyRequest);
} else {
// Permission not granted by user so throw exception (onError)
throw new LocationSettingsNotSatisfiedException();
}
}
Any ideas?
checkAndHandleResolution()
only handles the location settings call (and – if needed – showing the resolution dialog). It is never stated that it also handles permission checks. See the readme:
Make sure to have the Location and Activity Recognition permissions from Marshmallow on, if they are needed by your API requests.
Checking the location settings is simplified with this library, by providing a Single via rxLocation.settings().checkAndHandleResolution(locationRequest), which handles showing the resolution dialog if the location settings do not satisfy your request.
Permissions are not the focus of this library, but you can take a look at RxPermissions for this use case.
Thank you -- I see that I was confusing Settings and App Permissions.