mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-27 20:36:51 +01:00
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,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?");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user