3

I have a service to mock GPS location doing a loop between a list of coordinates, but the method onLocationChanged() only detects the first mock of the GPS. I mean, if I launch one GPS program it only detects the first call of my service, doesn't mind if its the first location of the list or the last, just detect the first call it make.

I'm sure that I'm making the calls to change the coordinates in my services because I use a Toast message, but doesn't work..

Mi code. First I set up the LocationManager

ls = new MyLocationListener();

lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
lm.addTestProvider(Context.LOCATION_SERVICE, false, false,
        false, false, true, true, true, 0, 5);
lm.requestLocationUpdates(Context.LOCATION_SERVICE, 0, 0, ls);
lm.setTestProviderEnabled(Context.LOCATION_SERVICE, true);

MyLocationListener only has a show message in the method onLocationChanged(). Then with a timer I call periodically the function to mock GPS.

private void setMockLocation(double latitude, double longitude, float accuracy) {

        Location newLocation = new Location(Context.LOCATION_SERVICE);

        newLocation.setLatitude(latitude);
        newLocation.setLongitude(longitude);
        newLocation.setAccuracy(accuracy);
        newLocation.setTime(System.currentTimeMillis());

        lm.setTestProviderEnabled(mocLocationProvider, true);

        lm.setTestProviderStatus(Context.LOCATION_SERVICE,
                                 LocationProvider.AVAILABLE,
                                 null,System.currentTimeMillis());    


        lm.setTestProviderLocation(Context.LOCATION_SERVICE, newLocation);      
}

But it only works the first time called, not the next calls.

EDIT

After a few investigating work, I know the code works into 2.2 and 4.2. The version that has the device I need to work on it is 4.0. I don't know why, but doesn't run in that version. Any ideas?

Giacomo1968
  • 25,759
  • 11
  • 71
  • 103
adalpari
  • 3,052
  • 20
  • 39
  • After a few investigating work, I know the code works into 2.2 and 4.2. The version that has the device I need to work on it is 4.0. I don't know why, but doesn't run in that version. Any ideas? – adalpari Nov 27 '12 at 12:37

1 Answers1

1

It's late to answer this but if anyone to have the same bug in the future, here how I solved this.

I had the same issue but after setting 'setElapsedRealtimeNanos', it worked for me.

newLocation.setElapsedRealtimeNanos(SystemClock.elapsedRealtimeNanos());
hiruss
  • 11
  • 1