I'm using the LocationClient which works good. Now I'm trying to create mock locations (setMockMode(true) + setMockLocation(mockLoc). But onLocationChanged of my LocationListener isn't called. What can be the problem?
I followed this: http://developer.android.com/training/location/location-testing.html
Steps:
Okay so you gotta update your Locations with setTime()
and setElapsedRealtimeNanos()
.
A complete create method for a location will look something like following:
@SuppressLint("NewApi")
public Location createLocation(double lat, double lng, float accuracy) {
// Create a new Location
Location newLocation = new Location(PROVIDER);
newLocation.setLatitude(lat);
newLocation.setLongitude(lng);
newLocation.setAccuracy(accuracy);
newLocation.setTime(System.currentTimeMillis());
int sdk = android.os.Build.VERSION.SDK_INT;
if(sdk >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) {
newLocation.setElapsedRealtimeNanos(
SystemClock.elapsedRealtimeNanos());
}
return newLocation;
}
This has been tested to work with Nexus 5.
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