I'm developing an Android application; this App needs to send periodically (every 10 minutes) the current position (coordenates) to a web service. But ... I'm a little confused about the more correct way (and friendlier to the device battery) to do that.
I read this answer and her method _getLocation()
looks well; but I don't know whether that method could get the availability of the location I need; total availability...
I would like, if the location is not available using GSM / WIFI, application choose the GPS method.
Is that what makes this method?
private void _getLocation() {
// Get the location manager
LocationManager locationManager = (LocationManager)
getSystemService(LOCATION_SERVICE);
Criteria criteria = new Criteria();
String bestProvider = locationManager.getBestProvider(criteria, false);
Location location = locationManager.getLastKnownLocation(bestProvider);
try {
lat = location.getLatitude();
lon = location.getLongitude();
} catch (NullPointerException e) {
lat = -1.0;
lon = -1.0;
}
}
Anybody know one way to get the coordinates of the device periodically... without dramatically increase battery consumption?