Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error android.os.SystemClock.elapsedRealtimeNanos in MockLocationProvider.pushLocation

Tags:

android

I simulate GPS position in app Android and when I do

myMockLocationProvider.pushLocation(37.422, -122.084);

I get the following error:

java.lang.NoSuchMethodError: android.os.SystemClock.elapsedRealtimeNanos at mylab.MockLocationProvider.pushLocation(MockLocationProvider.java:36)

Any idea?

like image 647
Moisés Martínez Avatar asked Jan 18 '26 06:01

Moisés Martínez


1 Answers

I was having the same problem and I have just realized that I was using a mobile with an API version of 16. When I looked at the documentation of `SystemClock.elapsedRealtimeNanos()` they say that this method was added only after the API version is 17. So, I guess you are using a device with an API lower than 17.

Try the following code and see if it works:

Location loc = new Location(LocationManager.GPS_PROVIDER);
loc.setLatitude(37.422);
loc.setLongitude(-122.084);
loc.setAltitude(0);
loc.setTime(System.currentTimeMillis());
loc.setAccuracy(10);
if (android.os.Build.VERSION.SDK_INT >= 17)
    loc.setElapsedRealtimeNanos(SystemClock.elapsedRealtimeNanos());
like image 97
ceciliajoanna Avatar answered Jan 20 '26 21:01

ceciliajoanna