According to this article (UPD: link removed as it leads to some crap now), setting the minTime when requesting location updates will cause the provider to set itself to TEMPORARILY_UNAVAILABLE for minTime milliseconds in order to conserve battery power. During this period of inactivity, the GPS provider will turn itself off and the GPS icon will disappear.
In my code, I set the minTime to about 30 seconds, but the provider only becomes TEMPORARILY_UNAVAILABLE once every five minutes. When it does, it only stays TEMPORARILY_UNAVAILABLE for ten seconds at most before turning itself back on. I know this because the GPS icon disappears for only ten seconds before reappearing again.
I understand that the minTime setting is only a rough guideline for the Android location provider...but I'm pretty sure that five minutes is entirely different from 30 seconds. Does anyone know what is going on here? How does minTime and requestLocationUpdates actually work?
LocationManager Setup:
locManager = (LocationManager) getSystemService(LOCATION_SERVICE); locManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,30000L, 0, locListener);
locListener:
public void onLocationChanged(Location loc) {
//Keep track of best location
//Having a location > no location
if (bestLocation == null)
bestLocation = loc;
//More accuracy > Less accuracy
else if (loc.getAccuracy() <= bestLocation.getAccuracy())
bestLocation = loc;
Log.d(TAG, "Location Updated";
}
public void onStatusChanged(String provider, int status, Bundle extras) {
Log.d(TAG, "New status: " + status);
if (status== LocationProvider.TEMPORARILY_UNAVAILABLE)
//Do stuff since the provider is temporarily off
}
Debug output on a real Android device (HTC Incredible 2.2):
Location Updated
Location Updated
New status: 2
Location Updated
Location Updated
Location Updated
New status: 2
... (five minutes later)
New status: 1