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:com.metinkale.prayerapp.compass.Main.java

@Override
protected void onPause() {
    LocationManager locMan = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    locMan.removeUpdates(this);
    super.onPause();
}

From source file:com.metinkale.prayerapp.vakit.AddCity.java

@SuppressWarnings("MissingPermission")
@Override/*from   w  w  w.  j  av a2s.co m*/
protected void onDestroy() {
    if (PermissionUtils.get(this).pLocation) {
        LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
        lm.removeUpdates(this);
    }
    super.onDestroy();
}

From source file:com.metinkale.prayerapp.compass.Main.java

@Override
public void onLocationChanged(Location location) {
    if ((System.currentTimeMillis() - location.getTime()) < (mOnlyNew ? (1000 * 60) : (1000 * 60 * 60 * 24))) {
        LocationManager locMan = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
        locMan.removeUpdates(this);
    }/*from www.  ja va2s  .  c o  m*/

}

From source file:com.metinkale.prayerapp.compass.Main.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (mRefresh == item) {
        mOnlyNew = true;//from  w w  w.j av  a2 s  . c o  m
        if (PermissionUtils.get(this).pLocation) {
            LocationManager locMan = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

            locMan.removeUpdates(this);
            List<String> providers = locMan.getProviders(true);
            for (String provider : providers) {
                locMan.requestLocationUpdates(provider, 0, 0, this);
            }
        }
    } else if (mSwitch == item) {
        if (mMode == Mode.Map) {
            mSensorManager.registerListener(mMagAccel,
                    mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),
                    SensorManager.SENSOR_DELAY_GAME);
            mSensorManager.registerListener(mMagAccel,
                    mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD),
                    SensorManager.SENSOR_DELAY_GAME);

            updateFrag(Mode.TwoDim);

            mSwitch.setIcon(MaterialDrawableBuilder.with(this).setIcon(MaterialDrawableBuilder.IconValue.MAP)
                    .setColor(Color.WHITE).setToActionbarSize().build());
        } else if (PermissionUtils.get(this).pLocation) {
            mSensorManager.unregisterListener(mMagAccel);
            updateFrag(Mode.Map);
            mSwitch.setIcon(MaterialDrawableBuilder.with(this)
                    .setIcon(MaterialDrawableBuilder.IconValue.COMPASS_OUTLINE).setColor(Color.WHITE)
                    .setToActionbarSize().build());
        } else {
            Toast.makeText(this, R.string.permissionNotGranted, Toast.LENGTH_LONG).show();
        }
    }

    return super.onOptionsItemSelected(item);
}

From source file:com.facebook.react.modules.location.LocationModule.java

