本文整理了Java中android.location.LocationManager.setTestProviderLocation()
方法的一些代码示例,展示了LocationManager.setTestProviderLocation()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。LocationManager.setTestProviderLocation()
方法的具体详情如下:
包路径:android.location.LocationManager
类名称:LocationManager
方法名:setTestProviderLocation
暂无
代码示例来源:origin: xbenjii/PokeMock
@Override
public void run() {
while (true) {
currentLocation.setTime(System.currentTimeMillis());
currentLocation.setElapsedRealtimeNanos(SystemClock.elapsedRealtimeNanos());
mLocationManager.setTestProviderLocation(mockLocationProvider, currentLocation);
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}).start();
代码示例来源:origin: stackoverflow.com
//Instantiate in your activity
LocationManager lm = getSystemService(LOCATION_SERVICE);
//Add a test provider
lm.addTestProvider("myprovider", false, false, false, false, true, true, true, Criteria.POWER_HIGH, Criteria.ACCURACY_FINE);
//Update the last location your provider will serve
Location fakeLoc = ...;
lm.setTestProviderLocation("myprovider", fakeLoc);
//Using your custom location provider
LocationProvider customProvider = lm.getProvider("myprovider");
代码示例来源:origin: stackoverflow.com
public void testGPS() {
LocationManager lm = (LocationManager) mActivity
.getSystemService(Context.LOCATION_SERVICE);
lm.setTestProviderEnabled(LocationManager.GPS_PROVIDER, true);
lm.setTestProviderStatus(LocationManager.GPS_PROVIDER,
LocationProvider.AVAILABLE,
null, System.currentTimeMillis());
Location location = new Location(LocationManager.GPS_PROVIDER);
location.setLatitude(1.0);
location.setLongitude(2.0);
location.setTime(System.currentTimeMillis());
lm.setTestProviderLocation(LocationManager.GPS_PROVIDER, location);
try {
Thread.sleep(2000);
} catch(InterruptedException e) {
}
}
代码示例来源:origin: luv/mockgeofix
protected void _simulate(Location location) {
if (!location.hasAccuracy()) {
location.setAccuracy(accuracy);
}
if (!location.hasAltitude()) {
location.setAltitude(0);
}
try {
Method locationJellyBeanFixMethod = Location.class.getMethod("makeComplete");
if (locationJellyBeanFixMethod != null) {
locationJellyBeanFixMethod.invoke(location);
}
} catch (IllegalAccessException ignored) {
} catch (NoSuchMethodException ignored) {
} catch (InvocationTargetException ignored) {}
mLocationManager.setTestProviderLocation(locationProviderName, location);
}
代码示例来源:origin: org.seleniumhq.selenium/selenium-android-driver
public void setLocation(Location loc) {
android.location.Location location =
new android.location.Location(locationProvider);
location.setLatitude(loc.getLatitude());
location.setLongitude(loc.getLongitude());
location.setAltitude(loc.getAltitude());
// set the time so it's not ignored!
location.setTime(System.currentTimeMillis());
locManagerSupplier.get().setTestProviderLocation(locationProvider, location);
}
代码示例来源:origin: stackoverflow.com
mLocationManager.setTestProviderLocation(GPS_PROVIDER, mMockLocation);
代码示例来源:origin: stackoverflow.com
public void test1_TestCaseFoo()
{
Location location = new Location("network");
location.setLatitude(-15.83554363);
location.setLongitude(-48.01770782);
location.setTime(new Date().getTime());
location.setAccuracy(100.0f);
location.setElapsedRealtimeNanos(System.nanoTime());
LocationManager locationManager = (LocationManager) getInstrumentation().getTargetContext().getSystemService(Context.LOCATION_SERVICE);
locationManager.addTestProvider(LocationManager.GPS_PROVIDER, false, false, false, false, true, true, true, Criteria.POWER_LOW, Criteria.ACCURACY_FINE);
locationManager.setTestProviderStatus(LocationManager.GPS_PROVIDER, LocationProvider.AVAILABLE, null, System.currentTimeMillis());
locationManager.setTestProviderEnabled(LocationManager.GPS_PROVIDER, true);
locationManager.setTestProviderLocation(LocationManager.GPS_PROVIDER, location);
locationManager.addTestProvider(LocationManager.NETWORK_PROVIDER, false, false, false, false, true, true, true, Criteria.POWER_LOW, Criteria.ACCURACY_FINE);
locationManager.setTestProviderStatus(LocationManager.NETWORK_PROVIDER, LocationProvider.AVAILABLE, null, System.currentTimeMillis());
locationManager.setTestProviderEnabled(LocationManager.NETWORK_PROVIDER, true);
locationManager.setTestProviderLocation(LocationManager.NETWORK_PROVIDER, location);
mActivity = getActivity();
....
代码示例来源:origin: amotzte/android-mock-location-for-development
void pushLocation(double lat, double lon,double alt,float accuracy) {
LocationManager lm = (LocationManager) ctx.getSystemService(
Context.LOCATION_SERVICE);
Location mockLocation = new Location(providerName);
mockLocation.setLatitude(lat);
mockLocation.setLongitude(lon);
mockLocation.setAltitude(alt);
mockLocation.setTime(System.currentTimeMillis());
mockLocation.setAccuracy(accuracy);
if ( Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
mockLocation.setElapsedRealtimeNanos(SystemClock.elapsedRealtimeNanos());
}
lm.setTestProviderLocation(providerName, mockLocation);
}
代码示例来源:origin: johncarpenter/Android-GPX-Mock-Location-Provider
private void sendLocation(GpxTrackPoint point) {
Location loc = new Location(providerName);
loc.setLatitude(point.getLat());
loc.setLongitude(point.getLon());
loc.setTime(System.currentTimeMillis());
loc.setBearing((float) point.getHeading());
loc.setAccuracy(1.0f);
loc.setSpeed((float) point.getSpeed());
loc.setAltitude(100.0);
// bk added
Method method;
try {
method = Location.class.getMethod("makeComplete", new Class[0]);
if (method != null)
{
try
{
method.invoke(loc, new Object[0]);
}
catch (Exception exception) { }
}
} catch (NoSuchMethodException e) {
e.printStackTrace();
}
Log.d("SendLocation", "Sending update for " + providerName);
mLocationManager.setTestProviderLocation(providerName, loc);
}
代码示例来源:origin: Phantast/smartnavi
geoLocationManager.setTestProviderLocation(mocLocationProvider, loc);
} catch (Exception e) {
e.printStackTrace();
代码示例来源:origin: stackoverflow.com
location.setAccuracy(accuracy);
location.setTime(timestamp);
location.setElapsedRealtimeNanos(SystemClock.elapsedRealtimeNanos()); locationManager.setTestProviderLocation(GPS_MOCK_PROVIDER, location);
代码示例来源:origin: openxc/openxc-android
mLocationManager.setTestProviderLocation(
LocationManager.GPS_PROVIDER, location);
location.setProvider(VEHICLE_LOCATION_PROVIDER);
mLocationManager.setTestProviderLocation(
VEHICLE_LOCATION_PROVIDER, location);
} catch(SecurityException e) {
代码示例来源:origin: stackoverflow.com
LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
Criteria criteria = new Criteria();
criteria.setAccuracy( Criteria.ACCURACY_FINE );
String mocLocationProvider = LocationManager.GPS_PROVIDER;//lm.getBestProvider( criteria, true );
if ( mocLocationProvider == null ) {
Toast.makeText(getApplicationContext(), "No location provider found!", Toast.LENGTH_SHORT).show();
return;
}
lm.addTestProvider(mocLocationProvider, false, false,
false, false, true, true, true, 0, 5);
lm.setTestProviderEnabled(mocLocationProvider, true);
Location loc = new Location(mocLocationProvider);
Location mockLocation = new Location(mocLocationProvider); // a string
mockLocation.setLatitude(-26.902038); // double
mockLocation.setLongitude(-48.671337);
mockLocation.setAltitude(loc.getAltitude());
mockLocation.setTime(System.currentTimeMillis());
mockLocation.setAccuracy(1);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
mockLocation.setElapsedRealtimeNanos(SystemClock.elapsedRealtimeNanos());
}
lm.setTestProviderLocation( mocLocationProvider, mockLocation);
Toast.makeText(getApplicationContext(), "Working", Toast.LENGTH_SHORT).show();
内容来源于网络,如有侵权,请联系作者删除!