Example usage for android.location Criteria ACCURACY_COARSE

List of usage examples for android.location Criteria ACCURACY_COARSE

Introduction

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

Prototype

int ACCURACY_COARSE

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

Click Source Link

Document

A constant indicating an approximate accuracy requirement

Usage

From source file:Main.java

/**
 * this criteria will settle for less accuracy, high power, and cost
 *//*w  w w.j  a  v a2s .  c o m*/
public static Criteria createCoarseCriteria() {

    Criteria c = new Criteria();
    c.setAccuracy(Criteria.ACCURACY_COARSE);
    c.setAltitudeRequired(false);
    c.setBearingRequired(false);
    c.setSpeedRequired(false);
    c.setCostAllowed(true);
    c.setPowerRequirement(Criteria.POWER_HIGH);
    return c;

}

From source file:com.example.android.expandingcells.ExpandingCells.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // Get the location manager
    locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    // Define the criteria how to select the location provider
    criteria = new Criteria();
    criteria.setAccuracy(Criteria.ACCURACY_COARSE); //default

    criteria.setCostAllowed(false);/*from  w ww  . j  a v  a  2  s .c  om*/
    // get the best provider depending on the criteria
    provider = locationManager.getBestProvider(criteria, false);

    // the last known location of this provider
    Location location = locationManager.getLastKnownLocation(provider);

    mylistener = new MyLocationListener();

    if (location != null) {
        mylistener.onLocationChanged(location);
    } else {
        // leads to the settings because there is no last known location
        Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
        startActivity(intent);
    }
    // location updates: at least 1 meter and 200millsecs change
    //NETWORK_PROVIDER
    locationManager.requestLocationUpdates(provider, 200, 1, mylistener);

    this.NewsList = new ArrayList<News>(4);
    for (int i = 0; i < 4; i++) {
        NewsList.add(new News());
    }

    //Methods to populate the Object
    getColor();
    getHoroscope();
    getRaghukalam();
    //getWeather();

    //Log.d("DEBUG", Byte.getBody());
    Log.d("DEBUG", "Print");
    // Toast.makeText(this, Byte.size(), Toast.LENGTH_LONG).show();

    ExpandableListItem[] values = new ExpandableListItem[] {
            new ExpandableListItem("Color", R.drawable.mb_color, CELL_DEFAULT_HEIGHT,
                    NewsList.get(0).getBody()),
            new ExpandableListItem("Horoscope", R.drawable.mb_horoscope, CELL_DEFAULT_HEIGHT,
                    NewsList.get(1).getBody()),
            new ExpandableListItem("Raghukalam", R.drawable.mb_raghukalam, CELL_DEFAULT_HEIGHT,
                    NewsList.get(2).getBody()),
            new ExpandableListItem("Weather", R.drawable.mb_weather, CELL_DEFAULT_HEIGHT,
                    NewsList.get(3).getBody()), };

    List<ExpandableListItem> mData = new ArrayList<ExpandableListItem>();

    for (int i = 0; i < NUM_OF_CELLS; i++) {
        ExpandableListItem obj = values[i % values.length];
        mData.add(new ExpandableListItem(obj.getTitle(), obj.getImgResource(), obj.getCollapsedHeight(),
                obj.getText()));
    }

    // CustomArrayAdapter adapter = new CustomArrayAdapter(this, R.layout.list_view_item, mData);
    adapter = new CustomArrayAdapter(this, R.layout.list_view_item, mData);

    mListView = (ExpandingListView) findViewById(R.id.main_list_view);
    mListView.setAdapter(adapter);
    mListView.setDivider(null);
}

From source file:it.ms.theing.loquitur.functions.LocationInterface.java

private Location getLocation() {
    done = true;/*from   w w w.  j  a  v a2s.co  m*/
    long timeInMillis = Calendar.getInstance().getTimeInMillis();
    Criteria criteria = new Criteria();
    criteria.setAccuracy(Criteria.ACCURACY_FINE);
    String fine = locationManager.getBestProvider(criteria, true);
    if (fine == null)
        return null;
    Location location = locationManager.getLastKnownLocation(fine);
    if (location != null) {
        if (timeInMillis - location.getTime() < TIMEVAL) {
            return location;
        }
    }
    criteria.setAccuracy(Criteria.ACCURACY_COARSE);
    String coarse = locationManager.getBestProvider(criteria, true);
    if (!(fine.equals(coarse))) {
        location = locationManager.getLastKnownLocation(fine);
        if (location != null) {
            if (timeInMillis - location.getTime() < TIMEVAL) {
                return location;
            }
        }
    }
    timeout.postDelayed(tout, TIMEOUT); // At most 1 minute
    //locationManager.requestSingleUpdate(fine, ll, Looper.myLooper());
    locationManager.requestSingleUpdate(fine, ll, null);
    done = false;
    return null;
}

From source file:com.facebook.android.Places.java

public void getLocation() {
    /*//from  w  w  w .  j ava2s .c  o m
     * launch a new Thread to get new location
     */
    new Thread() {
        @Override
        public void run() {
            Looper.prepare();
            dialog = ProgressDialog.show(Places.this, "", getString(R.string.fetching_location), false, true,
                    new DialogInterface.OnCancelListener() {
                        @Override
                        public void onCancel(DialogInterface dialog) {
                            showToast("No location fetched.");
                        }
                    });

            if (lm == null) {
                lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
            }

            if (locationListener == null) {
                locationListener = new MyLocationListener();
            }

            Criteria criteria = new Criteria();
            criteria.setAccuracy(Criteria.ACCURACY_COARSE);
            String provider = lm.getBestProvider(criteria, true);
            if (provider != null && lm.isProviderEnabled(provider)) {
                lm.requestLocationUpdates(provider, 1, 0, locationListener, Looper.getMainLooper());
            } else {
                /*
                 * GPS not enabled, prompt user to enable GPS in the
                 * Location menu
                 */
                new AlertDialog.Builder(Places.this).setTitle(R.string.enable_gps_title)
                        .setMessage(getString(R.string.enable_gps))
                        .setPositiveButton(R.string.gps_settings, new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                startActivityForResult(
                                        new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS),
                                        0);
                            }
                        }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                dialog.dismiss();
                                Places.this.finish();
                            }
                        }).show();
            }
            Looper.loop();
        }
    }.start();
}

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  v a 2 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.dealsmessanger.android.DemoActivity.java

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

    setContentView(R.layout.main);/*from ww  w .  j a  v a 2  s.c  o  m*/
    mDisplay = (TextView) findViewById(R.id.display);

    context = getApplicationContext();

    // Check device for Play Services APK. If check succeeds, proceed with GCM registration.
    //        if (checkPlayServices()) {
    //            gcm = GoogleCloudMessaging.getInstance(this);
    //            regid = getRegistrationId(context);
    //
    //            if (regid.isEmpty()) {
    //                registerInBackground();
    //            }
    //        } else {
    //            Log.i(TAG, "No valid Google Play Services APK found.");
    //        }
    registerInBackground();
    // Get the location manager
    locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    // Define the criteria how to select the location provider
    criteria = new Criteria();
    criteria.setAccuracy(Criteria.ACCURACY_COARSE); // default

    criteria.setCostAllowed(false);
    // get the best provider depending on the criteria
    provider = locationManager.getBestProvider(criteria, false);

    // the last known location of this provider
    location = locationManager.getLastKnownLocation(provider);

    mylistener = new MyLocationListener();

    if (location != null) {
        mylistener.onLocationChanged(location);
    } else {
        // leads to the settings because there is no last known location
        Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
        startActivity(intent);
    }
    // location updates: at least 1 meter and 200millsecs change
    locationManager.requestLocationUpdates(provider, 200, 1, mylistener);

}

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

