From 3b32b09dcad1a02c45d9ed28fac76de99bf42a17 Mon Sep 17 00:00:00 2001 From: mendhak Date: Sat, 4 Apr 2015 10:29:22 +0100 Subject: [PATCH] Intent with setprefercelltower will enable or disable GPS listener Closes #300 --- .../com/mendhak/gpslogger/GpsLoggingService.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/gpslogger/src/main/java/com/mendhak/gpslogger/GpsLoggingService.java b/gpslogger/src/main/java/com/mendhak/gpslogger/GpsLoggingService.java index 27be6b4e5..b61ca57e7 100644 --- a/gpslogger/src/main/java/com/mendhak/gpslogger/GpsLoggingService.java +++ b/gpslogger/src/main/java/com/mendhak/gpslogger/GpsLoggingService.java @@ -46,7 +46,7 @@ import java.text.DecimalFormat; import java.text.NumberFormat; import java.text.SimpleDateFormat; -import java.util.Date; +import java.util.*; public class GpsLoggingService extends Service { private static NotificationManager notificationManager; @@ -157,7 +157,16 @@ private void HandleIntent(Intent intent) { if (bundle.get(IntentConstants.PREFER_CELLTOWER) != null) { boolean preferCellTower = bundle.getBoolean(IntentConstants.PREFER_CELLTOWER); tracer.debug("Intent received - Set Prefer Cell Tower: " + String.valueOf(preferCellTower)); - prefs.edit().putBoolean("prefer_celltower", preferCellTower).apply(); + + List listeners = Utilities.GetListeners(); + if(preferCellTower){ + listeners.remove(listeners.indexOf("gps")); + } else { + listeners.remove(listeners.indexOf("network")); + listeners.remove(listeners.indexOf("passive")); + } + Set listenersSet = new HashSet(listeners); + prefs.edit().putStringSet("listeners", listenersSet).apply(); needToStartGpsManager = true; }