Solution:
you can use GPS
instead of selecting best provider by deciding criteria.
Example, Replace:
locationManager.requestLocationUpdates(provider, 400, 1, this);
With:
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 400, 1, this);
Explaination:
Depending on your application's use case, you have to choose a specific location provider
i.e. LocationManager.GPS_PROVIDER
or LocationManager.NETWORK_PROVIDER
Alternatively, you can provide some input criteria such as accuracy, power requirement, monetary cost, and so on, and let Android decide a closest match location 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);
Have a look at how to use locationmanager , how to specify Criteria and how getBestProvider method works for reference