Hi again Igor, Thanks for your excellent suggestions, I will work on it over the next couple of days.
As another curiosity, I am experiencing a very small number of cases where LocationManager.getProvider(LocationManager.NETWORK_PROVIDER) returns null. Apparently some phones do not have this capability. Best, Michael. On Nov 30, 7:57 pm, ip332 <iprile...@gmail.com> wrote: > One more thing: check how and when do you remove listener. > > On Nov 30, 11:52 am, ip332 <iprile...@gmail.com> wrote: > > > > > Michael > > > Here are some suggestions: > > 1. Additional logging: mCoarseLocationListener details, WiFi status, > > cell signal status (may be in those 5% cases users don't have any > > signal?) > > 2. Get details from users about phone models, running applications and > > Android versions. Recently I found interesting "feature" on Motorola > > phone: sensors do not report events unless the values have been > > changed - this is a violation of the Android API. May be somewhat > > similar happens with respect to the network location on some phones. > > 3. Add "listener restart" logic after a certain timeout, i.e. if you > > didn't get onLocationChanged() after a certain time stop the listener, > > create and start it again. > > 4. Get Android source code and study the LocationManager hierarchy. > > Probably the most complicated approach but I would start from here. > > > Best regards > > Igor > > > On Nov 30, 3:07 am, michael <michael.d.peder...@googlemail.com> wrote: > > > > Hi Igor, > > > > Thanks for your reply, it is much appreciated. Thanks also for > > > pointing out the issues with the code I provided. However, this was > > > merely a stripped-down outline of what I am doing. The use of > > > mCoarseLocationListener is a type from the strip-down process, and I > > > agree that the LocationProvider variable is not necessary. > > > > However, the problem remains that while the code works fine in 95% of > > > cases, there are still 5% of cases where I never get a call to > > > onLocationChanged. Any suggestions as to why this is the case would > > > still be much appreciated. > > > > Best, > > > Michael. > > > > On Nov 30, 12:29 am, ip332 <iprile...@gmail.com> wrote: > > > > > Michael, > > > > > According to Android documentation the following call > > > > locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, > > > > 0, 0, this); > > > > requests updates from WiFi or cellular network which means you should > > > > get some update (from cell tower) even if WiFi location is not > > > > available. However, I've seen cases when Google map application failed > > > > to set map to "MyLocation" for several minutes while driving on a > > > > freeway. > > > > > Back to your code. I think you need to replace > > > > getLastKnownLocation(mCoarseLocationProvider) with > > > > getLastKnownLocation(LocationManager.NETWORK_PROVIDER) - it is not > > > > clear where do you get mCoarseLocationProvider. > > > > Also you don't need to use LocationProvider variable in your code > > > > fragment: > > > > public MyLocationListener() { > > > > mLocMan = > > > > (LocationManager)getSystemService(Context.LOCATION_SERVICE); > > > > > if > > > > (mLocMan.getLastKnownLocation(LocationManager.NETWORK_PROVIDER) != > > > > null) { > > > > mCurrentLocation = > > > > mLocMan.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); > > > > } > > > > > > > > > mLocMan.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, > > > > this); > > > > } > > > > > Check the following link which has a lot of useful > > > > suggestions:http://developer.android.com/guide/topics/location/obtaining-user-loc... > > > > > Bets regards > > > > Igor > > > > > On Nov 29, 2:44 pm, michael <michael.d.peder...@googlemail.com> wrote: > > > > > > Let me also add that the location listener does sometimes get calls to > > > > > onProviderEnabled -- this happens after asking the user to enable > > > > > wireless network locations if initially disabled. So I know for sure > > > > > that the listener is registered correctly. It just never gets an > > > > > onLocationChanged call. > > > > > > /Michael. > > > > > > On Nov 29, 10:10 pm, michael <michael.d.peder...@googlemail.com> > > > > > wrote: > > > > > > > Hi folks, > > > > > > > I have a location listener running in a foreground service. The > > > > > > listener registers for wireless network updates in its constructor. > > > > > > In > > > > > > the majority of cases, location updates are received as expected. > > > > > > > However, log entries from the live app show that for about 5% of my > > > > > > users, location updates are never received even though wireless > > > > > > network location is enabled on the phone (I check this through the > > > > > > LocationManager.isProviderEnabled method). That is, > > > > > > onLocationChanged > > > > > > is never called, at least not within say 20 minutes of registering > > > > > > the > > > > > > listener. > > > > > > > Does anybody have any idea why this might be? Are there cases, or > > > > > > certain geographic areas, where you would not expect wireless > > > > > > locations to be available? > > > > > > > A stripped-down outline of the location listener code is shown > > > > > > below: > > > > > > > class MyLocationListener extends LocationListener { > > > > > > private Location mLocation = null; > > > > > > > public MyLocationListener() { > > > > > > mLocMan = (LocationManager) > > > > > > getSystemService(Context.LOCATION_SERVICE); > > > > > > > if (mLocMan.getLastKnownLocation(mCoarseLocationProvider) != > > > > > > null) { > > > > > > mCurrentLocation = > > > > > > mLocMan.getLastKnownLocation(mCoarseLocationProvider); > > > > > > } > > > > > > > LocationProvider lp = > > > > > > mLocMan.getProvider(LocationManager.NETWORK_PROVIDER); > > > > > > mLocMan.requestLocationUpdates(lp.getName(), 0, 0, this); > > > > > > } > > > > > > > public void onLocationChanged(Location loc) { > > > > > > mLocation = loc; > > > > > > } > > > > > > > } > > > > > > > I verify through flurry logs that the "network" location provider is > > > > > > indeed obtained and enabled, and that mLocation == null after about > > > > > > 20 > > > > > > minutes. > > > > > > > Any suggestions would be enormously appreciated. I am running out of > > > > > > ideas for how to fix this, and I cannot replicate the issue on my > > > > > > own > > > > > > test devices. > > > > > > > Cheers, > > > > > > Michael.- Hide quoted text - > > > > > - Show quoted text - -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en