You can determine if any providers are available with LocationManager, but can it be done with the google play services location api?
When nothing is enabled, in fac
I've combed the docs and also haven't found any way to use LocationClient to detect if location services are enabled. onConnected, onDisconnected, and onConnectionFailed do not seem to be linked to whether Location Services are enabled or not.
I'm currently doing location requests using LocationClient, but using the old locationManager.isProviderEnabled(String provider)
method to detect if the Location Services are enabled. This is optimal for me, as, even if LocationClient did provide a way, it makes no distinction between GPS and Network and I'd really like to be able to request that the user enable GPS.
if (!manager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
//GPS Provider disabled
return false;
}
Google Play Services 7.0 introduced a Settins Api where you can ask for location settings you need and then query if are enabled or ask the user to enable them.
There is now a reliable way to detect if location updates are available since Google Play Services 7.3.0:
Implement and register a LocationCallback and override onLocationAvailability() or call LocationServices.FusedLocationApi.getLocationAvailability() to retrieve the availability status. If it's false, then you known the location updates aren't going to be delivered unless something changes in the device configuration.
This method is actually quite smart: for example it is able to determine that no location updates are going to be delivered on a WiFi-only device if WiFi is disabled or device is in airplane mode, even if the Network location provider is always enabled.
This works for me. Tested on an Amazon tablet device vs a Samsung s7
if (GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(context) == ConnectionResult.SUCCESS) {
//Google Play services are available
} else {
//Google Play services are not available on this device
}