List of usage examples for android.location LocationManager removeUpdates
public void removeUpdates(PendingIntent intent)
From source file:uk.ac.horizon.ug.exploding.client.LocationUtils.java
public static void unregisterOnThread(Context context, LocationListener locationCallback, Listener listener) { Log.i(TAG, "Unregister for location events"); LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); if (locationCallback != null) locationManager.removeUpdates(locationCallback); if (listener != null) locationManager.removeGpsStatusListener(listener); }
From source file:com.binomed.showtime.android.util.localisation.LocationUtils.java
public static void unRegisterListener(Context context, ProviderEnum provider, LocalisationManagement listener) { switch (provider) { case GPS_PROVIDER: case GSM_PROVIDER: { LocationManager locationManager = getLocationManager(context); if (locationManager != null) { locationManager.removeUpdates(listener); } else {//w w w . j a v a2 s.c o m if (Log.isLoggable(TAG, Log.DEBUG)) { Log.d(TAG, "No listener Put"); //$NON-NLS-1$ } } break; } case WIFI_PROVIDER: case XPS_PROVIDER: { XPS xps = listener.getXps(); if (xps != null) { xps.abort(); } break; } default: break; } }
From source file:de.madvertise.android.sdk.MadUtil.java
/** * Try to update current location. Non blocking call. * //from ww w . jav a2 s. c o m * @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:org.mozilla.mozstumbler.service.stumblerthread.scanners.GPSScanner.java
public void stop() { LocationManager lm = getLocationManager(); lm.removeUpdates(this); reportLocationLost();/*from w w w . j ava 2 s . c om*/ if (mGPSListener != null) { lm.removeGpsStatusListener(mGPSListener); mGPSListener = null; } }
From source file:org.runnerup.tracker.component.TrackerGPS.java
@Override public ResultCode onEnd(Callback callback, Context context) { if (!mWithoutGps) { LocationManager lm = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); try {//from w w w. j ava2 s .c o m lm.removeUpdates(tracker); } catch (SecurityException ex) { ex.printStackTrace(); } catch (Exception ex) { ex.printStackTrace(); } if (mGpsStatus != null) { mGpsStatus.stop(this); } mGpsStatus = null; mConnectCallback = null; } return ResultCode.RESULT_OK; }
From source file:de.madvertise.android.sdk.MadvertiseUtil.java
/** * Try to update current location. Non blocking call. * //from w w w . j av a 2s. c o m * @param context * application context */ public static void refreshCoordinates(final Context context) { MadvertiseUtil.logMessage(null, Log.DEBUG, "Trying to refresh location"); if (context == null) { MadvertiseUtil.logMessage(null, Log.DEBUG, "Context not set - quit location refresh"); return; } // check if we need a regular update if ((sLocationUpdateTimestamp + MadvertiseUtil.SECONDS_TO_REFRESH_LOCATION * 1000) > System .currentTimeMillis()) { MadvertiseUtil.logMessage(null, Log.DEBUG, "It's not time yet for refreshing the location"); return; } synchronized (context) { // recheck, if location was updated by another thread while we // paused if ((sLocationUpdateTimestamp + MadvertiseUtil.SECONDS_TO_REFRESH_LOCATION * 1000) > System .currentTimeMillis()) { MadvertiseUtil.logMessage(null, Log.DEBUG, "Another thread updated the loation already"); return; } boolean permissionCoarseLocation = MadvertiseUtil .checkPermissionGranted(android.Manifest.permission.ACCESS_COARSE_LOCATION, context); boolean permissionFineLocation = MadvertiseUtil .checkPermissionGranted(android.Manifest.permission.ACCESS_FINE_LOCATION, context); // return (null) if we do not have any permissions if (!permissionCoarseLocation && !permissionFineLocation) { MadvertiseUtil.logMessage(null, Log.DEBUG, "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) { MadvertiseUtil.logMessage(null, Log.DEBUG, "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) { MadvertiseUtil.logMessage(null, Log.DEBUG, "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; sLocationUpdateTimestamp = System.currentTimeMillis(); locationManager.requestLocationUpdates(provider, 0, 0, new LocationListener() { @Override public void onLocationChanged(Location location) { MadvertiseUtil.logMessage(null, Log.DEBUG, "Refreshing location"); sCurrentLocation = location; sLocationUpdateTimestamp = System.currentTimeMillis(); // stop draining battery life finalizedLocationManager.removeUpdates(this); } // not used yet @Override public void onProviderDisabled(String provider) { } @Override public void onProviderEnabled(String provider) { } @Override public void onStatusChanged(String provider, int status, Bundle extras) { } }, context.getMainLooper()); } }
From source file:com.example.david.wheretogo_test1.PickerActivity.java
@Override protected void onStop() { super.onStop(); if (locationListener != null) { LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); locationManager.removeUpdates(locationListener); locationListener = null;// ww w . jav a 2s . c o m } }
From source file:com.jmstudios.redmoon.receiver.LocationUpdateListener.java
@Override public void onProviderDisabled(String provider) { if (DEBUG)/* w w w . j a v a 2 s . c o m*/ Log.i(TAG, "Location search failed"); LocationManager locationManager = (LocationManager) mContext.getSystemService(Context.LOCATION_SERVICE); if (ContextCompat.checkSelfPermission(mContext, Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) locationManager.removeUpdates(this); if (mPreference != null) mPreference.handleLocationSearchFailed(); }
From source file:com.eutectoid.dosomething.PickerActivity.java
@Override protected void onStop() { super.onStop(); // API 23: we have to check if ACCESS_FINE_LOCATION and/or ACCESS_COARSE_LOCATION permission are granted if (ContextCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED || ContextCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) { if (locationListener != null) { LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); locationManager.removeUpdates(locationListener); locationListener = null;//from w w w.j a v a2 s . co m } } }
From source file:com.jmstudios.redmoon.receiver.LocationUpdateListener.java
@Override public void onLocationChanged(Location location) { if (DEBUG)/*ww w.j av a 2 s . c o m*/ Log.i(TAG, "Location search succeeded"); LocationManager locationManager = (LocationManager) mContext.getSystemService(Context.LOCATION_SERVICE); if (ContextCompat.checkSelfPermission(mContext, Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) locationManager.removeUpdates(this); String prefKey = mContext.getString(R.string.pref_key_location); SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(mContext); SharedPreferences.Editor editor = sp.edit(); editor.putString(prefKey, location.getLatitude() + "," + location.getLongitude()); editor.apply(); if (mPreference != null) mPreference.handleLocationFound(location); }