void setupLocManager(Context appContext) {
    if (appContext == null)
        return;/*from  w w  w .  ja 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:ca.mudar.mtlaucasou.BaseListFragment.java

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

    mActivityHelper = ActivityHelper.createInstance(getActivity());
    mAppHelper = ((AppHelper) getActivity().getApplicationContext());

    locationManager = (LocationManager) getSupportActivity().getSystemService(Context.LOCATION_SERVICE);
    locationListener = new MyLocationListener();
    criteria = new Criteria();
    criteria.setAccuracy(Criteria.ACCURACY_COARSE);

    SharedPreferences prefs = getSupportActivity().getSharedPreferences(Const.APP_PREFS_NAME,
            Context.MODE_PRIVATE);
    hasFollowLocationChanges = prefs.getBoolean(Const.PrefsNames.FOLLOW_LOCATION_CHANGES, false);

    Location myLocation = mAppHelper.getLocation();

    mHandler = new NotifyingAsyncQueryHandler(getActivity().getContentResolver(), this);

    if (mCursor != null) {
        getActivity().stopManagingCursor(mCursor);
        mCursor = null;/*from w  w  w. ja v  a2 s . com*/
    }

    setListAdapter(null);
    mHandler.cancelOperation(QUERY_TOKEN);

    /**
     * Update the projection alias to calculate the distance based on the
     * current Location.
     */
    String mSort;
    if (mAppHelper.getListSort().equals(PrefsValues.LIST_SORT_DISTANCE) && myLocation != null) {
        mSort = PlacemarkColumns.PLACEMARK_DISTANCE + " ASC ";
    } else {
        mSort = defaultSort;
    }

    mCursor = getActivity().getContentResolver().query(mActivityHelper.getContentUri(indexSection),
            PLACEMARKS_SUMMARY_PROJECTION, null, null, mSort);
    getActivity().startManagingCursor(mCursor);

    mAdapter = new PlacemarksCursorAdapter(getActivity(), R.layout.fragment_list_item_placemarks, mCursor,
            new String[] { PlacemarkColumns.PLACEMARK_NAME, PlacemarkColumns.PLACEMARK_ADDRESS },
            new int[] { R.id.placemark_name, R.id.placemark_address }, 0);

    setListAdapter(mAdapter);

    mHandler.startQuery(QUERY_TOKEN, null, mActivityHelper.getContentUri(indexSection),
            PLACEMARKS_SUMMARY_PROJECTION, null, null, mSort);
}

From source file:com.airbop.library.simple.CommonUtilities.java

/**
 * Simple helper that gets the location criteria that we want. 
 * @return// w ww  .  j a  v  a  2  s  .c  om
 */
public static Criteria getCriteria() {
    if (true) {
        Criteria criteria = new Criteria();
        criteria.setAccuracy(Criteria.ACCURACY_COARSE);
        criteria.setPowerRequirement(Criteria.POWER_LOW);
        criteria.setAltitudeRequired(false);
        criteria.setBearingRequired(false);
        criteria.setSpeedRequired(false);
        criteria.setCostAllowed(true);

        return criteria;
    }
    return null;
}

From source file:com.jesjimher.bicipalma.MesProperesActivity.java

/** Called when the activity is first created. */
@Override//from   www  . j  a v  a  2 s.c  om
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.mesproperes);
    this.prefs = PreferenceManager.getDefaultSharedPreferences(this);

    // Si s'ha d'activar el wifi en inici, fer-ho
    WifiManager wm = (WifiManager) this.getSystemService(Context.WIFI_SERVICE);
    // Guardar el estado actual para restaurarlo al salir
    this.estatWifi = wm.isWifiEnabled();
    if (prefs.getBoolean("activarWifiPref", false))
        wm.setWifiEnabled(true);

    // Cargamos la versin cacheada de las estaciones
    leerCacheEstaciones();

    actualizarListado();

    // Iniciamos la descarga de las estaciones y su estado desde la web (en un thread aparte)
    descargaEstaciones = new RecuperarEstacionesTask(this);
    descargaEstaciones.execute();

    // Inicialmente se busca por red (ms rpido)
    //       dBuscaUbic=ProgressDialog.show(c, "",getString(R.string.buscandoubica),true,true);
    //        Toast.makeText(getApplicationContext(), "Activando", Toast.LENGTH_SHORT).show();
    locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    Criteria criteria = new Criteria();
    criteria.setAccuracy(Criteria.ACCURACY_COARSE);
    providerCoarse = locationManager.getBestProvider(criteria, true);

    if (providerCoarse == null) {
        Toast.makeText(getApplicationContext(), "No hay forma de posicionarse", Toast.LENGTH_SHORT).show();
        return;
    }
    locationManager.requestLocationUpdates(providerCoarse, 10, 0, (LocationListener) this);

    // Usar ltima ubicacin conocida de red para empezar y recibir futuras actualizaciones
    lBest = locationManager.getLastKnownLocation(providerCoarse);

    // Guardar el inicio de bsqueda de ubicacin para no pasarse de tiempo
    //tIni=new Date().getTime();
    tIni = System.currentTimeMillis();

    // Crear listeners para mostrar estacin en mapa, o abrir men con clic largo
    ListView lv = (ListView) findViewById(R.id.listado);
    lv.setOnItemClickListener((OnItemClickListener) this);
    lv.setOnItemLongClickListener((OnItemLongClickListener) this);
}