Skip to content

Instantly share code, notes, and snippets.

@danikx
Last active September 5, 2017 10:25
Show Gist options
  • Save danikx/f4d1e8c9975e3a7f3a926ee477bc3ab7 to your computer and use it in GitHub Desktop.
Save danikx/f4d1e8c9975e3a7f3a926ee477bc3ab7 to your computer and use it in GitHub Desktop.
android check gps enabled (method 2)
public static boolean isGpsEnabled(){
LocationManager lm = (LocationManager)context.getSystemService(Context.LOCATION_SERVICE);
boolean gps_enabled = false;
boolean network_enabled = false;
try {
gps_enabled = lm.isProviderEnabled(LocationManager.GPS_PROVIDER);
} catch(Exception ex) {}
try {
network_enabled = lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
} catch(Exception ex) {}
return gps_enabled;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment