Skip to content

Instantly share code, notes, and snippets.

@c4software
Created July 31, 2018 12:02
Show Gist options
  • Save c4software/69d0342281f42d3b76f81efca3935620 to your computer and use it in GitHub Desktop.
Save c4software/69d0342281f42d3b76f81efca3935620 to your computer and use it in GitHub Desktop.
Test if user have enabled the Android Location Service.
private boolean locationServiceEnabled() {
final LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
if (locationManager != null) {
try {
return locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER) ||
locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
} catch (final Exception e) {
Timber.e(e);
return false;
}
} else {
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment