From 8b8f356274210b95c090bf56c27e4e36087a0919 Mon Sep 17 00:00:00 2001 From: Christian Schneppe Date: Sun, 28 Jan 2018 13:14:59 +0100 Subject: aaded some checks to fix some rare crashes of location services --- .../java/de/pixart/messenger/ui/LocationActivity.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/main/java/de/pixart/messenger/ui/LocationActivity.java b/src/main/java/de/pixart/messenger/ui/LocationActivity.java index 74e2b45f9..6389fa7d4 100644 --- a/src/main/java/de/pixart/messenger/ui/LocationActivity.java +++ b/src/main/java/de/pixart/messenger/ui/LocationActivity.java @@ -31,13 +31,19 @@ public abstract class LocationActivity extends Activity implements LocationListe } catch (final UnsupportedOperationException ignored) { } } - - locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, Config.LOCATION_FIX_TIME_DELTA, Config.LOCATION_FIX_SPACE_DELTA, this); - locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, Config.LOCATION_FIX_TIME_DELTA, Config.LOCATION_FIX_SPACE_DELTA, this); - + if (locationManager.getAllProviders().contains(LocationManager.NETWORK_PROVIDER) + && locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) { + locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, Config.LOCATION_FIX_TIME_DELTA, Config.LOCATION_FIX_SPACE_DELTA, this); + } + if (locationManager.getAllProviders().contains(LocationManager.GPS_PROVIDER) + && locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { + locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, Config.LOCATION_FIX_TIME_DELTA, Config.LOCATION_FIX_SPACE_DELTA, this); + } // If something else is also querying for location more frequently than we are, the battery is already being // drained. Go ahead and use the existing locations as often as we can get them. - locationManager.requestLocationUpdates(LocationManager.PASSIVE_PROVIDER, 0, 0, this); + if (locationManager.getAllProviders().contains(LocationManager.PASSIVE_PROVIDER)) { + locationManager.requestLocationUpdates(LocationManager.PASSIVE_PROVIDER, 0, 0, this); + } } protected void pauseLocationUpdates() { -- cgit v1.2.3