To keep track of how often the network provider updates, I changed the onLocationChanged () method to the following:
public void onLocationChanged(Location location) { dummyText.setText(location.toString() + "\n" + "Elapsed Time (ms): " + (lastTime - location.getTime())); lastTime = location.getTime(); }
And added:
long lastTime = 0;
... as a global variable.
This will print the time between updates in milliseconds (after the first fix - the first fix will just print a negative time value from the first location).
I ran the above code on my Samsung Galaxy S3, and the network provider is updated about every 20 seconds, so the code seems to be fine.
I also ran this on Samsung Dart (with T-mobile but not activated) on WiFi, and the network provider was updated every 45 seconds.
I also ran this on the Samsung Nexus S 4G (from Sprint but not activated) on WiFi, and the network provider was not updated at all at first. Restarting the device seemed to fix the problem, and now updating it approximately every 20 seconds.
Based on your comments and my experience, it seems like this problem varies between OEMs and even between device models of the same OEM. Perhaps this is another feature of the lack of strict enforcement of LocationListener behavior prior to Android Jelly Bean 4.1. Strict adherence to LocationListener behavior only recently started in Android Jelly Bean 4.1, which is mentioned in the Android developer docs here in the first signature of the requestLocationUpdates method:
http://developer.android.com/reference/android/location/LocationManager.html
Prior to Jellybean, the minTime parameter was just a hint, and some provider provider implementations ignored it. Starting with Jellybean and later for Android-compatible devices, it is mandatory to comply with the minTime and minDistance parameters.
In addition, in my experience, the interval for updating NETWORK_PROVIDER location updates on devices that update is quite often fixed for about 20-30 seconds on many different devices. Thus, the minTime parameter that you pass to the locationManager.requestLocationUpdates () method is likely to be ignored.
The need to reboot the device to get the location of the network provider is likely due to a lack of response from the Google server that provides this location information. Not sure why rebooting fixes it.