Java Code Examples for android.location.LocationManager#addTestProvider()
The following examples show how to use
android.location.LocationManager#addTestProvider() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MainActivity.java From together-go with GNU Lesser General Public License v3.0 | 6 votes |
private void initMoveManager() { if (Build.VERSION.SDK_INT < 23) { if (Settings.Secure.getInt(this.getContentResolver(), Settings.Secure.ALLOW_MOCK_LOCATION, 0) == 0) { simulateLocationPermission(); } } random = new Random(); try { locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE); locationManager.addTestProvider(LocationManager.GPS_PROVIDER, false, true, false, false, true, true, true, 0, 5); locationManager.setTestProviderEnabled(LocationManager.GPS_PROVIDER, true); } catch (SecurityException e) { simulateLocationPermission(); } }
Example 2
Source File: MockLocationProvider.java From FakeTraveler with GNU General Public License v3.0 | 6 votes |
/** * Class constructor * * @param name provider * @param ctx context * @return Void */ public MockLocationProvider(String name, Context ctx) { this.providerName = name; this.ctx = ctx; LocationManager lm = (LocationManager) ctx.getSystemService( Context.LOCATION_SERVICE); try { lm.addTestProvider(providerName, false, false, false, false, false, true, true, 0, 5); lm.setTestProviderEnabled(providerName, true); } catch(SecurityException e) { throw new SecurityException("Not allowed to perform MOCK_LOCATION"); } }
Example 3
Source File: MoveService.java From together-go with GNU Lesser General Public License v3.0 | 5 votes |
@Override public void onCreate() { Log.i("move", "create"); super.onCreate(); //initialize(); random = new Random(); locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE); locationManager.addTestProvider(LocationManager.GPS_PROVIDER, false, true, false, false, true, true, true, 0, 5); locationManager.setTestProviderEnabled(LocationManager.GPS_PROVIDER, true); thread = new Thread(new Runnable() { @Override public void run() { while (true) { try { Thread.sleep(500); } catch (InterruptedException e) { e.printStackTrace(); } setLocation(longitude, latitude); longitude += 0.0002; Log.i("Location", "location location"); } } }); thread.start(); }
Example 4
Source File: MoveService.java From together-go with GNU Lesser General Public License v3.0 | 5 votes |
private void initialize() { Log.i("move", "start start"); random = new Random(); locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE); locationManager.addTestProvider(LocationManager.GPS_PROVIDER, false, true, false, false, true, true, true, 0, 5); locationManager.setTestProviderEnabled(LocationManager.GPS_PROVIDER, true); }
Example 5
Source File: LocationProvider.java From privatelocation with GNU General Public License v3.0 | 5 votes |
public LocationProvider(String name, Context context) { this.providerName = name; this.context = context; LocationManager locationManager = (LocationManager) context.getSystemService( Context.LOCATION_SERVICE); try { locationManager.addTestProvider(providerName, false, false, false, false, false, true, true, Criteria.POWER_LOW, Criteria.ACCURACY_FINE); locationManager.setTestProviderEnabled(providerName, true); } catch (SecurityException e) { throw new SecurityException("Error applying mock location"); } }
Example 6
Source File: OtherUtils.java From robotium-extensions with Apache License 2.0 | 5 votes |
OtherUtils(ExtSolo extSolo, String className, String methodName) { mMetadataConnected = extSolo.getInstrumentation() .getTargetContext() .bindService(new Intent("com.bitbar.testdroid.monitor.MetadataService") .setPackage("com.bitbar.testdroid.monitor"), mConnection, Context.BIND_AUTO_CREATE); //set needed variables this.extSolo = extSolo; this.className = className; this.methodName = methodName; //get current language locale = extSolo.getInstrumentation().getTargetContext().getResources().getConfiguration().locale; Log.d(ExtSolo.TAG, String.format(Messages.CURRENT_LOCALE, locale.toString())); //initializaion of mocking location - move to constructor try { locationManager = (LocationManager) extSolo.getInstrumentation().getContext().getSystemService(Context.LOCATION_SERVICE); locationManager.addTestProvider(LocationManager.GPS_PROVIDER, false, false, false, false, true, false, false, 1, 1); locationManager.setTestProviderEnabled(LocationManager.GPS_PROVIDER, true); mockGPSTimer = new Timer(); } catch (SecurityException e) { locationManager = null; } setUp(); }
Example 7
Source File: MockLocationProvider.java From coursera-android-labs with MIT License | 5 votes |
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); }
Example 8
Source File: MockLocationProvider.java From android_coursera_1 with MIT License | 5 votes |
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); }
Example 9
Source File: MockLocationProvider.java From android_coursera_1 with MIT License | 5 votes |
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); }
Example 10
Source File: Utils.java From android-utils with MIT License | 4 votes |
/** * Set Mock Location for test device. DDMS cannot be used to mock location on an actual device. * So this method should be used which forces the GPS Provider to mock the location on an actual * device. **/ public static void setMockLocation(Context ctx, double longitude, double latitude) { // use application level context to avoid unnecessary leaks. LocationManager locationManager = (LocationManager) ctx.getApplicationContext().getSystemService(Context.LOCATION_SERVICE); locationManager.addTestProvider(LocationManager.GPS_PROVIDER, "requiresNetwork" == "", "requiresSatellite" == "", "requiresCell" == "", "hasMonetaryCost" == "", "supportsAltitude" == "", "supportsSpeed" == "", "supportsBearing" == "", android.location.Criteria.POWER_LOW, android.location.Criteria.ACCURACY_FINE); Location newLocation = new Location(LocationManager.GPS_PROVIDER); newLocation.setLongitude(longitude); newLocation.setLatitude(latitude); newLocation.setTime(new Date().getTime()); newLocation.setAccuracy(500); locationManager.setTestProviderEnabled(LocationManager.GPS_PROVIDER, true); locationManager.setTestProviderStatus(LocationManager.GPS_PROVIDER, LocationProvider.AVAILABLE, null, System.currentTimeMillis()); // http://jgrasstechtips.blogspot.it/2012/12/android-incomplete-location-object.html makeLocationObjectComplete(newLocation); locationManager.setTestProviderLocation(LocationManager.GPS_PROVIDER, newLocation); }
Example 11
Source File: MockLocationGenerator.java From test-samples with Apache License 2.0 | 3 votes |
public MockLocationGenerator(Context context) { this.context = context; locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); locationManager.addTestProvider(locationManager.NETWORK_PROVIDER, false, false, false, false, false, true, true, 0, 1); locationManager.addTestProvider(locationManager.GPS_PROVIDER, false, false, false, false, false, true, true, 0, 1); }