Example usage for android.location LocationManager setTestProviderEnabled

List of usage examples for android.location LocationManager setTestProviderEnabled

Introduction

In this page you can find the example usage for android.location LocationManager setTestProviderEnabled.

Prototype

public void setTestProviderEnabled(String provider, boolean enabled) 

Source Link

Document

Sets a mock enabled value for the given provider.

Usage

From source file:org.cowboycoders.cyclisimo.turbo.TurboService.java

private void disableLocationProvider(String provider) {
    LocationManager locationManager = (LocationManager) getApplicationContext()
            .getSystemService(Context.LOCATION_SERVICE);
    if (locationManager.isProviderEnabled(provider)) {
        try {//from   w w w.  j  ava 2 s . c o  m
            // is this the same as the below? probably
            locationManager.setTestProviderEnabled(provider, false);
            locationManager.clearTestProviderEnabled(provider);
            locationManager.clearTestProviderLocation(provider);
            locationManager.clearTestProviderStatus(provider);
            locationManager.removeTestProvider(provider);
        } catch (SecurityException e) {
            // ignore 
        }
    }
}

From source file:org.cowboycoders.cyclisimo.turbo.TurboService.java

private boolean enableLocationProvider(String provider) {
    LocationManager locationManager = (LocationManager) getApplicationContext()
            .getSystemService(Context.LOCATION_SERVICE);
    if (locationManager.isProviderEnabled(provider)) {
        try {/*from w  w w . java2 s . c o  m*/
            locationManager.addTestProvider(provider, "requiresNetwork" == "", "requiresSatellite" == "",
                    "requiresCell" == "", "hasMonetaryCost" == "", "supportsAltitude" == "",
                    "supportsSpeed" == "", "supportsBearing" == "", android.location.Criteria.POWER_LOW,
                    android.location.Criteria.ACCURACY_FINE);

            locationManager.setTestProviderEnabled(provider, true);
            locationManager.setTestProviderStatus(provider, LocationProvider.AVAILABLE, null,
                    System.currentTimeMillis());
        } catch (SecurityException e) {
            handleException(e, "Error enabling location provider", true, NOTIFCATION_ID_STARTUP);
            return false;
        }
    } else {
        return false;
    }

    return true;
}