List of usage examples for android.location LocationManager removeUpdates
public void removeUpdates(PendingIntent intent)
From source file:it.geosolutions.geocollect.android.core.mission.PendingMissionListActivity.java
@Override protected void onPause() { super.onPause(); if (mReceiver != null) { unregisterReceiver(mReceiver);/*from w w w .j a va 2 s . c o m*/ } LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); if (locationManager != null) { locationManager.removeUpdates(this); } }
From source file:com.platform.GeoLocationManager.java
public void stopGeoSocket() { final MainActivity app = MainActivity.app; if (app == null) return;/*from www. ja v a2 s . c om*/ final LocationManager locationManager = (LocationManager) app.getSystemService(Context.LOCATION_SERVICE); app.runOnUiThread(new Runnable() { @Override public void run() { if (ActivityCompat.checkSelfPermission(app, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(app, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { Log.e(TAG, "stopGeoSocket, can't happen"); RuntimeException ex = new RuntimeException("stopGeoSocket, can't happen"); FirebaseCrash.report(ex); throw ex; } locationManager.removeUpdates(socketLocationListener); } }); }
From source file:org.akvo.rsr.up.UpdateEditorActivity.java
/** * When the user clicks the "Get Location" button, start listening for * location updates//from ww w . j a v a2s . c om */ public void onGetGPSClick(View v) { LocationManager locMgr = (LocationManager) getSystemService(Context.LOCATION_SERVICE); if (needUpdate) {//turn off needUpdate = false; btnGpsGeo.setText(R.string.btncaption_gps_position); locMgr.removeUpdates(this); searchingIndicator.setText(""); accuracyField.setText(""); gpsProgress.setVisibility(View.GONE); //hide in-progress wheel } else {//turn on if (locMgr.isProviderEnabled(LocationManager.GPS_PROVIDER)) { positionGroup.setVisibility(View.VISIBLE); accuracyField.setText("?"); accuracyField.setTextColor(Color.WHITE); latField.setText(""); lonField.setText(""); eleField.setText(""); btnGpsGeo.setText(R.string.btncaption_gps_cancel); gpsProgress.setVisibility(View.VISIBLE); //Hide progress needUpdate = true; searchingIndicator.setText(R.string.label_gps_searching); lastAccuracy = UNKNOWN_ACCURACY; locMgr.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this); } else { // we can't turn GPS on directly, the best we can do is launch the // settings page DialogUtil.showGPSDialog(this); } } }
From source file:at.ac.uniklu.mobile.sportal.service.MutingService.java
private void mute(int alarmId) { Log.d(TAG, "mute()"); SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); if (Preferences.getLocationStatus(preferences) == Preferences.LOCATION_STATUS_WAITING) { Log.d(TAG, "mute() blocked - waiting for a location update"); return;/*w w w. ja va2s . c o m*/ } // check if phone is already muted by the user AudioManager audioManager = (AudioManager) getSystemService(AUDIO_SERVICE); boolean isPhoneAlreadyMuted = audioManager.getRingerMode() != AudioManager.RINGER_MODE_NORMAL && !Preferences.isMutingPeriod(preferences); if (isPhoneAlreadyMuted) { Log.d(TAG, "phone is already muted, scheduling next mute"); scheduleMute(true); return; } // load the current period from the db MutingPeriod mutingPeriod = null; Log.d(TAG, "muting period id: " + alarmId); if (DEBUG_WITH_FAKE_ALARMS) { mutingPeriod = new MutingPeriod(); mutingPeriod.setId(-1); mutingPeriod.setBegin(System.currentTimeMillis()); mutingPeriod.setEnd(mutingPeriod.getBegin() + 10000); mutingPeriod.setName("Fakeevent"); } else { mutingPeriod = Studentportal.getStudentPortalDB().mutingPeriods_getPeriod(alarmId); } // check if phone is located at university notifyUser(Studentportal.NOTIFICATION_MS_INFO, true, mutingPeriod.getName(), mutingPeriod.getName(), getString(R.string.automute_notification_course_started_locating)); boolean isPhoneLocationKnown = false; boolean isPhoneLocatedAtUniversity = false; String locationSource = null; WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE); if (wifiManager.isWifiEnabled()) { ScanResult scanResult = MutingUtils.findMutingWifiNetwork(wifiManager.getScanResults()); if (scanResult != null) { Log.d(TAG, "phone located by wifi: " + scanResult.SSID); isPhoneLocationKnown = true; isPhoneLocatedAtUniversity = true; locationSource = "wifi (" + scanResult.SSID + ")"; } } if (!isPhoneLocationKnown) { // phone location could not be determined by wifi, trying network location instead... LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE); if (locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) { Intent locationIntent = new Intent("at.ac.uniklu.mobile.sportal.LOCATION_UPDATE") .putExtra(EXTRA_ALARM_ID, alarmId); PendingIntent pendingLocationIntent = PendingIntent.getBroadcast(this, 0, locationIntent, PendingIntent.FLAG_UPDATE_CURRENT); // remove the location receiver (so it doesn't get registered multiple times [could also happen on overlapping mute() calls) locationManager.removeUpdates(pendingLocationIntent); if (Preferences.getLocationStatus(preferences) == Preferences.LOCATION_STATUS_RECEIVED) { isPhoneLocationKnown = true; pendingLocationIntent.cancel(); Location location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); if (location == null) { Log.d(TAG, "location received but still null"); } else { MutingRegion mutingRegion = MutingUtils.findOverlappingMutingRegion(location); if (mutingRegion != null) { Log.d(TAG, "phone located by network @ " + mutingRegion.getName()); isPhoneLocatedAtUniversity = true; locationSource = "location (" + mutingRegion.getName() + ")"; } } } else { Log.d(TAG, "trying to locate the phone by network..."); // wait for a location update Preferences.setLocationStatus(preferences, Preferences.LOCATION_STATUS_WAITING); locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, pendingLocationIntent); return; // exit method - it will be re-called from the location broadcast receiver on a location update } } } boolean isAlwaysMuteEnabled = Preferences.isAutomuteWithoutLocation(this, preferences); if (isPhoneLocationKnown) { if (!isPhoneLocatedAtUniversity) { Log.d(TAG, "phone is not located at university, scheduling next mute"); scheduleMute(true); removeNotification(Studentportal.NOTIFICATION_MS_INFO); return; } } else { Log.d(TAG, "phone cannot be located"); if (!isAlwaysMuteEnabled) { Log.d(TAG, "alwaysmute is disabled, scheduling next mute"); Preferences.setLocationStatus(preferences, Preferences.LOCATION_STATUS_NONE); scheduleMute(true); removeNotification(Studentportal.NOTIFICATION_MS_INFO); return; } } // only turn the ringtone off if we aren't currently in a muting period. // if we are in a muting period the ringtone is already muted and the request should be ignored, // else rintoneTurnOn() won't turn the ringtone back on because ringtone override will be set to true if (!Preferences.isMutingPeriod(preferences)) { MutingUtils.ringtoneTurnOff(this); } // persist that from now on the phone is in a muting period Preferences.setMutingPeriod(preferences, true); // inform user via a notification that a course has started and the phone has been muted notifyUser(Studentportal.NOTIFICATION_MS_INFO, true, mutingPeriod.getName(), mutingPeriod.getName(), getString(R.string.automute_notification_course_muted)); final boolean isPhoneLocationKnownAnalytics = isPhoneLocationKnown; final String locationSourceAnalytics = locationSource; Analytics.onEvent(Analytics.EVENT_MUTINGSERVICE_MUTE, "isPhoneLocationKnown", isPhoneLocationKnownAnalytics + "", "locationSource", locationSourceAnalytics); scheduleUnmute(mutingPeriod.getEnd()); }
From source file:com.google.android.apps.paco.ExperimentExecutorCustomRendering.java
private void unregisterLocationListener() { LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE); if (lm != null) { lm.removeUpdates(this); }//from w w w . ja v a 2 s .c o m }
From source file:net.imatruck.betterweather.BetterWeatherExtension.java
/** * Disables the location listener/*from www . j a v a2 s. com*/ */ private void disableOneTimeLocationListener() { if (mOneTimeLocationListenerActive) { LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE); if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { LOGE(TAG, "Location permission was not granted, cannot remove location updates"); return; } lm.removeUpdates(mOneTimeLocationListener); mOneTimeLocationListenerActive = false; } }
From source file:org.planetmono.dcuploader.ActivityUploader.java
@Override public void onDestroy() { super.onDestroy(); Log.d(Application.TAG, "stopping activity."); /* stop location query when going out */ if (locationEnabled) { LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE); lm.removeUpdates(locationTracker); }//from w ww. ja v a 2s .c o m for (String path : tempFiles) new File(path).delete(); tempFiles.clear(); }
From source file:org.ohmage.reminders.types.location.LocTrigService.java
private void stopGPS() { if (!mGPSStarted) { return;//from w w w .ja v a 2 s . c o m } cancelSamplingAlarm(ACTION_ALRM_GPS_TIMEOUT); Log.v(TAG, "LocTrigService: Turning off location updates"); LocationManager locMan = (LocationManager) getSystemService(LOCATION_SERVICE); locMan.removeUpdates(this); if (LocTrigConfig.useNetworkLocation) { if (mWifiLock != null) { if (mWifiLock.isHeld()) { mWifiLock.release(); } } } mGPSStarted = false; }
From source file:org.ohmage.triggers.types.location.LocTrigService.java
private void stopGPS() { if (!mGPSStarted) { return;// w ww . ja v a2 s .c o m } cancelSamplingAlarm(ACTION_ALRM_GPS_TIMEOUT); Log.i(DEBUG_TAG, "LocTrigService: Turning off location updates"); LocationManager locMan = (LocationManager) getSystemService(LOCATION_SERVICE); locMan.removeUpdates(this); if (LocTrigConfig.useNetworkLocation) { if (mWifiLock != null) { if (mWifiLock.isHeld()) { mWifiLock.release(); } } } mGPSStarted = false; }
From source file:org.mozilla.gecko.GeckoAppShell.java
public static void enableLocation(final boolean enable) { getMainHandler().post(new Runnable() { public void run() { LayerView v = GeckoApp.mAppContext.getLayerController().getView(); LocationManager lm = (LocationManager) GeckoApp.mAppContext .getSystemService(Context.LOCATION_SERVICE); if (enable) { Criteria criteria = new Criteria(); String provider = lm.getBestProvider(criteria, true); if (provider == null) return; Looper l = Looper.getMainLooper(); Location loc = lm.getLastKnownLocation(provider); if (loc != null) { GeckoApp.mAppContext.onLocationChanged(loc); }//from w w w. ja va2 s . c o m lm.requestLocationUpdates(provider, 100, (float) .5, GeckoApp.mAppContext, l); } else { lm.removeUpdates(GeckoApp.mAppContext); } } }); }