Skip to content

Instantly share code, notes, and snippets.

@guptasanchit90
Created November 22, 2015 09:49
Show Gist options
  • Save guptasanchit90/9eeaa1c09b2a5e651929 to your computer and use it in GitHub Desktop.
Save guptasanchit90/9eeaa1c09b2a5e651929 to your computer and use it in GitHub Desktop.
Check location enabled or not
public class LocationHelper{
public static boolean isLocationEnabled(Context context) {
LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
// Check GPS status
boolean isGPSEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
// Check network status
boolean isNetworkEnabled = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
if (!isGPSEnabled && !isNetworkEnabled) {
return false;
}
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment