LocationManager.NETWORK_PROVIDER does not start onLocationChanged in ICS

Does anyone know what happened to the event-listener for the location changed for the WIFI provider. I saw a lot of questions about this, but did not answer the correct answer.

I am doing everything well and it works for older versions of Android, but now I have upgraded my SAMSUNG GALAXY TAB 10.1 to ICS and it does not work anymore. Perhaps this is a SAMSUNG (or my mobile provider) error when they implemented their interface in ICS ...

I register an eventlistener like this (keep in mind that it works well in pre-release versions of Android, and I also turned on all location services in the settings):

locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, loclistener); //refresh time and distance are to 0 so it should trigger location change event

After this request, I checked if the network provider is turned on and it displays as it is.

code:

 if (locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) { Toast.makeText(this, "NETWORK PROVIDER enabled!", Toast.LENGTH_LONG).show(); } 

If anyone has an idea, please help me ...

+4
source share
4 answers

This is a known issue:

After rebooting the device, the network location provider is working fine, but after a while it stops updating.

https://code.google.com/p/android/issues/detail?id=57707

Unfortunately, no solution.

+4
source

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.

+1
source

I had the same problem with NETWORK_PROVIDER . The reason is that when you request updates, NETWORK_PROVIDER does not create a callback for the onLocationChanged() method. You also need to call getLastKnownLocation(NETWORK_PROVIDER) to start updating the location.

It is strange that for GPS_PROVIDER this is not necessary.

Hope this helps.

+1
source

Ok So now it works for me. This is really weird. I have restarted all my devices and now it is updating. I do not know what happened, and I would really like to know what is the reason for this strange behavior. Thanks @barbeau for all your time and help.

0
source

All Articles