I have the following code that crashes due to the Criteria being null.
For some reason the String best is null. Any ideas why?
private void startGPS() {
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE);
criteria.setPowerRequirement(Criteria.NO_REQUIREMENT);
String best = locationManager.getBestProvider(criteria, true);
Log.v(DEBUG_TAG, "Best provider: " + best);
locationManager.requestLocationUpdates(best, 50, 0, this);
}
getBestProvider(criteria, true)will only return enabled providers. Since you requestCriteria.ACCURACY_FINEyou should get GPS, but if it is not enabled you’ll getnull.