@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();
//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");
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) { } }
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); }
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); }
mLocationManager.setTestProviderLocation(GPS_PROVIDER, mMockLocation);
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(); ....
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); }
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); }
geoLocationManager.setTestProviderLocation(mocLocationProvider, loc); } catch (Exception e) { e.printStackTrace();
location.setAccuracy(accuracy); location.setTime(timestamp); location.setElapsedRealtimeNanos(SystemClock.elapsedRealtimeNanos()); locationManager.setTestProviderLocation(GPS_MOCK_PROVIDER, location);
mLocationManager.setTestProviderLocation( LocationManager.GPS_PROVIDER, location); location.setProvider(VEHICLE_LOCATION_PROVIDER); mLocationManager.setTestProviderLocation( VEHICLE_LOCATION_PROVIDER, location); } catch(SecurityException e) {
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();