1

I have these two lines of code ready to be used in the section of my app where the user's location is requested:

locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 5000, 0, locationListener);

locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 5000, 0, locationListener);

The problem is that, when testing in real device, I have noticed that, using GPS_provider does not work very well when being in certain places like inside of a building....the app is stuck waiting to acquire GPS coordinates which take a lot of time or just never come unless I have open-sky conditions.

The question would be: how do I do to still use GPS_providerby default but, if gps coordinates take more than XXXX seconds to be acquired, then switch to Network_providerand acquire position from Network.

Small edit: is it maybe any way to check GPS signal strength before using GPS or Network provider?

codeKiller
  • 5,493
  • 17
  • 60
  • 115

1 Answers1

1

LocationListener has a function onStatusChanged(). You have to override this function to check GPS_PROVIDER's status and accordingly take necessary action , which in your case is switching to NETWORK_PROVIDER.

Hope this answers your query

Ayush Bansal
  • 702
  • 1
  • 7
  • 17
  • thanks for your answer, still need to figure out how to switch provider after GPS has been trying to acquire position for XXX seconds....maybe the best would be use `getBestProvider`and add a `Criteria`with a `speed`requirement?? – codeKiller May 08 '17 at 07:40