fix NPE in settings when last known position is null
This is not a proper fix, we would have to request a location first. I just had a last known position when testing before. :/ Issue #346
This commit is contained in:
parent
8b24e098ea
commit
a2c2e48719
|
@ -142,6 +142,7 @@ public class SettingsActivity extends AbstractSettingsActivity {
|
||||||
String provider = locationManager.getBestProvider(criteria, false);
|
String provider = locationManager.getBestProvider(criteria, false);
|
||||||
if (provider != null) {
|
if (provider != null) {
|
||||||
Location location = locationManager.getLastKnownLocation(provider);
|
Location location = locationManager.getLastKnownLocation(provider);
|
||||||
|
if (location != null) {
|
||||||
String latitude = String.format(Locale.US, "%.6g", location.getLatitude());
|
String latitude = String.format(Locale.US, "%.6g", location.getLatitude());
|
||||||
String longitude = String.format(Locale.US, "%.6g", location.getLongitude());
|
String longitude = String.format(Locale.US, "%.6g", location.getLongitude());
|
||||||
LOG.info("got location. Lat: " + latitude + " Lng: " + longitude);
|
LOG.info("got location. Lat: " + latitude + " Lng: " + longitude);
|
||||||
|
@ -151,6 +152,9 @@ public class SettingsActivity extends AbstractSettingsActivity {
|
||||||
pref_longitude.setText(longitude);
|
pref_longitude.setText(longitude);
|
||||||
pref_latitude.setSummary(latitude);
|
pref_latitude.setSummary(latitude);
|
||||||
pref_longitude.setSummary(longitude);
|
pref_longitude.setSummary(longitude);
|
||||||
|
} else {
|
||||||
|
GB.toast(SettingsActivity.this, "no last known position", 3000, 0);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
LOG.warn("No location provider found, did you deny location permission?");
|
LOG.warn("No location provider found, did you deny location permission?");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue