Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid GPS tracking and WakeLock
    text
    copied!<p>I need to do background GPS tracking on an Android phone, and I'm currently planning on having two scenarios:</p> <ol> <li>When the phone is connected to a (car) charger, get frequent GPS locations (every minute).</li> <li>When the phone is not connected to a charger, only poll for a location once every 5-30 minutes, depending on how much the battery is affected.</li> </ol> <p>I know that I'll need to implement the tracking in a service, and probably show a notification to keep the service alive. However, I gather that the phone might go into sleep mode at any time, which would stop the GPS tracking.</p> <p>For these scenarios, <strong>what is the best way to do continuous background GPS tracking, without the phone going to sleep, and without draining too much power?</strong></p> <p>So far I gathered the following:</p> <p>For scenario 1, I'll probably need a acquire a WakeLock, and keep the CPU awake all the time (but the screen may sleep). The MyTracks application seems to be doing this in <a href="http://code.google.com/p/mytracks/source/browse/MyTracks/src/com/google/android/apps/mytracks/services/TrackRecordingService.java" rel="nofollow noreferrer" title="TrackRecordingService">TrackRecordingService</a>. OpenGPSTracking seems to do <a href="http://code.google.com/p/open-gpstracker/source/browse/trunk/OpenGPSTracker/trunk/application/src/nl/sogeti/android/gpstracker/logger/GPSLoggerService.java" rel="nofollow noreferrer">the same</a>.</p> <p>For scenario 2, I can use AlarmManager to schedule a check every x minutes. My service will need to acquire a temporary WakeLock, wait for a single GPS location, then stop and release the WakeLock again.</p> <p>How would the power usage compare for these two methods (permanent WakeLock vs AlarmManager)? Can the GPS receive an accurate location in a reasonable amount of time when only checking every 30 minutes?</p> <p>There are a few related questions on StackOverflow, but none with satisfying answers. Some semi-useful ones:</p> <ul> <li><a href="https://stackoverflow.com/questions/6291729/how-to-keep-application-running-in-background-keep-collecting-data">how to keep application running in background? keep collecting data?</a> (pointed me to MyTracks)</li> <li><a href="https://stackoverflow.com/questions/7700924/tracking-users-sms-and-geo-position-in-the-background-is-my-idea-working">Tracking user&#39;s sms and geo position in the background - is my idea working?</a></li> <li><a href="https://stackoverflow.com/questions/6934991/android-service-with-always-on-gps">Android service with always on GPS</a></li> </ul>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload