Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android : location api asking for wifi

This is weird. I mean, I have strong network, and GPS is turned On, still it asks for Wifi !!

I'm using new Location Api with class FusedLocationProviderClient.

This is how I am checking if Location Settings are enabled or not:

private void checkIfLocationSettingsAreEnabled() {
    LocationRequest locationRequest = new LocationRequest();
    locationRequest.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY);
    locationRequest.setInterval(10000);
    locationRequest.setFastestInterval(5000);

    LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder();
    builder.addLocationRequest(locationRequest);
    builder.setAlwaysShow(true);

    SettingsClient client = LocationServices.getSettingsClient(context);
    Task<LocationSettingsResponse> locationSettingsResponseTask = client.checkLocationSettings(builder.build());
    locationSettingsResponseTask.addOnSuccessListener(locationSettingsResponse -> {
        getLastKnownLocation();
    });
    locationSettingsResponseTask.addOnFailureListener(e -> {
        if (e instanceof ResolvableApiException) {
            myLocationListener.onResolutionNeeded(e);
        } else {
            myLocationListener.onLocationFailure(e);
        }
    });
}

With the above code, I am able to get below image:

enter image description here

But then, after clicking OK, again I make call to checkIfSettingsAreEnabled() this shows another popup as below:

enter image description here

I wonder why enabling Wifi is mandatory, even if I am on desert safari, where there is no Wifi to connect to !!

Is there any way to Skip this Wifi option, and work as normal as Google Maps does ?

In fact, Google Maps uses priority PRIORITY_HIGH_ACCURACY and still once, the first settings dialog has been shown, it doesn't ask second time to turn on Wifi.

like image 716
Chintan Soni Avatar asked Jan 31 '18 05:01

Chintan Soni


1 Answers

FusedLocationProvider uses a combo of GPS and WIFI to get your location. Especially when asking for balanced mode, it needs both or won't work (GPS takes power, so it won't rely just on it for balanced). Try max accuracy, its less likely to use it then. Or just use the GPS provider if you actually want GPS.

like image 84
Gabe Sechan Avatar answered Oct 20 '22 10:10

Gabe Sechan