Hi,
In an application I would like to start a Service that can receive two notification from GPS: GPS_EVENT_STARTED and GPS_EVENT_STOPPED.
To do so I've done the following code:
package com.test;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.location.GpsStatus;
import android.location.LocationManager;
import android.os.IBinder;
import android.util.Log;
public class TestNotification extends Service {
private LocationManager mLm;
private MyListener mMyListener;
private class MyListener implements GpsStatus.Listener {
@Override
public void onGpsStatusChanged(int event) {
Log.i("MyGps", "Event");
switch(event) {
case GpsStatus.GPS_EVENT_STARTED:
Log.i("MyGps", "Started");
break;
case GpsStatus.GPS_EVENT_STOPPED:
Log.i("MyGps", "Stopped");
break;
}
}
}
@Override
public IBinder onBind(Intent arg0) {
return null;
}
@Override
public void onCreate() {
mLm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
mMyListener = new MyListener();
mLm.addGpsStatusListener( mMyListener );
}
}
I also have set the following permission in manifest: ACCESS_FINE_LOCATION I don't want to use requestLocationUpdates because it makes the GPS working everytime and send events when fixes change.
It test it on emulator and on real device (Eclair) but it doesn't work, the Service never receive any notification.
I've read in detail the following thread (here) but no solution work. I send it in a separate question because I only want to be informed of GPS start and stop, not fixes.
Do you have any advice on this? May be it is because I try to do it in a Service rather that in an Activity?
Thanks for reading.