altosdroid: Hook up the position listeners
authorKeith Packard <keithp@keithp.com>
Fri, 12 Apr 2013 05:16:25 +0000 (22:16 -0700)
committerKeith Packard <keithp@keithp.com>
Fri, 12 Apr 2013 05:16:25 +0000 (22:16 -0700)
Signed-off-by: Keith Packard <keithp@keithp.com>
altosdroid/AndroidManifest.xml
altosdroid/src/org/altusmetrum/AltosDroid/TelemetryService.java

index 237c6dcf40e1dbf01498337c169709233cbd8cff..bf88574453b7be124f3054da02cb2063dcd6134e 100644 (file)
@@ -31,7 +31,6 @@
     <!-- Permissions needed for GoogleMaps -->
     <uses-permission android:name="android.permission.INTERNET"/>
     <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
-    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
     <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
 
     <permission android:name="org.altusmetrum.AltosDroid.permission.MAPS_RECEIVE"
index 5ff00a680a5d50c974419242a3be74fe054f8126..e1a5ada8ed2dd02e820f215268bcc4c8480f87b5 100644 (file)
@@ -29,7 +29,8 @@ import android.app.PendingIntent;
 import android.app.Service;
 import android.bluetooth.BluetoothDevice;
 import android.content.Intent;
-//import android.os.Bundle;
+import android.content.Context;
+import android.os.Bundle;
 import android.os.IBinder;
 import android.os.Handler;
 import android.os.Message;
@@ -37,9 +38,32 @@ import android.os.Messenger;
 import android.os.RemoteException;
 import android.util.Log;
 import android.widget.Toast;
+import android.location.Location;
+import android.location.LocationManager;
+import android.location.LocationListener;
 
 import org.altusmetrum.altoslib_1.*;
 
+class AltosLocationListener implements LocationListener {
+       boolean fine;
+
+       public void onLocationChanged(Location location) {
+       }
+
+       public void onStatusChanged(String provider, int status, Bundle extras) {
+       }
+
+       public void onProviderEnabled(String provider) {
+       }
+
+       public void onProviderDisabled(String provider) {
+       }
+
+       public AltosLocationListener(boolean fine) {
+               this.fine = fine;
+       }
+}
+
 public class TelemetryService extends Service {
 
        private static final String TAG = "TelemetryService";
@@ -81,6 +105,11 @@ public class TelemetryService extends Service {
        // internally track state of bluetooth connection
        private int state = STATE_NONE;
 
+       // location listeners
+
+       private AltosLocationListener gpsListener;
+       private AltosLocationListener netListener;
+       
        // Handler of incoming messages from clients.
        static class IncomingHandler extends Handler {
                private final WeakReference<TelemetryService> service;
@@ -249,6 +278,14 @@ public class TelemetryService extends Service {
                // Start our timer - first event in 10 seconds, then every 10 seconds after that.
                timer.scheduleAtFixedRate(new TimerTask(){ public void run() {onTimerTick();}}, 10000L, 10000L);
 
+               // Listen for GPS and Network position updates
+               gpsListener = new AltosLocationListener(true);
+               netListener = new AltosLocationListener(false);
+
+               LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
+               
+               locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, gpsListener);
+               locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, netListener);
        }
 
        @Override
@@ -281,6 +318,11 @@ public class TelemetryService extends Service {
        @Override
        public void onDestroy() {
 
+               // Stop listening for location updates
+               LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
+               locationManager.removeUpdates(gpsListener);
+               locationManager.removeUpdates(netListener);
+
                // Stop the bluetooth Comms threads
                stopAltosBluetooth();