public static void reactivateFakeProvider() { if (BuildConfig.debug) Log.i("Location-Status", "reactivate Fake Provider"); try { mocLocationProvider = LocationManager.GPS_PROVIDER; geoLocationManager.addTestProvider(mocLocationProvider, false, false, false, false, true, true, true, 0, 5); geoLocationManager.setTestProviderEnabled(mocLocationProvider, true); } catch (Exception e) { e.printStackTrace(); } }
private void setupTestProvider() { mLocationManager.addTestProvider(PROVIDER_NAME, false, //requiresNetwork, false, // requiresSatellite, false, // requiresCell, false, // hasMonetaryCost, false, // supportsAltitude, false, // supportsSpeed, s false, // upportsBearing, Criteria.POWER_LOW, // powerRequirement Criteria.ACCURACY_FINE); // accuracy mLocationManager.setTestProviderEnabled("gps", true); }
protected void _register() { // if the test provider already exists, android handles this fine try { mLocationManager.addTestProvider(locationProviderName, false, false, false, false, true, true, true, 0, accuracy); mLocationManager.setTestProviderEnabled(locationProviderName, true); } catch (IllegalArgumentException ex) { Log.e(TAG, "IllegalArgumentException thrown in _register"); } }
MockLocationProvider(String name, Context ctx) { this.providerName = name; this.ctx = ctx; LocationManager lm = (LocationManager) ctx.getSystemService( Context.LOCATION_SERVICE); lm.addTestProvider(providerName, false, false, false, false, false, true, true, 0, 5); lm.setTestProviderEnabled(providerName, true); }
private void overwriteNativeProvider() { if(mOverwriteNativeStatus && !mNativeGpsOverridden && mLocationManager != null) { try { mLocationManager.addTestProvider(LocationManager.GPS_PROVIDER, false, false, false, false, false, true, false, 0, 5); mLocationManager.setTestProviderEnabled( LocationManager.GPS_PROVIDER, true); } catch(SecurityException e) { Log.w(TAG, "Unable to use mocked locations, " + "insufficient privileges - make sure mock locations " + "are allowed in device settings", e); } } }
public static void pauseFakeProvider() { if (BuildConfig.debug) Log.i("Location-Status", "pause Fake Provider"); try { geoLocationManager.setTestProviderEnabled(mocLocationProvider, false); geoLocationManager.removeTestProvider(mocLocationProvider); geoLocationManager.clearTestProviderEnabled(mocLocationProvider); } catch (Exception e) { e.printStackTrace(); } }
private void setupMockLocations() { try { if(mLocationManager.getProvider( VEHICLE_LOCATION_PROVIDER) == null) { mLocationManager.addTestProvider(VEHICLE_LOCATION_PROVIDER, false, false, false, false, false, true, false, 0, 5); } mLocationManager.setTestProviderEnabled( VEHICLE_LOCATION_PROVIDER, true); } catch(SecurityException e) { Log.w(TAG, "Unable to use mocked locations, " + "insufficient privileges - make sure mock locations " + "are allowed in device settings", e); mLocationManager = null; } } }
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: if (shouldStart == false) { try { geoLocationManager.setTestProviderEnabled(mocLocationProvider, false); geoLocationManager.removeTestProvider(mocLocationProvider); geoLocationManager.clearTestProviderEnabled(mocLocationProvider); } catch (Exception e) { e.printStackTrace(); } notificationManager.cancelAll(); Toast.makeText(this, getApplicationContext().getResources().getString(R.string.tx_70), Toast.LENGTH_LONG).show(); } finish(); return (true); default: return super.onOptionsItemSelected(item); } }
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) { } }
private void disableGpsProvider() { if (mLocationManager.getProvider(PROVIDER_NAME) != null) { mLocationManager.setTestProviderEnabled(PROVIDER_NAME, false); mLocationManager.clearTestProviderEnabled(PROVIDER_NAME); mLocationManager.clearTestProviderLocation(PROVIDER_NAME); mLocationManager.removeTestProvider(PROVIDER_NAME); } }
mLocationManager.addTestProvider(GPS_PROVIDER, false, false, false, false, false, true, true, 0, 5); mLocationManager.setTestProviderEnabled(GPS_PROVIDER, true);
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(); ....
try { geoLocationManager.addTestProvider(mocLocationProvider, false, false, false, false, true, true, true, 1, 5); geoLocationManager.setTestProviderEnabled(mocLocationProvider, true); geoLocationManager.setTestProviderStatus(mocLocationProvider, 2, null, System.currentTimeMillis());
public void stop() { //stop the Handlers who are responsible for restarting the sensor-listeners mTracker.send(new HitBuilders.EventBuilder() .setCategory("Action") .setAction("Backround_service_stopped") .build()); GoogleMap.listHandler.removeMessages(10); Config.backgroundServiceActive = false; try { geoLocationManager.setTestProviderEnabled(mocLocationProvider, false); } catch (Exception e) { // e.printStackTrace(); } try { geoLocationManager.clearTestProviderEnabled(mocLocationProvider); } catch (Exception e) { // e.printStackTrace(); } try { geoLocationManager.removeTestProvider(mocLocationProvider); } catch (Exception e) { // e.printStackTrace(); } notificationManager.cancelAll(); Toast.makeText(this, getApplicationContext().getResources().getString(R.string.tx_70), Toast.LENGTH_LONG).show(); finish(); }
geoLocationManager.setTestProviderEnabled(mocLocationProvider, false); } catch (Exception e2) {
locationManager.setTestProviderEnabled(GPS_MOCK_PROVIDER, true);
mLocationManager.setTestProviderEnabled(mockLocationProvider, true); mLocationManager.setTestProviderStatus(mockLocationProvider, LocationProvider.AVAILABLE, null, System.currentTimeMillis()); if(ContextCompat.checkSelfPermission(this,
locManager.addTestProvider(locationProvider, true, true, true, true, true, true, true, 0, 5); locManager.setTestProviderEnabled(locationProvider, true); locManager.requestLocationUpdates(locationProvider, 0, 0, this); } 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();