LocationManager addTestProvider - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for LocationManager addTestProvider method.

This code example shows how to use the following methods:addTestProvider, getProvider, setTestProviderEnabled
        } 
    } 
 
    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", e);
            mLocationManager = null;
        } 
    } 
} 
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:addTestProvider, setTestProviderEnabled, setTestProviderLocation, setTestProviderStatus, sleep
		double longitude = -88.22055;	
		Location fakeLocation = new Location(LocationManager.GPS_PROVIDER);		
		 
		try 
		{ 
			manager.addTestProvider(LocationManager.GPS_PROVIDER, true, true, true, true, true, true, true, 0, 5);
			manager.setTestProviderEnabled(LocationManager.GPS_PROVIDER, true);
			manager.setTestProviderStatus(LocationManager.GPS_PROVIDER, LocationProvider.AVAILABLE, null,System.currentTimeMillis());
		} 
		catch (Exception ex) {}
		 
		fakeLocation.setLatitude(latitude);
		fakeLocation.setLongitude(longitude);
		manager.setTestProviderLocation(LocationManager.GPS_PROVIDER, fakeLocation);	
		((RouteMap)mActivity).setMapCenter((int)(latitude * 1E6), (int)(longitude * 1E6));
		 
		thisWait(2000); 
		 
		((RouteMap)mActivity).clickOnOverlay(); // springfield and gregory ne corner
		 

6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:addTestProvider, requestLocationUpdates, setTestProviderEnabled, setTestProviderLocation, setTestProviderStatus
    } 
 
	private void doIt () 
    { 
 
    	lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, new LocationListener() {       
    	            @Override 
    	            public void onStatusChanged(String provider, int status, Bundle extras) {}
    	            @Override 
    	            public void onProviderEnabled(String provider) {}
    	            @Override 
    	            public void onProviderDisabled(String provider) {}
    	            @Override 
    	            public void onLocationChanged(Location location) {}
    	}); 
    	             
    	/* Set a mock location for debugging purposes */ 
    	setMockLocation(15.387653, 73.872585, 500); 
    } 
     

