Friday, 27 September 2013

Android GPS not working in service

Android GPS not working in service

Im trying to get my GPS working in a service but its not working. The GPS
bit works on its own but not in the service.
I have tried debugging with System.out.println() and fond where it stops
working but cant work out why it all looks good.
public int onStartCommand(Intent intent, int flags, int startId) {
System.out.println("test 1");
LocationManager lm =
(LocationManager)getSystemService(Context.LOCATION_SERVICE);
System.out.println("test 2");
LocationListener lli = new myLocationListener();
System.out.println("test 3");
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 5000, 10,
lli);
System.out.println("test 4");
// We want this service to continue running until it is explicitly
// stopped, so return sticky.
return START_STICKY;
}
class myLocationListener implements LocationListener{
@Override
public void onLocationChanged(Location location) {
// TODO Auto-generated method stub
if(location != null){
pet.setMeter();
}
}
It gets to Test 4 then dies. I am lost at why so if anyone can help that
would be awesome thanks.

No comments:

Post a Comment