android.location.Criteria Java Examples

The following examples show how to use android.location.Criteria. 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 Project: android_9.0.0_r45   Author: lulululbj   File: LocationManagerService.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Return the name of the best provider given a Criteria object.
 * This method has been deprecated from the public API,
 * and the whole LocationProvider (including #meetsCriteria)
 * has been deprecated as well. So this method now uses
 * some simplified logic.
 */
@Override
public String getBestProvider(Criteria criteria, boolean enabledOnly) {
    String result = null;

    List<String> providers = getProviders(criteria, enabledOnly);
    if (!providers.isEmpty()) {
        result = pickBest(providers);
        if (D) Log.d(TAG, "getBestProvider(" + criteria + ", " + enabledOnly + ")=" + result);
        return result;
    }
    providers = getProviders(null, enabledOnly);
    if (!providers.isEmpty()) {
        result = pickBest(providers);
        if (D) Log.d(TAG, "getBestProvider(" + criteria + ", " + enabledOnly + ")=" + result);
        return result;
    }

    if (D) Log.d(TAG, "getBestProvider(" + criteria + ", " + enabledOnly + ")=" + result);
    return null;
}
 
Example #2
Source Project: Complete-Google-Map-API-Tutorial   Author: mohammadima3oud   File: MyLocationActivity.java    License: Apache License 2.0 6 votes vote down vote up
private void goToMyLocation()
{
	if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED &&
			ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED)
	{
		enableMyLocation();
	} else
	{
		googleMap.setMyLocationEnabled(true);
		LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
		Criteria criteria = new Criteria();
		Location location = locationManager.getLastKnownLocation(locationManager.getBestProvider(criteria, false));
		if (location != null)
		{
			googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(location.getLatitude(), location.getLongitude()), 13));
		}
	}
}
 
Example #3
Source Project: DevUtils   Author: afkT   File: LocationUtils.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 获取定位参数对象
 * @return {@link Criteria}
 */
private static Criteria getCriteria() {
    Criteria criteria = new Criteria();
    // 设置定位精确度 Criteria.ACCURACY_COARSE 比较粗略, Criteria.ACCURACY_FINE 则比较精细
    criteria.setAccuracy(Criteria.ACCURACY_FINE);
    // 设置是否要求速度
    criteria.setSpeedRequired(false);
    // 设置是否允许运营商收费
    criteria.setCostAllowed(false);
    // 设置是否需要方位信息
    criteria.setBearingRequired(false);
    // 设置是否需要海拔信息
    criteria.setAltitudeRequired(false);
    // 设置对电源的需求
    criteria.setPowerRequirement(Criteria.POWER_LOW);
    return criteria;
}
 
Example #4
Source Project: background-geolocation-android   Author: mauron85   File: DistanceFilterLocationProvider.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Translates a number representing desired accuracy of Geolocation system from set [0, 10, 100, 1000].
 * 0:  most aggressive, most accurate, worst battery drain
 * 1000:  least aggressive, least accurate, best for battery.
 */
private Integer translateDesiredAccuracy(Integer accuracy) {
    if (accuracy >= 1000) {
        return Criteria.ACCURACY_LOW;
    }
    if (accuracy >= 100) {
        return Criteria.ACCURACY_MEDIUM;
    }
    if (accuracy >= 10) {
        return Criteria.ACCURACY_HIGH;
    }
    if (accuracy >= 0) {
        return Criteria.ACCURACY_HIGH;
    }

    return Criteria.ACCURACY_MEDIUM;
}
 
Example #5
Source Project: background-geolocation-android   Author: mauron85   File: DistanceFilterLocationProvider.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent)
{
    logger.info("Stationary location monitor fired");
    playDebugTone(Tone.DIALTONE);

    criteria.setAccuracy(Criteria.ACCURACY_FINE);
    criteria.setHorizontalAccuracy(Criteria.ACCURACY_HIGH);
    criteria.setPowerRequirement(Criteria.POWER_HIGH);

    try {
        locationManager.requestSingleUpdate(criteria, singleUpdatePI);
    } catch (SecurityException e) {
        logger.error("Security exception: {}", e.getMessage());
    }
}
 
