Example usage for android.location Criteria NO_REQUIREMENT

List of usage examples for android.location Criteria NO_REQUIREMENT

Introduction

In this page you can find the example usage for android.location Criteria NO_REQUIREMENT.

Prototype

int NO_REQUIREMENT

To view the source code for android.location Criteria NO_REQUIREMENT.

Click Source Link

Document

A constant indicating that the application does not choose to place requirement on a particular feature.

Usage

From source file:Main.java

public static String getBestProvider(LocationManager locationManager) throws IllegalArgumentException {
    Criteria criteria = new Criteria();
    criteria.setAccuracy(Criteria.ACCURACY_FINE);
    criteria.setPowerRequirement(Criteria.NO_REQUIREMENT);

    return locationManager.getBestProvider(criteria, true);
}

From source file:ch.hesso.master.sweetcity.activity.report.ReportActivity.java

void updateCurrentLocation() {
    if (this.locationListener == null)
        this.locationListener = new LocationListener() {
            @Override/*from   w  w w.  j  a va2  s . com*/
            public void onLocationChanged(Location location) {
                ReportActivity.this.currentLocation = location;
            }

            @Override
            public void onProviderDisabled(String provider) {
            }

            @Override
            public void onProviderEnabled(String provider) {
            }

            @Override
            public void onStatusChanged(String provider, int status, Bundle extras) {
            }
        };

    Criteria criteria = new Criteria();
    criteria.setAccuracy(Criteria.ACCURACY_COARSE);
    criteria.setAltitudeRequired(false);
    criteria.setBearingRequired(false);
    criteria.setCostAllowed(false);
    criteria.setHorizontalAccuracy(Criteria.ACCURACY_MEDIUM);
    criteria.setPowerRequirement(Criteria.NO_REQUIREMENT);
    criteria.setSpeedAccuracy(Criteria.NO_REQUIREMENT);
    criteria.setSpeedRequired(false);

    LocationManager locationManager = (LocationManager) ReportActivity.this.getSystemService(LOCATION_SERVICE);
    locationManager.requestSingleUpdate(criteria, this.locationListener, null);
}

From source file:com.quantcast.measurement.service.QCLocation.java

void setupLocManager(Context appContext) {
    if (appContext == null)
        return;/* w  w w .j  a  v a 2 s  .c om*/

    _locManager = (LocationManager) appContext.getSystemService(Context.LOCATION_SERVICE);
    if (_locManager != null) {
        //specifically set our Criteria. All we need is a general location
        Criteria criteria = new Criteria();
        criteria.setAccuracy(Criteria.ACCURACY_COARSE);
        criteria.setAltitudeRequired(false);
        criteria.setBearingRequired(false);
        criteria.setCostAllowed(false);
        criteria.setPowerRequirement(Criteria.NO_REQUIREMENT);
        criteria.setSpeedRequired(false);

        _myProvider = _locManager.getBestProvider(criteria, true);

        _geocoder = new Geocoder(appContext);
    }
    QCLog.i(TAG, "Setting location provider " + _myProvider);
}

From source file:com.mobilevangelist.glass.helloworld.GetTheWeatherActivity.java

public static Location getLastLocation(Context context) {
    Location result = null;//w ww.  ja va2s .  c om
    LocationManager locationManager;
    Criteria locationCriteria;
    List<String> providers;

    locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
    locationCriteria = new Criteria();
    locationCriteria.setAccuracy(Criteria.NO_REQUIREMENT);
    providers = locationManager.getProviders(locationCriteria, true);

    // Note that providers = locatoinManager.getAllProviders(); is not used because the
    // list might contain disabled providers or providers that are not allowed to be called.

    //Note that getAccuracy can return 0, indicating that there is no known accuracy.

    for (String provider : providers) {
        Location location = locationManager.getLastKnownLocation(provider);
        if (result == null) {
            result = location;
        } else if (result.getAccuracy() == 0.0) {
            if (location.getAccuracy() != 0.0) {
                result = location;
                break;
            } else {
                if (result.getAccuracy() > location.getAccuracy()) {
                    result = location;
                }
            }
        }
    }

    return result;
}

