Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keeping a GPS service alive and optimizing battery life

Tags:

android

gps

I must build an application with a GPS tracker running during about a day. I'm aware of similar questions in SO but I haven't found any answers to some questions I have.

-I need a GPS fix every 10 min, so I think the best way to do it is to start the location service, get a fix (or timeout) and stop the service (with removeUpdates()). How can I have an application (or service or whatever) running this cycle every 10min and be sure it will continue as long as there is some battery left (even if device goes to sleep, it should wake it up every 10min to get a fix)? Is using AlarmManager a good idea?

-Can I expect the battery to last one day with this method?

I've checked mytracks but the gps listener seems always on and the battery is expected to last no more than 5h.

I've also checked CWAC Location Poller but it does only removeUpdates() on timeout and restart the listener immediately. It also uses a wakelock while in my case I think an AlarmManager could be a better idea.

Any help/suggestion welcome

like image 599
jul Avatar asked Oct 24 '11 08:10

jul


People also ask

Does location services affect battery life?

When you try searching for a location, say on your Maps app, the GPS module will be accessed to pull data and cross reference it with Internet sources. At a high rate of tracking and constant refreshing – without going to sleep, the phone uses more of its power. The eventual result is your battery bar cutting low.

Does keeping GPS on drain battery?

Location mode under your phone's Settings menu includes three options- High accuracy, Battery saving and Device only. The first option uses GPS, Wi-Fi, Bluetooth or mobile networks to give you the most accurate location but it causes heavy battery drainage as well.

Does GPS consume a lot of battery?

GPS is expensive because it is a very slow communication channel—you need to communicate with three or four satellites for an extended duration at 50 bits per second ... Mobile devices such as Android and the iPhone achieve their battery life largely because they can aggressively and quickly enter into and exit from ...


1 Answers

You are spot on with alarm manager I use

    Intent serviceIntent = new Intent(this, TrackerService.class);
    mPendingIntent = PendingIntent.getService(this, 0, serviceIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);

    alarmManager.cancel(mPendingIntent);
    alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP,
                System.currentTimeMillis(), interval, mPendingIntent);

in a similar app for getting network location

interval is ms between starting the service

the service starts up, gets the location and closes

this was MUCH more battery efficient that hanging around with an active service waiting for reports

that code i posted cancels the previous alarms first so you don't get more than 1 :)

like image 72
dten Avatar answered Sep 20 '22 01:09

dten