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?
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());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With