From f6f6b53283d6a02cb62d3315d71e5a6911f59646 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 20 Jun 2021 17:06:28 -0700 Subject: [PATCH] altosdroid: Work without GPS available On devices without GPS receivers, use network location instead of crashing. Signed-off-by: Keith Packard --- .../altusmetrum/AltosDroid/AltosDroid.java | 21 +++++++++++++------ .../AltosDroid/PreloadMapActivity.java | 7 +++++-- icon/Makefile.am | 9 ++++++-- 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/altosdroid/app/src/main/java/org/altusmetrum/AltosDroid/AltosDroid.java b/altosdroid/app/src/main/java/org/altusmetrum/AltosDroid/AltosDroid.java index 404b63ac..5caee5f8 100644 --- a/altosdroid/app/src/main/java/org/altusmetrum/AltosDroid/AltosDroid.java +++ b/altosdroid/app/src/main/java/org/altusmetrum/AltosDroid/AltosDroid.java @@ -742,14 +742,23 @@ public class AltosDroid extends FragmentActivity implements AltosUnitsListener, private void enable_location_updates() { // Listen for GPS and Network position updates LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); - locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 1, this); - location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); + if (locationManager != null) + { + try { + locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 1, this); + location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); + } catch (Exception e) { + locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 1000, 1, this); + location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); + } - if (location != null) - AltosDebug.debug("Resume, location is %f,%f\n", - location.getLatitude(), - location.getLongitude()); + if (location != null) + AltosDebug.debug("Resume, location is %f,%f\n", + location.getLatitude(), + location.getLongitude()); + AltosDebug.debug("Failed to get GPS updates\n"); + } update_ui(telemetry_state, state, true); } diff --git a/altosdroid/app/src/main/java/org/altusmetrum/AltosDroid/PreloadMapActivity.java b/altosdroid/app/src/main/java/org/altusmetrum/AltosDroid/PreloadMapActivity.java index f911e1ee..eb123011 100644 --- a/altosdroid/app/src/main/java/org/altusmetrum/AltosDroid/PreloadMapActivity.java +++ b/altosdroid/app/src/main/java/org/altusmetrum/AltosDroid/PreloadMapActivity.java @@ -356,8 +356,11 @@ public class PreloadMapActivity extends Activity implements AltosLaunchSiteListe // Listen for GPS and Network position updates LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); - - locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 1, this); + try { + locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 1, this); + } catch (Exception e) { + locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 1000, 1, this); + } new AltosLaunchSites(this); } diff --git a/icon/Makefile.am b/icon/Makefile.am index 9ce9cba8..0f4389d0 100644 --- a/icon/Makefile.am +++ b/icon/Makefile.am @@ -1,7 +1,8 @@ JAVA_RES=16 32 48 64 128 256 MAC_RES=16 32 128 256 512 WIN_RES=16 24 32 48 64 72 96 128 180 256 -RES=$(shell echo $(JAVA_RES) $(MAC_RES) $(WIN_RES) | awk '{ for (i = 1; i <= NF; i++) printf("%s\n", $$i); }' | sort -n -u) +AMAZON_RES=114 512 +RES=$(shell echo $(JAVA_RES) $(MAC_RES) $(WIN_RES) $(AMAZON_RES)| awk '{ for (i = 1; i <= NF; i++) printf("%s\n", $$i); }' | sort -n -u) # Application icon base names @@ -73,6 +74,10 @@ JAVA_TG_FILES = $(shell for i in $(JAVA_RES); do echo $(TG_NAME)-$$i.png; done) JAVA_FILES = $(JAVA_AM_FILES) $(JAVA_MP_FILES) $(JAVA_TG_FILES) +# Files needed for Amazon store + +AMAZON_FILES = $(shell for i in $(AMAZON_RES); do echo $(AM_NAME)-$$i.png; done) + # PNG files needed by anyone AM_FILES = $(shell for i in $(RES); do echo $(AM_NAME)-$$i.png; done) @@ -120,7 +125,7 @@ java-telegps: fat: all $(ICO_FILES) $(ICNS_FILES) $(EXE_FILES) -all-local: $(JAVA_FILES) $(AM_XPM) $(LED_ICONS) +all-local: $(JAVA_FILES) $(AM_XPM) $(LED_ICONS) $(AMAZON_FILES) clean-local: $(RM) $(AM_NAME)-*.png $(TG_NAME)-*.png $(MP_NAME)-*.png -- 2.30.2