Back to project page androidui.
The source code is released under:
MIT License
If you think the Android project androidui listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package course.labs.placebadges; //from w w w . j a va 2 s. c om // Adapted from code found at: // http://mobiarch.wordpress.com/2012/07/17/testing-with-mock-location-data-in-android/ import android.content.Context; import android.location.Location; import android.location.LocationManager; import android.os.SystemClock; public class MockLocationProvider { private String mProviderName; private LocationManager mLocationManager; private static float mockAccuracy = 5; public MockLocationProvider(String name, Context ctx) { this.mProviderName = name; mLocationManager = (LocationManager) ctx .getSystemService(Context.LOCATION_SERVICE); mLocationManager.addTestProvider(mProviderName, false, false, false, false, true, true, true, 0, 5); mLocationManager.setTestProviderEnabled(mProviderName, true); } public void pushLocation(double lat, double lon) { Location mockLocation = new Location(mProviderName); mockLocation.setLatitude(lat); mockLocation.setLongitude(lon); mockLocation.setAltitude(0); mockLocation.setTime(System.currentTimeMillis()); mockLocation .setElapsedRealtimeNanos(SystemClock.elapsedRealtimeNanos()); mockLocation.setAccuracy(mockAccuracy); mLocationManager.setTestProviderLocation(mProviderName, mockLocation); } public void shutdown() { mLocationManager.removeTestProvider(mProviderName); } }