Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@talut
Created April 16, 2018 13:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save talut/96dc1c274a7bca41c92a99b84af8f12b to your computer and use it in GitHub Desktop.
Save talut/96dc1c274a7bca41c92a99b84af8f12b to your computer and use it in GitHub Desktop.
Android provider criteria
/**
* Get provider name.
* @return Name of best suiting provider.
* */
String getProviderName() {
LocationManager locationManager = (LocationManager) this
.getSystemService(Context.LOCATION_SERVICE);
Criteria criteria = new Criteria();
criteria.setPowerRequirement(Criteria.POWER_LOW); // Chose your desired power consumption level.
criteria.setAccuracy(Criteria.ACCURACY_FINE); // Choose your accuracy requirement.
criteria.setSpeedRequired(true); // Chose if speed for first location fix is required.
criteria.setAltitudeRequired(false); // Choose if you use altitude.
criteria.setBearingRequired(false); // Choose if you use bearing.
criteria.setCostAllowed(false); // Choose if this provider can waste money :-)
// Provide your criteria and flag enabledOnly that tells
// LocationManager only to return active providers.
return locationManager.getBestProvider(criteria, true);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment