Der getBestProvider von LocationManager gibt null zurück
Ich habe eine Menge Leute, die einen Fehler melden, den ich nicht reproduzieren kann. Beim Versuch, eineMapView
es wird berichtet, dass diegetBestProvider
gibt null zurück und ich weiß, dass dies bedeutet, dass kein Anbieter gefunden wird, der meine Kriterien erfülltACCURACY_COARSE
Wenn es also kein GPS gibt, sollte es auch auf dieses zurückgreifennetwork or passive
Auf diesen Benutzergeräten ist dies jedoch offensichtlich nicht der Fall. Was würde das auch bedeuten, wenn GPS ausgeschaltet ist und keine Netzwerkverbindung besteht?
Ich habe versucht, das GPS auszuschalten und das Telefon in den Flugzeugmodus zu versetzen, um das Problem zu reproduzieren. Trotzdem konnte ich die Kartenansicht ohne Kraftaufwand öffnen, sodass ich nicht weiß, wie ich mit diesem Problem umgehen soll.
locationManager = (LocationManager) this.getSystemService(LOCATION_SERVICE);
geocoder = new Geocoder(this);
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_COARSE);
List<String> lProviders = locationManager.getProviders(false);
for(int i=0; i<lProviders.size(); i++){
Log.d("LocationActivity", lProviders.get(i));
}
String provider = locationManager.getBestProvider(criteria, true); // null
long minTime = 60000;
float minDistance = 5;
locationManager.requestLocationUpdates(provider, minTime, minDistance, this);
Error
java.lang.RuntimeException: Unable to start activity ComponentInfo{ecm2.android/ecm2.android.LocationActivity}:
java.lang.IllegalArgumentException: provider==null
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
at android.app.ActivityThread.access$2300(ActivityThread.java:125)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4627)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.IllegalArgumentException: provider==null
at android.location.LocationManager.requestLocationUpdates(LocationManager.java:625)
at ecm2.android.LocationActivity.onCreate(LocationActivity.java:142)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)