Example usage for android.location LocationManager removeUpdates

List of usage examples for android.location LocationManager removeUpdates

Introduction

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

Prototype

public void removeUpdates(PendingIntent intent) 

Source Link

Document

Removes all location updates for the specified pending intent.

Usage

From source file:org.telegram.ui.ThemeActivity.java

private void stopLocationUpdate() {
    updatingLocation = false;/* w  ww  .j  a va2  s .c  o  m*/
    LocationManager locationManager = (LocationManager) ApplicationLoader.applicationContext
            .getSystemService(Context.LOCATION_SERVICE);
    locationManager.removeUpdates(gpsLocationListener);
    locationManager.removeUpdates(networkLocationListener);
}

From source file:org.getlantern.firetweet.activity.support.ComposeActivity.java

/**
 * The Location Manager manages location providers. This code searches for
 * the best provider of data (GPS, WiFi/cell phone tower lookup, some other
 * mechanism) and finds the last known location.
 *//*from   w  w w.  j  a  v  a2  s.c  o m*/
private boolean startLocationUpdateIfEnabled() {
    final LocationManager lm = mLocationManager;
    final boolean attachLocation = mPreferences.getBoolean(KEY_ATTACH_LOCATION, false);
    if (!attachLocation) {
        lm.removeUpdates(this);
        return false;
    }
    final Criteria criteria = new Criteria();
    criteria.setAccuracy(Criteria.ACCURACY_FINE);
    final String provider = lm.getBestProvider(criteria, true);
    if (provider != null) {
        mLocationText.setText(R.string.getting_location);
        lm.requestLocationUpdates(provider, 0, 0, this);
        final Location location;
        if (lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
            location = lm.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
        } else {
            location = lm.getLastKnownLocation(provider);
        }
        if (location != null) {
            onLocationChanged(location);
        }
    } else {
        Toast.makeText(this, R.string.cannot_get_location, Toast.LENGTH_SHORT).show();
    }
    return provider != null;
}

From source file:org.mariotaku.twidere.activity.support.ComposeActivity.java

/**
 * The Location Manager manages location providers. This code searches for
 * the best provider of data (GPS, WiFi/cell phone tower lookup, some other
 * mechanism) and finds the last known location.
 *///from w  ww .  j a v a 2  s  . c  om
private boolean startLocationUpdateIfEnabled() {
    final LocationManager lm = mLocationManager;
    final boolean attachLocation = mPreferences.getBoolean(KEY_ATTACH_LOCATION);
    if (!attachLocation) {
        lm.removeUpdates(this);
        return false;
    }
    final Criteria criteria = new Criteria();
    criteria.setAccuracy(Criteria.ACCURACY_FINE);
    final String provider = lm.getBestProvider(criteria, true);
    if (provider != null) {
        mLocationText.setText(R.string.getting_location);
        lm.requestLocationUpdates(provider, 0, 0, this);
        final Location location;
        if (lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
            location = lm.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
        } else {
            location = lm.getLastKnownLocation(provider);
        }
        if (location != null) {
            onLocationChanged(location);
        }
    } else {
        Toast.makeText(this, R.string.cannot_get_location, Toast.LENGTH_SHORT).show();
    }
    return provider != null;
}

From source file:org.planetmono.dcuploader.ActivityUploader.java

private void queryLocation(boolean enabled) {
    LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

    if (enabled) {
        lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationTracker);
        lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationTracker);
        ((Button) findViewById(R.id.upload_ok)).setEnabled(false);
        findViewById(R.id.upload_location_progress).setVisibility(View.VISIBLE);
    } else {/*  ww w.  ja  v a 2  s  . c  o m*/
        lm.removeUpdates(locationTracker);
        ((Button) findViewById(R.id.upload_ok)).setEnabled(true);
        findViewById(R.id.upload_location_progress).setVisibility(View.INVISIBLE);
    }
}

From source file:com.mparticle.MParticle.java

/**
 * Disables any mParticle location tracking that had been started
 *//*from www. j  a  v  a 2 s  .  c  o  m*/
private void disableLocationTracking(boolean userTriggered) {
    if (mLocationListener != null) {
        try {
            LocationManager locationManager = (LocationManager) mAppContext
                    .getSystemService(Context.LOCATION_SERVICE);

            if (MPUtility.checkPermission(mAppContext, Manifest.permission.ACCESS_FINE_LOCATION)
                    || MPUtility.checkPermission(mAppContext, Manifest.permission.ACCESS_COARSE_LOCATION)) {
                locationManager.removeUpdates(mLocationListener);
            }
            mLocationListener = null;
            if (userTriggered) {
                SharedPreferences.Editor editor = mPreferences.edit();
                editor.remove(PrefKeys.LOCATION_PROVIDER).remove(PrefKeys.LOCATION_MINTIME)
                        .remove(PrefKeys.LOCATION_MINDISTANCE).apply();
            }
        } catch (Exception e) {

        }
    }
}

From source file:com.mparticle.MParticle.java

/**
 * Enables location tracking given a provider and update frequency criteria. The provider must
 * be available and the correct permissions must have been requested within your application's manifest XML file.
 *
 * @param provider    the provider key/*from   w  w  w.j a  va 2s  .  c  om*/
 * @param minTime     the minimum time (in milliseconds) to trigger an update
 * @param minDistance the minimum distance (in meters) to trigger an update
 */
public void enableLocationTracking(String provider, long minTime, long minDistance) {
    if (mConfigManager.isEnabled()) {
        try {
            LocationManager locationManager = (LocationManager) mAppContext
                    .getSystemService(Context.LOCATION_SERVICE);
            if (!locationManager.isProviderEnabled(provider)) {
                ConfigManager.log(LogLevel.ERROR, "That requested location provider is not available");
                return;
            }

            if (null == mLocationListener) {
                mLocationListener = new MPLocationListener(this);
            } else {
                // clear the location listener, so it can be added again
                locationManager.removeUpdates(mLocationListener);
            }
            locationManager.requestLocationUpdates(provider, minTime, minDistance, mLocationListener);
            SharedPreferences.Editor editor = mPreferences.edit();
            editor.putString(PrefKeys.LOCATION_PROVIDER, provider).putLong(PrefKeys.LOCATION_MINTIME, minTime)
                    .putLong(PrefKeys.LOCATION_MINDISTANCE, minDistance).apply();

        } catch (SecurityException e) {
            ConfigManager.log(LogLevel.ERROR,
                    "The app must require the appropriate permissions to track location using this provider");
        }
    }
}