codeKiller
codeKiller

Reputation: 5739

Android: locationManager GPS_provider VS Network_provider

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?

Upvotes: 1

Views: 4770

Answers (1)

Ayush Bansal
Ayush Bansal

Reputation: 722

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

Upvotes: 1

Related Questions