Get Location (coordinates) Periodically Without Dramatically Increase Battery Consumption
Solution 1:
If you are worried about battery and not so stricted on the 10 minutes interval you could try to use PassiveProvider instead of GPS/Coarse. Usually other applications request locations often enough so you don't need to worry about it. If you are strict, than you could try to ask for location yourself in case one hasn't received in the past interval. Here is an example for using the Passive Provider.
LocationManager locationManager = (LocationManager) this
.getSystemService(Context.LOCATION_SERVICE);
LocationListener locationListener = newLocationListener() {
@OverridepublicvoidonStatusChanged(String provider, int status, Bundle extras) {}
@OverridepublicvoidonProviderEnabled(String provider) {}
@OverridepublicvoidonProviderDisabled(String provider) {}
@OverridepublicvoidonLocationChanged(Location location) {
// Do work with new location. Implementation of this method will be covered later.doWorkWithNewLocation(location);
}
};
long minTime = 10*60*1000;
long minDistance = 0;
locationManager.requestLocationUpdates(LocationManager.PASSIVE_PROVIDER, minTime, minDistance, locationListener);
Solution 2:
Play Services has a Low Consumption location API. You can found more info in Android Developer Site
UPDATE
Here you can found a example of Play Location Service stored in Github. Look the LocationUpdates example.
When you setup you Location Request you can change the priority, see more info here. I think that you use PRIORITY_BALANCED_POWER_ACCURACY
Post a Comment for "Get Location (coordinates) Periodically Without Dramatically Increase Battery Consumption"