Solution: you can use GPS instead of choosing the best provider by selecting criteria.
Example, Replace:
locationManager.requestLocationUpdates(provider, 400, 1, this);
WITH
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 400, 1, this);
Explaination:
Depending on the use case of your application, you need to choose a provider of a specific location i.e. LocationManager.GPS_PROVIDER or LocationManager.NETWORK_PROVIDER
Alternatively, you can provide some input criteria, such as accuracy, power consumption, cash costs, etc., and let Android decide the nearest location matching provider.
// Retrieve a list of location providers that have fine accuracy, no monetary cost, etc Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_FINE); criteria.setCostAllowed(false); String providerName = locManager.getBestProvider(criteria, true); //and then you can make location update request with selected best provider locationManager.requestLocationUpdates(provider, 400, 1, this);
See how to use locationmanager , how to do, specify criteria and how getBestProvider method works for reference
source share