This is the way I listen for GPS location updates (using LocationManager
and a LocationListener
):
locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
listener = new MyLocationistener(); // LocationListener
locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER,
30000, // milliseconds (minTime)
20, // meters (minDistance)
listener );
But I would like to dynamically adjust the minTime
and minDistance
arguments used by LocationManager#requestLocationUpdates
. My aim is to save battery, according to several usage policies, i.e.:
I would like to know:
LocationManager#removeUpdates
and LocationManager#requestLocationUpdates
again, if there is the only alternative.Edit: The application is a tracking system to know where people are, in order to assign tasks to the person nearest to a given poing. Actually battery hardly lasts 8 hours, so I'd like to increase it.
AFAIK you need to call removeUpdates
and requestLocationUpdates
again.
Also, you can look into other ways to see if the phone is moving at all, like the accelerometer. Read about it here and see this other question's answers
But To give you more ideas, you need to present the problem itself. Don't try to optimize too early, until you don't have a problem. If you have you need to post details about it.
Is this really a good idea to save battery life ?
Probably not. AFAIK, the GPS radio will be on the whole time, and that is the biggest battery drain in what you're describing. The way to save battery is to remove updates, so the GPS radio shuts off. However, the next time you request location updates, it will take some time for GPS to acquire its initial fix.
If the user is indoors (no GPS coverage), increase both
If you cannot get a GPS fix, turn the radio off, and try again some number of minutes later (or based on a UI event or something). There is no sense leaving the GPS on if it is not doing you any good.
If the battery is too low, increase both
If the battery is too low, turn off GPS. Either switch to a low-power provider (use Criteria
to find one) or go without location data. Let the user decide what is "too low" via a preference.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With