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:
Andreas Shimokawa 2016-07-03 21:29:02 +02:00
parent 8b24e098ea
commit a2c2e48719
1 changed files with 13 additions and 9 deletions

View File

@ -142,15 +142,19 @@ public class SettingsActivity extends AbstractSettingsActivity {
String provider = locationManager.getBestProvider(criteria, false);
if (provider != null) {
Location location = locationManager.getLastKnownLocation(provider);
String latitude = String.format(Locale.US, "%.6g", location.getLatitude());
String longitude = String.format(Locale.US, "%.6g", location.getLongitude());
LOG.info("got location. Lat: " + latitude + " Lng: " + longitude);
EditTextPreference pref_latitude = (EditTextPreference) findPreference("location_latitude");
EditTextPreference pref_longitude = (EditTextPreference) findPreference("location_longitude");
pref_latitude.setText(latitude);
pref_longitude.setText(longitude);
pref_latitude.setSummary(latitude);
pref_longitude.setSummary(longitude);
if (location != null) {
String latitude = String.format(Locale.US, "%.6g", location.getLatitude());
String longitude = String.format(Locale.US, "%.6g", location.getLongitude());
LOG.info("got location. Lat: " + latitude + " Lng: " + longitude);
EditTextPreference pref_latitude = (EditTextPreference) findPreference("location_latitude");
EditTextPreference pref_longitude = (EditTextPreference) findPreference("location_longitude");
pref_latitude.setText(latitude);
pref_longitude.setText(longitude);
pref_latitude.setSummary(latitude);
pref_longitude.setSummary(longitude);
} else {
GB.toast(SettingsActivity.this, "no last known position", 3000, 0);
}
} else {
LOG.warn("No location provider found, did you deny location permission?");
}