I’m testing my Android app on a device, and it always fails when I use
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);
currentLocation = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
However, if I use NETWORK_PROVIDER instead of GPS_PROVIDER, it works. The currentLocation returns null.
How can I handle this? Is there anything specific I need to put in my locationListener?
Thanks!
GPS_PROVIDER may not work in bounded place, suppose inside a house or something like this. You should program it in such a way that if gps provider gives null location then you use network provider as a alternative although its accuracy is not so high.
Here there is another issue. Your code should be as follows: