Example usage for android.location Criteria ACCURACY_FINE

List of usage examples for android.location Criteria ACCURACY_FINE

Introduction

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

Prototype

int ACCURACY_FINE

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

Click Source Link

Document

A constant indicating a finer location accuracy requirement

Usage

From source file:com.radioactiveyak.location_best_practices.UI.PlaceActivity.java

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

    // Inflate the layout
    setContentView(R.layout.main);/*from   w  w  w .ja  v a  2s .  co m*/

    // Get a handle to the Fragments
    placeListFragment = (PlaceListFragment) getSupportFragmentManager().findFragmentById(R.id.list_fragment);
    checkinFragment = (CheckinFragment) getSupportFragmentManager().findFragmentById(R.id.checkin_fragment);

    // Get references to the managers
    packageManager = getPackageManager();
    notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

    // Get a reference to the Shared Preferences and a Shared Preference Editor.
    prefs = getSharedPreferences(PlacesConstants.SHARED_PREFERENCE_FILE, Context.MODE_PRIVATE);
    prefsEditor = prefs.edit();

    // Instantiate a SharedPreferenceSaver class based on the available platform version.
    // This will be used to save shared preferences
    sharedPreferenceSaver = PlatformSpecificImplementationFactory.getSharedPreferenceSaver(this);

    // Save that we've been run once.
    prefsEditor.putBoolean(PlacesConstants.SP_KEY_RUN_ONCE, true);
    sharedPreferenceSaver.savePreferences(prefsEditor, false);

    // Specify the Criteria to use when requesting location updates while the application is Active
    criteria = new Criteria();
    if (PlacesConstants.USE_GPS_WHEN_ACTIVITY_VISIBLE)
        criteria.setAccuracy(Criteria.ACCURACY_FINE);
    else
        criteria.setPowerRequirement(Criteria.POWER_LOW);

    // Setup the location update Pending Intents
    Intent activeIntent = new Intent(this, LocationChangedReceiver.class);
    locationListenerPendingIntent = PendingIntent.getBroadcast(this, 0, activeIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    Intent passiveIntent = new Intent(this, PassiveLocationChangedReceiver.class);
    locationListenerPassivePendingIntent = PendingIntent.getBroadcast(this, 0, passiveIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    // Instantiate a LastLocationFinder class.
    // This will be used to find the last known location when the application starts.
    lastLocationFinder = PlatformSpecificImplementationFactory.getLastLocationFinder(this);
    lastLocationFinder.setChangedLocationListener(oneShotLastLocationUpdateListener);

    // Instantiate a Location Update Requester class based on the available platform version.
    // This will be used to request location updates.
    locationUpdateRequester = PlatformSpecificImplementationFactory.getLocationUpdateRequester(locationManager);

    // Create an Intent Filter to listen for checkins
    newCheckinReceiverName = new ComponentName(this, NewCheckinReceiver.class);
    newCheckinFilter = new IntentFilter(PlacesConstants.NEW_CHECKIN_ACTION);

    // Check to see if an Place ID has been specified in the launch Intent.
    // If so, we should display the details for the specified venue.
    if (getIntent().hasExtra(PlacesConstants.EXTRA_KEY_ID)) {
        Intent intent = getIntent();
        String key = intent.getStringExtra(PlacesConstants.EXTRA_KEY_ID);
        if (key != null) {
            selectDetail(null, key);
            // Remove the ID from the Intent (so that a resume doesn't reselect).
            intent.removeExtra(PlacesConstants.EXTRA_KEY_ID);
            setIntent(intent);
        }
    }
}

From source file:com.findcab.driver.activity.Signup.java

/**
 * ?GPS?//from   www . java  2  s  . c o m
 */
private void initLocation() {

    LocationManager locationManager;
    String serviceName = Context.LOCATION_SERVICE;
    locationManager = (LocationManager) this.getSystemService(serviceName);
    // ?
    Criteria criteria = new Criteria();
    criteria.setAccuracy(Criteria.ACCURACY_FINE);
    criteria.setAltitudeRequired(false);
    criteria.setBearingRequired(false);
    criteria.setCostAllowed(true);
    criteria.setPowerRequirement(Criteria.POWER_LOW);

    String provider = locationManager.getBestProvider(criteria, true);
    Location location = locationManager.getLastKnownLocation(provider);
    if (location != null) {

        lat = location.getLatitude();
        lng = location.getLongitude();

    }
}

From source file:com.detroitteatime.autocarfinder.Main.java

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

    mainLayout = (LinearLayout) this.getLayoutInflater().inflate(R.layout.main, null);

    setContentView(mainLayout);//from w w  w .j a va  2 s  .c o  m

    // Possible work around for market launches. See
    // http://code.google.com/p/android/issues/detail?id=2373
    // for more details. Essentially, the market launches the main activity
    // on top of other activities.
    // we never want this to happen. Instead, we check if we are the root
    // and if not, we finish.
    if (!isTaskRoot()) {
        final Intent intent = getIntent();
        final String intentAction = intent.getAction();
        if (intent.hasCategory(Intent.CATEGORY_LAUNCHER) && intentAction != null
                && intentAction.equals(Intent.ACTION_MAIN)) {
            // Log.w("My Code",
            // "Main Activity is not the root.  Finishing Main Activity instead of launching.");
            finish();
            return;
        }
    }

    // set up buttons
    start = (Button) findViewById(R.id.start);

    manual = (Button) findViewById(R.id.manual);
    // progress = (ProgressBar) findViewById(R.id.progressBar1);

    start.setOnClickListener(this);
    start.getBackground().setColorFilter(Color.parseColor(COLOR), PorterDuff.Mode.MULTIPLY);

    manual.setOnClickListener(this);
    manual.getBackground().setColorFilter(Color.parseColor(COLOR), PorterDuff.Mode.MULTIPLY);

    monitor = (FrameLayout) findViewById(R.id.frameLayout1);

    data1 = this.getSharedPreferences("storage", 0);
    editor1 = data1.edit();

    // firstTime = data1.getBoolean("first_time", true);

    editor1.putBoolean("first_time", false);
    editor1.commit();

    pi = PendingIntent.getActivity(this, 0, new Intent(this, Main.class), 0);

    data1 = getSharedPreferences("storage", 0);
    editor1 = data1.edit();

    // set a global layout listener which will be called when the layout
    // pass is completed and the view is drawn

    FragmentManager myFragmentManager = getSupportFragmentManager();
    mySupportMapFragment = (SupportMapFragment) myFragmentManager.findFragmentById(R.id.map);

    if (MapsInitializer.initialize(this) != ConnectionResult.SUCCESS) {
        Toast.makeText(this, "Map failed to initialize.", Toast.LENGTH_SHORT).show();

    }

    map = mySupportMapFragment.getMap();

    manager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    // Define the criteria how to select the locatioin provider -> use
    // default
    criteria = new Criteria();
    criteria.setAccuracy(Criteria.ACCURACY_FINE);
    criteria.setAltitudeRequired(false);
    criteria.setBearingRequired(false);
    provider = manager.getBestProvider(criteria, false);
    manager.requestLocationUpdates(provider, 1000, 1, this);

    navigate = (Button) findViewById(R.id.navigate);
    navigate.setOnClickListener(this);

    type = (Button) findViewById(R.id.satellite);
    type.setOnClickListener(this);

}

From source file:net.mceoin.cominghome.LocationService.java

private void backgroundThreadProcessing() {
    secondsToSleep = 30;/*from w ww . j a  v  a 2  s. c o  m*/
    while (runBackgroundThread) {
        if (locationManager == null) {
            initLocationManager();
        }
        try {
            if (debug)
                Log.d(TAG, "sleeping " + secondsToSleep + " seconds");
            Thread.sleep(secondsToSleep * 1000);
            if (secondsToSleep < MAXSLEEP_WHILE_NOT_MOVING) {
                secondsToSleep += 15;
            }
        } catch (InterruptedException e) {
            //                e.printStackTrace();
            if (debug)
                Log.d(TAG, "wake up!");
        }
        Criteria criteria = new Criteria();
        criteria.setAccuracy(Criteria.ACCURACY_FINE);
        String provider = locationManager.getBestProvider(criteria, true);

        //            provider = LocationManager.GPS_PROVIDER;
        Location location = locationManager.getLastKnownLocation(provider);
        if (mLocationClient.isConnected()) {
            if (debug)
                Log.d(TAG, "mLocationClient is connected");
            location = mLocationClient.getLastLocation();
        }
        if (debug)
            Log.d(TAG, "location=" + location);
        if (myLocation == null) {
            myLocation = location;
            broadcastLocationChanged(myLocation);
        } else {
            float dist = distFrom(myLocation, location);
            if (debug)
                Log.d(TAG, "dist=" + dist);
            if ((checkinRequested) || (dist > 20)) {
                myLocation = location;
                broadcastLocationChanged(myLocation);
                checkinRequested = false;
                if (secondsToSleep > MAXSLEEP_WHILE_MOVING) {
                    // if we're moving, don't sleep too much
                    secondsToSleep = MAXSLEEP_WHILE_MOVING;
                }
            }
        }

    }
}

From source file:com.example.mohamed.a3qaqer.RegisterActvity.java

private void getloc() {
    if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
        loc_string = "none";// indicate that no gps data
        return;/* ww w  . j av a 2  s  . co  m*/
    }
    Criteria criteria = new Criteria();
    criteria.setAccuracy(Criteria.ACCURACY_FINE);
    criteria.setBearingRequired(true);
    criteria.setCostAllowed(true);
    criteria.setPowerRequirement(Criteria.POWER_LOW);
    criteria.setAltitudeRequired(false);
    String bestProvider = locationManager.getBestProvider(criteria, true);
    if (ActivityCompat.checkSelfPermission(this,
            android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
            && ActivityCompat.checkSelfPermission(this,
                    android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
        return;
    }
    locationManager.requestLocationUpdates(bestProvider, 2000, 10, new LocationListener() {
        @Override
        public void onStatusChanged(String s, int i, Bundle bundle) {
        }

        @Override
        public void onProviderEnabled(String s) {
        }

        @Override
        public void onProviderDisabled(String s) {
        }

        @Override
        public void onLocationChanged(final Location location) {
        }
    });
    Location myLocation = locationManager.getLastKnownLocation(LocationManager.PASSIVE_PROVIDER);
    double longitude = myLocation.getLongitude();
    double latitude = myLocation.getLatitude();
    loc_string = latitude + "-" + longitude;

}

From source file:com.mibr.android.intelligentreminder.INeedToo.java

public LocationManager getLocationManager() {
    if (mLocationManager == null) {
        mLocationManager = (android.location.LocationManager) getSystemService(Context.LOCATION_SERVICE);
    }//from ww  w.  j  a  v a 2  s . co m
    if (_bestProvider == null) {
        Criteria criteria = new Criteria();
        criteria.setAccuracy(Criteria.ACCURACY_FINE);
        _bestProvider = mLocationManager.getBestProvider(criteria, false);
        mLocationManager.requestLocationUpdates(_bestProvider, 20000, 10, this);
    }
    return mLocationManager;
}

From source file:de.madvertise.android.sdk.MadUtil.java

/**
 * Try to update current location. Non blocking call.
 * /*from   ww  w .ja v a  2 s .  c  om*/
 * @param context
 *            application context
 */
protected static void refreshCoordinates(Context context) {
    if (PRINT_LOG)
        Log.d(LOG, "Trying to refresh location");

    if (context == null) {
        if (PRINT_LOG)
            Log.d(LOG, "Context not set - quit location refresh");
        return;
    }

    // check if we need a regular update
    if ((locationUpdateTimestamp + MadUtil.SECONDS_TO_REFRESH_LOCATION * 1000) > System.currentTimeMillis()) {
        if (PRINT_LOG)
            Log.d(LOG, "It's not time yet for refreshing the location");
        return;
    }

    synchronized (context) {
        // recheck, if location was updated by another thread while we paused
        if ((locationUpdateTimestamp + MadUtil.SECONDS_TO_REFRESH_LOCATION * 1000) > System
                .currentTimeMillis()) {
            if (PRINT_LOG)
                Log.d(LOG, "Another thread updated the loation already");
            return;
        }

        boolean permissionCoarseLocation = context.checkCallingOrSelfPermission(
                android.Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED;
        boolean permissionFineLocation = context.checkCallingOrSelfPermission(
                android.Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED;

        // return (null) if we do not have any permissions
        if (!permissionCoarseLocation && !permissionFineLocation) {
            if (PRINT_LOG)
                Log.d(LOG, "No permissions for requesting the location");
            return;
        }

        // return (null) if we can't get a location manager
        LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
        if (locationManager == null) {
            if (PRINT_LOG)
                Log.d(LOG, "Unable to fetch a location manger");
            return;
        }

        String provider = null;
        Criteria criteria = new Criteria();
        criteria.setCostAllowed(false);

        // try to get coarse location first
        if (permissionCoarseLocation) {
            criteria.setAccuracy(Criteria.ACCURACY_COARSE);
            provider = locationManager.getBestProvider(criteria, true);
        }

        // try to get gps location if coarse locatio did not work
        if (provider == null && permissionFineLocation) {
            criteria.setAccuracy(Criteria.ACCURACY_FINE);
            provider = locationManager.getBestProvider(criteria, true);
        }

        // still no provider, return (null)
        if (provider == null) {
            if (PRINT_LOG)
                Log.d(LOG, "Unable to fetch a location provider");
            return;
        }

        // create a finalized reference to the location manager, in order to
        // access it in the inner class
        final LocationManager finalizedLocationManager = locationManager;
        locationUpdateTimestamp = System.currentTimeMillis();
        locationManager.requestLocationUpdates(provider, 0, 0, new LocationListener() {
            public void onLocationChanged(Location location) {
                if (PRINT_LOG)
                    Log.d(LOG, "Refreshing location");
                currentLocation = location;
                locationUpdateTimestamp = System.currentTimeMillis();
                // stop draining battery life
                finalizedLocationManager.removeUpdates(this);
            }

            // not used yet
            public void onProviderDisabled(String provider) {
            }

            public void onProviderEnabled(String provider) {
            }

            public void onStatusChanged(String provider, int status, Bundle extras) {
            }
        }, context.getMainLooper());
    }
}

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);/*  ww  w .j  av a 2s.  com*/
        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:org.deviceconnect.android.deviceplugin.host.profile.HostGeolocationProfile.java

/**
 * ?????./* w  ww. j av a 2 s . com*/
 * @param accuracy .
 * @param response ?.
 */
private void getGPS(final boolean accuracy, final Intent response) {
    if (ActivityCompat.checkSelfPermission(getContext(),
            Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
            && ActivityCompat.checkSelfPermission(getContext(),
                    ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
        MessageUtils.setIllegalDeviceStateError(response, "ACCESS_FINE_LOCATION permission not granted.");
        sendResponse(response);
        return;
    }

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

    mLocationManager.requestSingleUpdate(mLocationManager.getBestProvider(criteria, true),
            new LocationListener() {
                @Override
                public void onLocationChanged(Location location) {
                    Bundle position = createPositionObject(location);

                    DConnectProfile.setResult(response, DConnectMessage.RESULT_OK);
                    response.putExtra(GeolocationProfile.PARAM_POSITION, position);
                    sendResponse(response);
                }

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

                @Override
                public void onProviderEnabled(String provider) {
                    // NOP
                }

                @Override
                public void onProviderDisabled(String provider) {
                    // NOP
                }
            }, Looper.getMainLooper());
}

From source file:com.brejza.matt.habmodem.Dsp_service.java

private void enableLocation() {
    //my location part
    Criteria criteria = new Criteria();
    criteria.setAccuracy(Criteria.ACCURACY_FINE);

    String bestProvider = this.locationManager.getBestProvider(criteria, true);
    if (bestProvider == null)
        return;/*  www  . j  a  v  a  2 s .  c o  m*/
    System.out.println("STARTING GPS WITH: " + bestProvider);
    logEvent("Starting Location with: " + bestProvider, true);
    this.locationManager.requestLocationUpdates(bestProvider, 2000, 0, this.loc_han);

}