Skip to content

Instantly share code, notes, and snippets.

@massimilianochiodi
Created April 15, 2022 09:01
Show Gist options
  • Save massimilianochiodi/45e3a88036ac668306aa2dc97d086d26 to your computer and use it in GitHub Desktop.
Save massimilianochiodi/45e3a88036ac668306aa2dc97d086d26 to your computer and use it in GitHub Desktop.
Location Service is active (java)
private boolean localizzazioneattiva(Context context) {
LocationManager lm;
boolean gpsEnabled;
boolean networkEnabled;
lm = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
try {
gpsEnabled = lm.isProviderEnabled(LocationManager.GPS_PROVIDER);
} catch (Exception ex) {
return false;
}
try {
networkEnabled = lm
.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
} catch (Exception ex) {
return false;
}
return gpsEnabled || networkEnabled;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment