Fused Location Provider: Is there a way to check if a location update failed? Fused Location Provider: Is there a way to check if a location update failed? android android

Fused Location Provider: Is there a way to check if a location update failed?


After digging around the API a little more and doing some tests, I found a solution to my problem which seems to be working.

 LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, locationRequest, new LocationCallback() {            @Override            public void onLocationResult(LocationResult result) {                DebugUtils.log("onLocationResult");            }            @Override            public void onLocationAvailability(LocationAvailability locationAvailability) {                DebugUtils.log("onLocationAvailability: isLocationAvailable =  " + locationAvailability.isLocationAvailable());            }        }, null);

Instead of using LocationListener. I used LocationCallback

onLocationResult is only called to provide the latest Location result based on the LocationRequest. It is not called if a location could not be provided and during my tests it is not when Location was disabled and GPS was used indoors etc. Please call result.getLastLocation() to get the actual location object.

onLocationAvailablity is always called. locationAvailability.isLocationAvailable() Returns true if the device location is known and reasonably up to date within the hints requested by the active LocationRequests. False is returned when failure to determine location may from a number of causes including disabled location settings or an inability to retrieve sensor data in the device's environment.

I have tested with no location services, GPS only while indoors. In each case I removed all existing location history (to prevent cached locations). An accurate up-to-date location was always returned.

Could others vouch for this?

Note: The last parameter for the requestLocationUpdates call is a looper. Passing in null means it will use the calling thread's message queue.