Example #6
Source Project: background-geolocation-android   Author: mauron85   File: RawLocationProvider.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void onStart() {
    if (isStarted) {
        return;
    }

    Criteria criteria = new Criteria();
    criteria.setAltitudeRequired(false);
    criteria.setBearingRequired(false);
    criteria.setSpeedRequired(true);
    criteria.setCostAllowed(true);
    criteria.setAccuracy(Criteria.ACCURACY_FINE);
    criteria.setHorizontalAccuracy(translateDesiredAccuracy(mConfig.getDesiredAccuracy()));
    criteria.setPowerRequirement(Criteria.POWER_HIGH);

    try {
        locationManager.requestLocationUpdates(locationManager.getBestProvider(criteria, true), mConfig.getInterval(), mConfig.getDistanceFilter(), this);
        isStarted = true;
    } catch (SecurityException e) {
        logger.error("Security exception: {}", e.getMessage());
        this.handleSecurityException(e);
    }
}
 
Example #7
Source Project: background-geolocation-android   Author: mauron85   File: RawLocationProvider.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Translates a number representing desired accuracy of Geolocation system from set [0, 10, 100, 1000].
 * 0:  most aggressive, most accurate, worst battery drain
 * 1000:  least aggressive, least accurate, best for battery.
 */
private Integer translateDesiredAccuracy(Integer accuracy) {
    if (accuracy >= 1000) {
        return Criteria.ACCURACY_LOW;
    }
    if (accuracy >= 100) {
        return Criteria.ACCURACY_MEDIUM;
    }
    if (accuracy >= 10) {
        return Criteria.ACCURACY_HIGH;
    }
    if (accuracy >= 0) {
        return Criteria.ACCURACY_HIGH;
    }

    return Criteria.ACCURACY_MEDIUM;
}
 
Example #8
Source Project: Android-UtilCode   Author: hoangkien0705   File: LocationUtils.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 设置定位参数
 *
 * @return {@link Criteria}
 */
private static Criteria getCriteria() {
    Criteria criteria = new Criteria();
    // 设置定位精确度 Criteria.ACCURACY_COARSE比较粗略,Criteria.ACCURACY_FINE则比较精细
    criteria.setAccuracy(Criteria.ACCURACY_FINE);
    // 设置是否要求速度
    criteria.setSpeedRequired(false);
    // 设置是否允许运营商收费
    criteria.setCostAllowed(false);
    // 设置是否需要方位信息
    criteria.setBearingRequired(false);
    // 设置是否需要海拔信息
    criteria.setAltitudeRequired(false);
    // 设置对电源的需求
    criteria.setPowerRequirement(Criteria.POWER_LOW);
    return criteria;
}
 
Example #9
Source Project: RxTools-master   Author: duboAndroid   File: RxLocationTool.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 设置定位参数
 *
 * @return {@link Criteria}
 */
private static Criteria getCriteria() {
    Criteria criteria = new Criteria();
    //设置定位精确度 Criteria.ACCURACY_COARSE比较粗略,Criteria.ACCURACY_FINE则比较精细
    criteria.setAccuracy(Criteria.ACCURACY_FINE);
    //设置是否要求速度
    criteria.setSpeedRequired(false);
    // 设置是否允许运营商收费
    criteria.setCostAllowed(false);
    //设置是否需要方位信息
    criteria.setBearingRequired(false);
    //设置是否需要海拔信息
    criteria.setAltitudeRequired(false);
    // 设置对电源的需求
    criteria.setPowerRequirement(Criteria.POWER_LOW);
    return criteria;
}
 
Example #10
Source Project: open-quartz   Author: jaredsburrows   File: LocationProvider.java    License: Apache License 2.0 6 votes vote down vote up
public LocationProvider(Context context) {
    mLocationManager = (LocationManager) context
            .getSystemService(Context.LOCATION_SERVICE);
    mGeocoder = new Geocoder(context);

    final Criteria criteria = new Criteria();
    mBestProvider = mLocationManager.getBestProvider(criteria,
            true);

    final List<String> providers = mLocationManager.getProviders(
            criteria, true);

    for (String provider : providers) {
        // mLocationManager.requestLocationUpdates(provider, 0, 0, this);
    }
}
 