/**
 * Stop listening for location updates./*from   www .j  a  v  a 2 s  .  c  o m*/
 *
 * NB: this is not balanced with {@link #startObserving}: any number of calls to that method will
 * be canceled by just one call to this one.
 */
@ReactMethod
public void stopObserving() {
    LocationManager locationManager = (LocationManager) getReactApplicationContext()
            .getSystemService(Context.LOCATION_SERVICE);
    locationManager.removeUpdates(mLocationListener);
    mWatchedProvider = null;
}

From source file:org.runnerup.gpstracker.GpsTracker.java

public void stopLogging() {
    assert (state == State.PAUSED || state == State.LOGGING);
    wakelock(false);//from  w w  w  .jav  a2  s.co m
    if (state != State.INIT) {
        LocationManager lm = (LocationManager) this.getSystemService(LOCATION_SERVICE);
        lm.removeUpdates(this);
        state = State.INIT;
    }
    liveLoggers.clear();
    stopHRMonitor();
}

From source file:at.ac.uniklu.mobile.sportal.service.MutingService.java

/**
 * Turns OFF automatic ringtone muting during courses.
 */// w w w .  j a v  a 2s . co  m
private void turnOff() {
    Log.d(TAG, "turnOff()");
    Analytics.onEvent(Analytics.EVENT_MUTINGSERVICE_OFF);

    // if the phone is currently in a muting period, turn the ringtone back on before turning off the service
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
    if (Preferences.isMutingPeriod(preferences)) {
        MutingUtils.ringtoneTurnOn(this);
        Preferences.setMutingPeriod(preferences, false);
    }

    // remove eventually existing user notification
    removeNotification(Studentportal.NOTIFICATION_MS_INFO);

    // cancel an eventually existing pending alarm and the beloging intent as well (otherwise isRunning would always return true)
    AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
    Intent alarmIntent = new Intent(this, OnAlarmReceiver.class).putExtra(ACTION, ACTION_NONE);
    PendingIntent pendingAlarmIntent = PendingIntent.getBroadcast(this, 0, alarmIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    alarmManager.cancel(pendingAlarmIntent);
    pendingAlarmIntent.cancel();

    // cancel an eventually exisiting location broadcast receiver
    LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
    Intent locationIntent = new Intent("at.ac.uniklu.mobile.sportal.LOCATION_UPDATE");
    PendingIntent pendingLocationIntent = PendingIntent.getBroadcast(this, 0, locationIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    locationManager.removeUpdates(pendingLocationIntent);
    pendingLocationIntent.cancel();

    if (isRunning()) {
        Log.e(TAG, "COULD NOT TURN OFF");
    }
}

From source file:com.facebook.react.modules.location.LocationModule.java

/**
 * Start listening for location updates. These will be emitted via the
 * {@link RCTDeviceEventEmitter} as {@code geolocationDidChange} events.
 *
 * @param options map containing optional arguments: highAccuracy (boolean)
 *//* ww  w  .  j  a v  a2 s.  c o  m*/
@ReactMethod
public void startObserving(ReadableMap options) {
    if (LocationManager.GPS_PROVIDER.equals(mWatchedProvider)) {
        return;
    }
    LocationOptions locationOptions = LocationOptions.fromReactMap(options);

    try {
        LocationManager locationManager = (LocationManager) getReactApplicationContext()
                .getSystemService(Context.LOCATION_SERVICE);
        String provider = getValidProvider(locationManager, locationOptions.highAccuracy);
        if (provider == null) {
            emitError(PositionError.POSITION_UNAVAILABLE, "No location provider available.");
            return;
        }
        if (!provider.equals(mWatchedProvider)) {
            locationManager.removeUpdates(mLocationListener);
            locationManager.requestLocationUpdates(provider, 1000, locationOptions.distanceFilter,
                    mLocationListener);
        }
        mWatchedProvider = provider;
    } catch (SecurityException e) {
        throwLocationPermissionMissing(e);
    }
}

From source file:org.microg.gms.maps.GoogleMapImpl.java

@Override
public void setMyLocationEnabled(boolean myLocation) throws RemoteException {
    Log.w(TAG, "MyLocation not yet supported");
    boolean hasPermission = ContextCompat.checkSelfPermission(context,
            ACCESS_COARSE_LOCATION) == PERMISSION_GRANTED
            || ContextCompat.checkSelfPermission(context, ACCESS_FINE_LOCATION) == PERMISSION_GRANTED;
    if (!hasPermission) {
        throw new SecurityException(
                "Neither " + ACCESS_COARSE_LOCATION + " nor " + ACCESS_FINE_LOCATION + " granted.");
    }/*from  ww  w  . ja  va  2 s.  c  o m*/
    LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
    if (myLocation) {
        locationManager.requestLocationUpdates(5000, 10, criteria, listener, Looper.getMainLooper());
    } else {
        locationManager.removeUpdates(listener);
    }
}

From source file:org.akvo.rsr.up.UpdateEditorActivity.java

/**
 * called by the system when it gets location updates.
 *///  ww  w.  j  a v  a 2  s  .c  om
public void onLocationChanged(Location location) {
    float currentAccuracy = location.getAccuracy();
    // if accuracy is 0 then the gps has no idea where we're at
    if (currentAccuracy > 0) {

        // If we are below the accuracy treshold, stop listening for updates.
        // This means that after the geolocation is 'green', it stays the same,
        // otherwise it keeps on listening
        if (currentAccuracy <= ACCURACY_THRESHOLD) {
            LocationManager locMgr = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
            locMgr.removeUpdates(this);
            searchingIndicator.setText(R.string.label_gps_ready);
            gpsProgress.setVisibility(View.GONE); //hide in-progress wheel
        }

        // if the location reading is more accurate than the last, update
        // the view
        if (lastAccuracy > currentAccuracy || needUpdate) {
            lastAccuracy = currentAccuracy;
            needUpdate = false;
            populateLocation(location);
        }
    } else if (needUpdate) {
        needUpdate = true;
        populateLocation(location);
    }
}