From source file:com.fpil.android.remotesensor.MainDisplay.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    locationManager = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE);

    Criteria locationCriteria = new Criteria();
    locationCriteria.setAccuracy(Criteria.ACCURACY_FINE);
    locationCriteria.setAltitudeRequired(false);
    locationCriteria.setBearingRequired(false);
    locationCriteria.setCostAllowed(true);
    locationCriteria.setPowerRequirement(Criteria.NO_REQUIREMENT);

    locationProviderName = locationManager.getBestProvider(locationCriteria, true);

    if (ActivityCompat.checkSelfPermission(getActivity(),
            Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
            && ActivityCompat.checkSelfPermission(getActivity(),
                    Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
        Toast.makeText(getActivity(), R.string.turn_on_gps, Toast.LENGTH_LONG).show();
        Intent myIntent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
        this.startActivity(myIntent);
    }//from  w  w w  .j a  va2  s  .  c o  m

    if (locationProviderName != null && locationManager.isProviderEnabled(locationProviderName)) {
        // Provider is enabled
        Toast.makeText(getActivity(), R.string.gps_available, Toast.LENGTH_LONG).show();
    } else {
        // Provider not enabled, prompt user to enable it
        Toast.makeText(getActivity(), R.string.turn_on_gps, Toast.LENGTH_LONG).show();
        Intent myIntent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
        this.startActivity(myIntent);
    }
}

From source file:ch.hesso.master.sweetcity.activity.map.MapActivity.java

public void showCurrentPosition() {
    if (map == null)
        return;//from  w  w  w.j a  va2  s.  co m

    // Enabling MyLocation Layer of Google Map
    map.setMyLocationEnabled(true);

    Criteria lightCriteria = new Criteria();
    lightCriteria.setAccuracy(Criteria.ACCURACY_COARSE);
    lightCriteria.setAltitudeRequired(false);
    lightCriteria.setBearingRequired(false);
    lightCriteria.setCostAllowed(false);
    lightCriteria.setHorizontalAccuracy(Criteria.ACCURACY_MEDIUM);
    lightCriteria.setPowerRequirement(Criteria.NO_REQUIREMENT);
    lightCriteria.setSpeedAccuracy(Criteria.NO_REQUIREMENT);
    lightCriteria.setSpeedRequired(false);

    listener = new MapLocationListener(map);

    locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
    locationManager.requestSingleUpdate(lightCriteria, listener, null);
    locationProvider = locationManager.getBestProvider(new Criteria(), true);
    Location location = locationManager.getLastKnownLocation(locationProvider);

    if (location != null) {
        listener.onLocationChanged(location);
        map.animateCamera(CameraUpdateFactory.zoomTo(15));
    }
}

From source file:org.wso2.edgeanalyticsservice.LocationSystemService.java

/** Initialize the location system Service and set the minimal update distance and time  */
public void startLocationService(Context context) {
    mContext = context;/* w  ww .  ja  v  a 2s .c  om*/
    mLocationManager = (LocationManager) mContext.getSystemService(mContext.LOCATION_SERVICE);
    Criteria locationCritera = new Criteria();
    locationCritera.setAccuracy(Criteria.ACCURACY_COARSE);
    locationCritera.setAltitudeRequired(false);
    locationCritera.setBearingRequired(false);
    locationCritera.setCostAllowed(true);
    locationCritera.setPowerRequirement(Criteria.NO_REQUIREMENT);

    String providerName = mLocationManager.getBestProvider(locationCritera, true);

    if (providerName != null && mLocationManager.isProviderEnabled(providerName)) {
        if (ActivityCompat.checkSelfPermission(mContext,
                Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
                && ActivityCompat.checkSelfPermission(mContext,
                        Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
            // TODO: Consider calling
            //    ActivityCompat#requestPermissions
            // here to request the missing permissions, and then overriding
            //   public
            // void onRequestPermissionsResult(int requestCode, String[] permissions,
            //                                          int[] grantResults)
            // to handle the case where the user grants the permission. See the documentation
            // for ActivityCompat#requestPermissions for more details.
            Log.e("Location", "No permission");
            return;
        }
        mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, MINIMUM_TIME_BETWEEN_UPDATES,
                (float) MINIMUM_DISTANCE_FOR_UPDATES, new MyLocationListner(), Looper.getMainLooper());
        mLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, MINIMUM_TIME_BETWEEN_UPDATES,
                (float) MINIMUM_DISTANCE_FOR_UPDATES, new MyLocationListner(), Looper.getMainLooper());
        mlocation = mLocationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
        //        mTaskManager.sendLocationData(new double[]{mlocation.getLatitude(), mlocation.getLongitude()});
        mLocationListner = new MyLocationListner();
        synchronized (this) {
            started = true;
        }
    } else {
        // Provider not enabled, prompt user to enable it
        Toast.makeText(mContext, "Please turn on GPS", Toast.LENGTH_LONG).show();
        Intent myIntent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
        myIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        mContext.startActivity(myIntent);
    }
}

From source file:name.gumartinm.weather.information.activity.MapActivity.java

public void onClickGetLocation(final View v) {
    // TODO: Somehow I should show a progress dialog.
    // If Google Play Services is available
    if (this.mLocationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
        // TODO: Hopefully there will be results even if location did not change...   
        final Criteria criteria = new Criteria();
        criteria.setAccuracy(Criteria.ACCURACY_FINE);
        criteria.setAltitudeRequired(false);
        criteria.setBearingAccuracy(Criteria.NO_REQUIREMENT);
        criteria.setBearingRequired(false);
        criteria.setCostAllowed(false);/*from  w  ww . j a va 2  s. c  o m*/
        criteria.setHorizontalAccuracy(Criteria.ACCURACY_HIGH);
        criteria.setPowerRequirement(Criteria.POWER_MEDIUM);
        criteria.setSpeedAccuracy(Criteria.NO_REQUIREMENT);
        criteria.setSpeedRequired(false);
        criteria.setVerticalAccuracy(Criteria.ACCURACY_HIGH);

        this.mLocationManager.requestSingleUpdate(criteria, this, null);
    } else {
        Toast.makeText(this, this.getString(R.string.weather_map_not_enabled_location), Toast.LENGTH_LONG)
                .show();
    }
    // Trying to use the synchronous calls. Problems: mGoogleApiClient read/store from different threads.
    // new GetLocationTask(this).execute();
}

From source file:net.frakbot.FWeather.util.LocationHelper.java

/**
 * Returns the default criteria set for the LocationManager.
 * @return the default Criteria//from  www  .j  a  v a 2s .c  om
 */
private static Criteria getDefaultCriteria() {
    Criteria criteria = new Criteria();
    criteria.setCostAllowed(false);
    criteria.setHorizontalAccuracy(Criteria.ACCURACY_LOW);
    criteria.setVerticalAccuracy(Criteria.NO_REQUIREMENT);
    criteria.setSpeedRequired(false);
    criteria.setPowerRequirement(Criteria.POWER_LOW);

    return criteria;
}