Example #11
Source Project: letv   Author: JackChan1999   File: Util.java    License: Apache License 2.0 6 votes vote down vote up
public static String getLocation(Context context) {
    if (context == null) {
        return "";
    }
    try {
        LocationManager locationManager = (LocationManager) context.getSystemService(HOME_RECOMMEND_PARAMETERS.LOCATION);
        Criteria criteria = new Criteria();
        criteria.setCostAllowed(false);
        criteria.setAccuracy(2);
        String bestProvider = locationManager.getBestProvider(criteria, true);
        if (bestProvider != null) {
            Location lastKnownLocation = locationManager.getLastKnownLocation(bestProvider);
            if (lastKnownLocation == null) {
                return "";
            }
            double latitude = lastKnownLocation.getLatitude();
            g = latitude + "*" + lastKnownLocation.getLongitude();
            return g;
        }
    } catch (Throwable e) {
        f.b("getLocation", "getLocation>>>", e);
    }
    return "";
}
 
Example #12
Source Project: appinventor-extensions   Author: mit-cml   File: LocationSensor.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new LocationSensor component with a default state of <code>enabled</code>.
 *
 * @param container  ignored (because this is a non-visible component)
 * @param enabled  true if the LocationSensor is enabled by default, otherwise false.
 */
public LocationSensor(ComponentContainer container, boolean enabled) {
  super(container.$form());
  this.enabled = enabled;
  handler = new Handler();
  // Set up listener
  form.registerForOnResume(this);
  form.registerForOnStop(this);

  // Initialize sensor properties (60 seconds; 5 meters)
  timeInterval = 60000;
  distanceInterval = 5;

  // Initialize location-related fields
  Context context = container.$context();
  geocoder = new Geocoder(context);
  locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
  locationCriteria = new Criteria();
  myLocationListener = new MyLocationListener();
  allProviders = new ArrayList<String>();
  // Do some initialization depending on the initial enabled state
  Enabled(enabled);
}
 
Example #13
Source Project: OsmGo   Author: DoFabien   File: Geolocation.java    License: MIT License 6 votes vote down vote up
/**
 * Given the call's options, return a Criteria object
 * that will indicate which location provider we need to use.
 * @param call
 * @return
 */
private Criteria getCriteriaForCall(PluginCall call) {
  boolean enableHighAccuracy = call.getBoolean("enableHighAccuracy", false);
  boolean altitudeRequired = call.getBoolean("altitudeRequired", false);
  boolean speedRequired = call.getBoolean("speedRequired", false);
  boolean bearingRequired = call.getBoolean("bearingRequired", false);

  int timeout = call.getInt("timeout", 30000);
  int maximumAge = call.getInt("maximumAge", 0);

  Criteria c = new Criteria();
  c.setAccuracy(enableHighAccuracy ? Criteria.ACCURACY_FINE : Criteria.ACCURACY_COARSE);
  c.setAltitudeRequired(altitudeRequired);
  c.setBearingRequired(bearingRequired);
  c.setSpeedRequired(speedRequired);
  return c;
}
 
Example #14
Source Project: AndroidUtilCode   Author: Blankj   File: LocationUtils.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 设置定位参数
 *
 * @return {@link Criteria}
 */
private static Criteria getCriteria() {
    Criteria criteria = new Criteria();
    // 设置定位精确度 Criteria.ACCURACY_COARSE比较粗略,Criteria.ACCURACY_FINE则比较精细
    criteria.setAccuracy(Criteria.ACCURACY_FINE);
    // 设置是否要求速度
    criteria.setSpeedRequired(false);
    // 设置是否允许运营商收费
    criteria.setCostAllowed(false);
    // 设置是否需要方位信息
    criteria.setBearingRequired(false);
    // 设置是否需要海拔信息
    criteria.setAltitudeRequired(false);
    // 设置对电源的需求
    criteria.setPowerRequirement(Criteria.POWER_LOW);
    return criteria;
}
 
Example #15
Source Project: AsteroidOSSync   Author: AsteroidOS   File: GPSTracker.java    License: GNU General Public License v3.0 6 votes vote down vote up
public void updateLocation() {
    try {
        mLocationManager = (LocationManager) mContext
                .getSystemService(LOCATION_SERVICE);

        Criteria criteria = new Criteria();
        criteria.setAccuracy(Criteria.ACCURACY_LOW);
        criteria.setSpeedRequired(false);
        criteria.setAltitudeRequired(false);
        criteria.setBearingRequired(false);
        criteria.setCostAllowed(true);
        criteria.setPowerRequirement(Criteria.POWER_LOW);
        String provider = mLocationManager.getBestProvider(criteria, true);
        if(provider != null) {
            mLocationManager.requestSingleUpdate(provider, this, null);
            mCanGetLocation = true;
        }
    }
    catch (SecurityException | NullPointerException e) {
        e.printStackTrace();
    }
}
 
Example #16
Source Project: MobileGuard   Author: ittianyu   File: GpsTraceService.java    License: MIT License 6 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();

    // locate
    locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    // check permission
    if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
        return;
    }

    // get best provider
    Criteria criteria = new Criteria();
    criteria.setCostAllowed(true);
    criteria.setAccuracy(Criteria.ACCURACY_FINE);
    String bestProvider = locationManager.getBestProvider(criteria, true);
    System.out.println("best provider:" + bestProvider);
    // start listening
    listener = new MyLocationListener();
    locationManager.requestLocationUpdates(bestProvider, 0, 0, listener);
}
 
Example #17
Source Project: codeexamples-android   Author: vogellacompany   File: ShowLocationActivity.java    License: Eclipse Public License 1.0 6 votes vote down vote up
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.main);
	latituteField = (TextView) findViewById(R.id.TextView02);
	longitudeField = (TextView) findViewById(R.id.TextView04);

	// Get the location manager
	locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
	// Define the criteria how to select the locatioin provider -> use
	// default
	Criteria criteria = new Criteria();
	provider = locationManager.getBestProvider(criteria, false);
	Location location = locationManager.getLastKnownLocation(provider);

	// Initialize the location fields
	if (location != null) {
		System.out.println("Provider " + provider + " has been selected.");
		onLocationChanged(location);
	} else {
		latituteField.setText("Location not available");
		longitudeField.setText("Location not available");
	}
}
 
Example #18
Source Project: Acastus   Author: DanielBarnett714   File: GeoLocation.java    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
public void updateLocation(){
    Criteria criteria = new Criteria();
    String bestProvider = String.valueOf(locationManager.getBestProvider(criteria, true)).toString();
    try {
        locationManager.requestLocationUpdates(bestProvider, 60000, 15, this);
        Handler h = new Handler(Looper.getMainLooper());
        h.post(new Runnable() {
            public void run() {
                Toast.makeText(context, R.string.accessing_location, Toast.LENGTH_SHORT).show();
            }
        });
    }catch (SecurityException e){

    }

}
 
Example #19
Source Project: lunzi   Author: macouen   File: MapLocationUtil.java    License: Apache License 2.0 6 votes vote down vote up
private String getProvider(LocationManager locationManager) {
    // 构建位置查询条件
    Criteria criteria = new Criteria();
    // 查询精度:高
    criteria.setAccuracy(Criteria.ACCURACY_FINE);
    // 速度
    criteria.setSpeedRequired(false);
    // 是否查询海拨:否
    criteria.setAltitudeRequired(false);
    // 是否查询方位角:否
    criteria.setBearingRequired(false);
    // 电量要求:低
    criteria.setPowerRequirement(Criteria.POWER_LOW);
    // 返回最合适的符合条件的provider,第2个参数为true说明,如果只有一个provider是有效的,则返回当前provider
    return locationManager.getBestProvider(criteria, true);
}
 
Example #20
Source Project: DeviceConnect-Android   Author: DeviceConnect   File: HostGeolocationProfile.java    License: MIT License 6 votes vote down vote up
/**
 * 位置情報取得開始.
 * @param accuracy 精度.
 * @param interval 受信間隔.
 */
private void startGPS(final boolean accuracy, final int interval) {
    if (ActivityCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
            && ActivityCompat.checkSelfPermission(getContext(), ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
        return;
    }

    Criteria criteria = new Criteria();
    if (accuracy) {
        criteria.setAccuracy(Criteria.ACCURACY_FINE);
    } else {
        criteria.setAccuracy(Criteria.ACCURACY_COARSE);
    }

    mLocationManager.requestLocationUpdates(mLocationManager.getBestProvider(criteria, true), interval, 0, this, Looper.getMainLooper());
}
 
Example #21
Source Project: medic-android   Author: medic   File: MedicAndroidJavascript.java    License: GNU Affero General Public License v3.0 6 votes vote down vote up
@Deprecated
@org.xwalk.core.JavascriptInterface
@android.webkit.JavascriptInterface
@SuppressLint("MissingPermission") // handled by catch(Exception)
/**
 * @deprecated Location should be fetched directly from the browser.
 * @see https://github.com/medic/medic-webapp/issues/3781
 */
public String getLocation() {
	try {
		if(locationManager == null) return jsonError("LocationManager not set.  Cannot retrieve location.");

		String provider = locationManager.getBestProvider(new Criteria(), true);
		if(provider == null) return jsonError("No location provider available.");

		Location loc = locationManager.getLastKnownLocation(provider);

		if(loc == null) return jsonError("Provider '" + provider + "' did not provide a location.");

		return new JSONObject()
				.put("lat", loc.getLatitude())
				.put("long", loc.getLongitude())
				.toString();
	} catch(Exception ex) {
		return jsonError("Problem fetching location: ", ex);
	}
}
 
Example #22
Source Project: redalert-android   Author: eladnava   File: LocationLogic.java    License: Apache License 2.0 6 votes vote down vote up
public static Location GetLastKnownLocation(Context context) {
    // Get location manager
    LocationManager locationManager = (LocationManager) context.getSystemService(context.LOCATION_SERVICE);

    // Create location criteria
    Criteria criteria = new Criteria();

    // Set fine accuracy
    criteria.setAccuracy(criteria.ACCURACY_FINE);

    // Get best provider
    String bestProvider = locationManager.getBestProvider(criteria, false);

    // No provider?
    if (bestProvider == null) {
        // Return null
        return null;
    }

    // Return last location
    return locationManager.getLastKnownLocation(bestProvider);
}
 
Example #23
Source Project: android_external_GmsLib   Author: microg   File: NativeLocationClientImpl.java    License: Apache License 2.0 6 votes vote down vote up
private static Criteria makeNativeCriteria(LocationRequest request) {
    Criteria criteria = new Criteria();
    switch (request.getPriority()) {
        case LocationRequest.PRIORITY_HIGH_ACCURACY:
            criteria.setAccuracy(Criteria.ACCURACY_FINE);
            criteria.setPowerRequirement(Criteria.POWER_HIGH);
            break;
        case LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY:
        default:
            criteria.setAccuracy(Criteria.ACCURACY_COARSE);
            criteria.setPowerRequirement(Criteria.POWER_MEDIUM);
            break;
        case LocationRequest.PRIORITY_NO_POWER:
        case LocationRequest.PRIORITY_LOW_POWER:
            criteria.setAccuracy(Criteria.ACCURACY_COARSE);
            criteria.setPowerRequirement(Criteria.POWER_LOW);
    }
    return criteria;
}
 
Example #24
Source Project: al-muazzin   Author: ozbek   File: Preferences.java    License: GNU Lesser General Public License v2.1 6 votes vote down vote up
public Location getCurrentLocation(Context context) {
    Criteria criteria = new Criteria();
    criteria.setAccuracy(Criteria.ACCURACY_FINE);
    criteria.setCostAllowed(true);

    LocationManager locationManager = (LocationManager) context
            .getSystemService(Context.LOCATION_SERVICE);
    try {
        Location currentLocation = locationManager.getLastKnownLocation(locationManager
                .getBestProvider(criteria, true));
        if (currentLocation == null) {
            criteria.setAccuracy(Criteria.ACCURACY_COARSE);
            currentLocation = locationManager.getLastKnownLocation(locationManager
                    .getBestProvider(criteria, true));
        }
        return currentLocation;
    } catch (IllegalArgumentException iae) {
        return null;
    }
}
 
Example #25
Source Project: open-quartz   Author: jaredsburrows   File: ChronometerView.java    License: Apache License 2.0 6 votes vote down vote up
public ChronometerView(Context context) {
    this(context, null, 0);

    final StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
            .permitAll().build();
    StrictMode.setThreadPolicy(policy);

    locationManager = (LocationManager) context
            .getSystemService(Context.LOCATION_SERVICE);
    geocoder = new Geocoder(context);

    criteria = new Criteria();
    best = locationManager.getBestProvider(criteria, true);
    location = locationManager.getLastKnownLocation(best);

    providers = locationManager.getProviders(criteria, true);

    for (String provider : providers) {
        locationManager.requestLocationUpdates(provider, 0, 0, this);
        Log.e("TAG", "" + provider);
    }

}
 
Example #26
Source Project: android_packages_apps_GmsCore   Author: microg   File: GoogleMapImpl.java    License: Apache License 2.0 6 votes vote down vote up
private GoogleMapImpl(Context context, GoogleMapOptions options) {
    this.context = context;
    Context appContext = context;
    if (appContext.getApplicationContext() != null)
        appContext = appContext.getApplicationContext();
    Context wrappedContext = ApplicationContextWrapper.gmsContextWithAttachedApplicationContext(appContext);
    backendMap = new BackendMap(wrappedContext, this);
    uiSettings = new UiSettingsImpl(this);
    projection = new ProjectionImpl(backendMap.getViewport());
    this.options = options;

    criteria = new Criteria();
    criteria.setAccuracy(Criteria.ACCURACY_COARSE);
    criteria.setPowerRequirement(Criteria.POWER_MEDIUM);

    if (options != null) initFromOptions();
}
 
Example #27
Source Project: android_9.0.0_r45   Author: lulululbj   File: LocationManagerService.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Return all providers by name, that match criteria and are optionally
 * enabled.
 * Can return passive provider, but never returns fused provider.
 */
@Override
public List<String> getProviders(Criteria criteria, boolean enabledOnly) {
    int allowedResolutionLevel = getCallerAllowedResolutionLevel();
    ArrayList<String> out;
    int uid = Binder.getCallingUid();
    long identity = Binder.clearCallingIdentity();
    try {
        synchronized (mLock) {
            out = new ArrayList<>(mProviders.size());
            for (LocationProviderInterface provider : mProviders) {
                String name = provider.getName();
                if (LocationManager.FUSED_PROVIDER.equals(name)) {
                    continue;
                }
                if (allowedResolutionLevel >= getMinimumResolutionLevelForProviderUse(name)) {
                    if (enabledOnly
                            && !isAllowedByUserSettingsLocked(name, uid, mCurrentUserId)) {
                        continue;
                    }
                    if (criteria != null && !LocationProvider.propertiesMeetCriteria(
                            name, provider.getProperties(), criteria)) {
                        continue;
                    }
                    out.add(name);
                }
            }
        }
    } finally {
        Binder.restoreCallingIdentity(identity);
    }

    if (D) Log.d(TAG, "getProviders()=" + out);
    return out;
}
 
Example #28
Source Project: android_9.0.0_r45   Author: lulululbj   File: LocationManagerService.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean providerMeetsCriteria(String provider, Criteria criteria) {
    LocationProviderInterface p = mProvidersByName.get(provider);
    if (p == null) {
        throw new IllegalArgumentException("provider=" + provider);
    }

    boolean result = LocationProvider.propertiesMeetCriteria(
            p.getName(), p.getProperties(), criteria);
    if (D) Log.d(TAG, "providerMeetsCriteria(" + provider + ", " + criteria + ")=" + result);
    return result;
}
 
Example #29
Source Project: privatelocation   Author: wesaphzt   File: LocationProvider.java    License: GNU General Public License v3.0 5 votes vote down vote up
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 #30
Source Project: WhereYouGo   Author: cgeo   File: MyLocationOverlay.java    License: GNU General Public License v3.0 5 votes vote down vote up
private synchronized boolean enableBestAvailableProvider() {
    disableMyLocation();

    Criteria criteria = new Criteria();
    criteria.setAccuracy(Criteria.ACCURACY_FINE);
    String bestAvailableProvider = this.locationManager.getBestProvider(criteria, true);
    if (bestAvailableProvider == null) {
        return false;
    }
    this.lastLocation = this.locationManager.getLastKnownLocation(bestAvailableProvider);
    this.locationManager.requestLocationUpdates(bestAvailableProvider, UPDATE_INTERVAL,
            UPDATE_DISTANCE, this);
    this.myLocationEnabled = true;
    return true;
}