本文整理了Java中android.location.LocationManager.removeUpdates()
方法的一些代码示例,展示了LocationManager.removeUpdates()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。LocationManager.removeUpdates()
方法的具体详情如下:
包路径:android.location.LocationManager
类名称:LocationManager
方法名:removeUpdates
暂无
代码示例来源:origin: stackoverflow.com
lm = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
try{gps_enabled=lm.isProviderEnabled(LocationManager.GPS_PROVIDER);}catch(Exception ex){}
try{network_enabled=lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER);}catch(Exception ex){}
timer1.cancel();
locationResult.gotLocation(location);
lm.removeUpdates(this);
lm.removeUpdates(locationListenerNetwork);
timer1.cancel();
locationResult.gotLocation(location);
lm.removeUpdates(this);
lm.removeUpdates(locationListenerGps);
@Override
public void run() {
lm.removeUpdates(locationListenerGps);
lm.removeUpdates(locationListenerNetwork);
gps_loc=lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if(network_enabled)
net_loc=lm.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
代码示例来源:origin: stackoverflow.com
Location location = mLocationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if(location != null && location.getTime() > Calendar.getInstance().getTimeInMillis() - 2 * 60 * 1000) {
mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
if (location != null) {
Log.v("Location Changed", location.getLatitude() + " and " + location.getLongitude());
mLocationManager.removeUpdates(this);
代码示例来源:origin: facebook/facebook-android-sdk
private Location getFreshLocation() throws ScannerException {
freshLocation = null;
HandlerThread handlerThread = new HandlerThread("LocationScanner");
try {
handlerThread.start();
for (String provider : enabledProviders) {
locationManager.requestLocationUpdates(
provider,
MIN_TIME_BETWEEN_UPDATES,
MIN_DISTANCE_BETWEEN_UPDATES,
this,
handlerThread.getLooper());
}
try {
synchronized (scanLock) {
scanLock.wait(params.getLocationRequestTimeoutMs());
}
} catch (Exception e) {
// ignore
}
} finally {
locationManager.removeUpdates(this);
handlerThread.quit();
}
if (freshLocation == null) {
throw new ScannerException(ScannerException.Type.TIMEOUT);
}
return freshLocation;
}
代码示例来源:origin: stackoverflow.com
locationManager = (LocationManager) mContext.getSystemService(Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(bestAvailableProvider, minTime, minDistance, this);
} else {
public void deactivate() {
locationManager.removeUpdates(this);
代码示例来源:origin: stackoverflow.com
boolean gpsIsEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
boolean networkIsEnabled = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 5000L, 10F, this);
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 5000L, 10F, this);
locationManager.removeUpdates(this);
代码示例来源:origin: stackoverflow.com
Criteria criteria = new Criteria();
String provider = locationManager.getBestProvider(criteria, false);
Location location = locationManager.getLastKnownLocation(provider);
System.out.println("Location not avilable");
locationManager.removeUpdates(this);
代码示例来源:origin: stackoverflow.com
try {
locationManager = (LocationManager) mContext
.getSystemService(LOCATION_SERVICE);
.isProviderEnabled(LocationManager.GPS_PROVIDER);
.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
this.canGetLocation = true;
if (isNetworkEnabled) {
locationManager.requestLocationUpdates(
LocationManager.NETWORK_PROVIDER,
MIN_TIME_BW_UPDATES,
if (locationManager != null) {
location = locationManager
.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
if (location != null) {
latitude = location.getLatitude();
locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER,
MIN_TIME_BW_UPDATES,
locationManager.removeUpdates(GPSTracker.this);
alertDialog.setMessage("GPS is not enabled. Do you want to go to settings menu?");
代码示例来源:origin: stackoverflow.com
locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
if(gpsProvider != null)
locationManager.requestLocationUpdates(gpsProvider.getName(), 0, 10, this);
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 1000 * 60 * 5, 0, this);
public void deactivate()
locationManager.removeUpdates(this);
代码示例来源:origin: stackoverflow.com
Location location = locationManager.getLastKnownLocation(provider);
protected void onResume() {
super.onResume();
locationManager.requestLocationUpdates(provider, 400, 1, this);
protected void onPause() {
super.onPause();
locationManager.removeUpdates(this);
代码示例来源:origin: commonsguy/cw-omnibus
@SuppressLint("MissingPermission")
private void follow() {
if (map!=null && locMgr!=null) {
if (autoFollow) {
locMgr.requestLocationUpdates(0L, 0.0f, crit, this, null);
map.setLocationSource(this);
map.getUiSettings().setMyLocationButtonEnabled(false);
}
else {
map.getUiSettings().setMyLocationButtonEnabled(true);
map.setLocationSource(null);
locMgr.removeUpdates(this);
}
}
}
}
代码示例来源:origin: stackoverflow.com
if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
protected void onStart() {
super.onStart();
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0,
0, this);
locationManager.removeUpdates(this);
super.onStop();
代码示例来源:origin: openbmap/radiocells-scanner-android
@Override
public void run() {
mLocationManager.removeUpdates(locationListenerGps);
mLocationManager.removeUpdates(locationListenerNetwork);
Location net_loc = null, gps_loc = null;
if (mGpsEnabled)
gps_loc = mLocationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if (mNetworkEnabled)
net_loc = mLocationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
//if there are both values use the latest one
if (gps_loc != null && net_loc != null){
if (gps_loc.getTime() > net_loc.getTime())
mLocationResult.gotLocation(gps_loc);
else
mLocationResult.gotLocation(net_loc);
return;
}
if (gps_loc != null) {
mLocationResult.gotLocation(gps_loc);
return;
}
if (net_loc != null) {
mLocationResult.gotLocation(net_loc);
return;
}
mLocationResult.gotLocation(null);
}
}
代码示例来源:origin: stackoverflow.com
locationManager = (LocationManager) mContext.getSystemService(LOCATION_SERVICE);
isGPSEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
isNetworkEnabled = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
locationManager.requestLocationUpdates(
provider_info,
MIN_TIME_BW_UPDATES,
location = locationManager.getLastKnownLocation(provider_info);
updateGPSCoordinates();
locationManager.removeUpdates(GPSTracker.this);
alertDialog.setMessage(R.string.GPSAlertDialogMessage);
代码示例来源:origin: stackoverflow.com
locationManager = (LocationManager) mContext.getSystemService(Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(bestAvailableProvider, minTime, minDistance, this);
} else {
public void deactivate() {
locationManager.removeUpdates(this);
代码示例来源:origin: qqq3/good-weather
@Override
public void run() {
locationManager.removeUpdates(mLocationListener);
if (ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
Location lastLocation = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if (lastLocation != null) {
mLocationListener.onLocationChanged(lastLocation);
} else {
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, mLocationListener);
}
}
}
}, LOCATION_TIMEOUT_IN_MS);
代码示例来源:origin: robolectric/robolectric
@Test
public void shouldRemoveLocationListeners() throws Exception {
TestLocationListener listener = new TestLocationListener();
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 1, 2.0f, listener);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1, 2.0f, listener);
TestLocationListener otherListener = new TestLocationListener();
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 1, 2.0f, otherListener);
locationManager.removeUpdates(listener);
List<LocationListener> expected = new ArrayList<>();
expected.add(otherListener);
assertThat(shadowLocationManager.getRequestLocationUpdateListeners()).isEqualTo(expected);
}
代码示例来源:origin: Shimingli/PerformanceOptimizationForAndroid
@Override
public void onLocationChanged(Location location) {
// thread is not runable, msg ignore, state:TIMED_WAITING, 这里的线程有可能ANR
if (location != null) {
double lat = location.getLatitude();//获取纬度
double lng = location.getLongitude();//获取经度
System.out.println("shiming lat+" + lat);
System.out.println("shiming lng+" + lng);
String name = Thread.currentThread().getName();
mCount++;
System.out.println("当前线程的位置name---"+name+"i==="+mCount);
mTv_location.setText("位置信息是2s变动的,可以设置,我是第"+mCount+"次变动的--->"+"\n\r"+"lat===="+lat+" lng----->"+lng);
}
if (mLocationManager!=null) {
mLocationManager.removeUpdates(this);
if (mLocationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
mLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 2000, 1000, mLlistener);
}else {
mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 2000, 1000, mLlistener);
}
// TODO: 2018/5/3 这里在报错了,我把他注释掉
// mLocationManager.setTestProviderEnabled(mProvider, false);// java.lang.IllegalArgumentException: Provider "network" unknown
}
}
代码示例来源:origin: stackoverflow.com
lm = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
try{gps_enabled=lm.isProviderEnabled(LocationManager.GPS_PROVIDER);}catch(Exception ex){}
try{network_enabled=lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER);}catch(Exception ex){}
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListenerGps);
if(network_enabled)
lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListenerNetwork);
timer1=new Timer();
timer1.cancel();
locationResult.gotLocation(location);
lm.removeUpdates(this);
lm.removeUpdates(locationListenerNetwork);
timer1.cancel();
locationResult.gotLocation(location);
lm.removeUpdates(this);
lm.removeUpdates(locationListenerGps);
gps_loc=lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if(network_enabled)
net_loc=lm.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
代码示例来源:origin: stackoverflow.com
public void FindLocation(Context context){
final LocationManager locationManager (LocationManager)context.getSystemService(Context.LOCATION_SERVICE);
LocationListener locationListener = new LocationListener(){
public void onLocationChanged(Location location){
updateLocation(location);
locationManager.removeUpdates(this);
}
public void onStatusChanged(String provider, int status, Bundle extras) {}
public void onProviderEnabled(String provider) {}
public void onProviderDisabled(String provider) {}
};
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);
}
代码示例来源:origin: qqq3/good-weather
@Override
public void run() {
locationManager.removeUpdates(mLocationListener);
if (ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
Location lastNetworkLocation = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
Location lastGpsLocation = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if ((lastGpsLocation == null) && (lastNetworkLocation != null)) {
mLocationListener.onLocationChanged(lastNetworkLocation);
} else if ((lastGpsLocation != null) && (lastNetworkLocation == null)) {
mLocationListener.onLocationChanged(lastGpsLocation);
} else {
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, mLocationListener);
}
}
}
}, LOCATION_TIMEOUT_IN_MS);
内容来源于网络,如有侵权,请联系作者删除!