6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:addTestProvider, getAllProviders, getProvider, removeTestProvider, setTestProviderEnabled
 
	    Log.w(TAG, "LastKnownLocation of "+provider+" is: "+manager.getLastKnownLocation(provider));
	} 
 
	public static void createMockLocationProvider(LocationManager manager, String provider) {
		Log.w(TAG, "Providers: " + manager.getAllProviders().toString());
	    if(manager.getProvider(provider) != null) {
	      Log.w(TAG, "Removing provider " + provider);
	      manager.removeTestProvider(provider);
	    } 
	    Log.w(TAG, "Providers: " + manager.getAllProviders().toString());
 
	    if(manager.getProvider(provider) == null) {
	      Log.w(TAG, "Adding provider " + provider + " again");
	      manager.addTestProvider(provider, "requiresNetwork" == "", "requiresSatellite" == "",
	          "requiresCell" == "", "hasMonetaryCost" == "", "supportsAltitude" == "", "supportsSpeed" == "", 
	          "supportsBearing" == "", android.location.Criteria.POWER_LOW, android.location.Criteria.ACCURACY_FINE);
	    } 
	    Log.w(TAG, "Providers: " + manager.getAllProviders().toString());
 

6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:addTestProvider, getLastKnownLocation, setTestProviderEnabled, setTestProviderLocation
		      "mock locations"); 
		}			 
		 
		// Get the location manager 
		LocationManager locationManager = (LocationManager) this.getActivity().getSystemService(Service.LOCATION_SERVICE);
		locationManager.addTestProvider(LocationManager.GPS_PROVIDER, false, false, false, false, true, true, true, 0, 5);
		Location mockLocation = new Location(LocationManager.GPS_PROVIDER);
		mockLocation.setLatitude(10.0);
		mockLocation.setLongitude(100.0);
		mockLocation.setTime(System.currentTimeMillis());
		locationManager.setTestProviderEnabled(LocationManager.GPS_PROVIDER, true);
	    locationManager.setTestProviderLocation(LocationManager.GPS_PROVIDER, mockLocation);
		Location loc = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
		System.out.println(loc.getLatitude() + "   " + loc.getLongitude());
	    assertEquals(10.0, loc.getLatitude());
	    assertEquals(100.0, loc.getLongitude());
	} 
} 
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:addTestProvider, removeTestProvider, setTestProviderEnabled, setTestProviderLocation
	{ 
		double lat = 46.9513449;
		double lng = 7.4384537;
		Activity currentActivity = solo.getCurrentActivity();
		LocationManager testLocMgr = (LocationManager) currentActivity.getSystemService(Context.LOCATION_SERVICE);
		testLocMgr.addTestProvider("TestProvider", false, false, false, false, false, false, false,
			Criteria.POWER_LOW, Criteria.ACCURACY_FINE);
		testLocMgr.setTestProviderEnabled("TestProvider", true);
 
		// Set up test 
		Location location = new Location("TestProvider");
		location.setLatitude(lat);
		location.setLongitude(lng);
		testLocMgr.setTestProviderLocation("TestProvider", location);
 
		// Check if your listener reacted the right way 
		double currentLatitude = ((ch.eonum.HealthActivity) currentActivity).getLocation().getLatitude();
		double currentLongitude = ((ch.eonum.HealthActivity) currentActivity).getLocation().getLongitude();
 
		assertEquals(lat, currentLatitude);

6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:addTestProvider, getLastKnownLocation, requestLocationUpdates, setTestProviderEnabled, setTestProviderLocation
	public void testPreconditions() { 
		assertNotNull(getActivity());
	} 
 
	public void testAddingLocationToATask() { 
		manager.addTestProvider(MOCK_GPS_PROVIDER, false, false, false, false,
				true, true, true, 0, 5); 
 
		// Setting a fake location to the mock provider 
		Location location = new Location(MOCK_GPS_PROVIDER);
		location.setLatitude(42.0);
		location.setLongitude(1337.0);
		location.setTime(System.currentTimeMillis()); // necessary to wake up
														// LocationListener 
		manager.setTestProviderLocation(MOCK_GPS_PROVIDER, location);
 
		// Enable mock provider 
		manager.setTestProviderEnabled(MOCK_GPS_PROVIDER, true);
 
		// Getting location updates 

7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:addTestProvider, getProvider, removeTestProvider, requestLocationUpdates, setTestProviderEnabled
	 */ 
	public static void publishMockLocation(double latitude, double longitude, Context context, ArrayList<CheckPoint> checkPoints,
			MapLocationListener locationListener)
	{ 
		LocationManager locationManager = (LocationManager) context.getSystemService(Service.LOCATION_SERVICE);
		if (locationManager.getProvider(PROVIDER_NAME) != null)
		{ 
			locationManager.removeTestProvider(PROVIDER_NAME);
		} 
		if (locationManager.getProvider(PROVIDER_NAME) == null)
		{ 
			locationManager.addTestProvider(PROVIDER_NAME, "requiresNetwork" == "", "requiresSatellite" == "", "requiresCell" == "",
					"hasMonetaryCost" == "", "supportsAltitude" == "", "supportsSpeed" == "", "supportsBearing" == "", 
					android.location.Criteria.POWER_LOW, android.location.Criteria.ACCURACY_FINE);
		} 
 
		Location newLocation = new Location(PROVIDER_NAME);
		newLocation.setLatitude(latitude);
		newLocation.setLongitude(longitude);
		newLocation.setTime(System.currentTimeMillis());

6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:addTestProvider, removeTestProvider, setTestProviderEnabled, setTestProviderLocation
	public void testLocationService() 
	{ 
		double lat = 46.9513449;
		double lng = 7.4384537;
		LocationManager testLocMgr = (LocationManager) this.mActivity.getSystemService(Context.LOCATION_SERVICE);
		testLocMgr.addTestProvider("TestProvider", false, false, false, false, false, false, false,
			Criteria.POWER_LOW, Criteria.ACCURACY_FINE);
		testLocMgr.setTestProviderEnabled("TestProvider", true);
 
		// Set up test 
 
		Location location = new Location("TestProvider");
		location.setLatitude(lat);
		location.setLongitude(lng);
		testLocMgr.setTestProviderLocation("TestProvider", location);
 
		// Check if your listener reacted the right way 
		double currentLatitude = mActivity.getLocation().getLatitude();
		double currentLongitude = mActivity.getLocation().getLongitude();
 

6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:addTestProvider, getProvider, requestLocationUpdates, setTestProviderEnabled
 
		locationManager = (LocationManager) activity.getSystemService(Context.LOCATION_SERVICE);
 
		if (mockStatus) {
 
			if (locationManager.getProvider("testProvider") == null) {
				locationManager.addTestProvider("testProvider", false, true, false, false, true, true, false, 0, 5);
			} 
			locationManager.setTestProviderEnabled("testProvider", true);
 
			locationManager.requestLocationUpdates("testProvider", 1000, 0, location);
 
			// locationManager.setTestProviderStatus("testProvider", 
			// LocationProvider.AVAILABLE, null, System.currentTimeMillis()); 
 
		} else { 
 
			locationManager.requestLocationUpdates(locationManager.GPS_PROVIDER, 1000, 0, location);
 
		} 
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java

Related LocationManager addTestProvider Questions & Answers:

addTestProvider Method Overview
Creates a mock location provider and adds it to the set of active providers.
See Code Examples for other Android LocationManager Methods: