【发布时间】:2012-02-07 23:26:07
【问题描述】:
我尝试使用我的LocationListener 进行两步位置检测。它按预期在每个 android 版本上按预期工作。只有在 ICS 上我无法停止 GPS 位置检测。
// inner class inside my PoiActivity
private class CustomLocationListener implements LocationListener {
String currentProvider = LocationManager.NETWORK_PROVIDER;
@Override
public void onLocationChanged(Location location) {
if (location != null) {
if (currentProvider.equals(LocationManager.NETWORK_PROVIDER)) {
System.out.println(this);
mLastKnownLocation = location;
mHandler.sendEmptyMessage(0);
mLocationManager.removeUpdates(this);
Log.i("CustomLocationListener", "Got a rough location, removing the network listener ");
Toast.makeText(PoiActivity.this, "Network found and removed", Toast.LENGTH_LONG).show();
mLocationManager
.requestLocationUpdates(LocationManager.GPS_PROVIDER, 10000, Constants.LOCATION_MAX_ACCURACY, this);
currentProvider = LocationManager.GPS_PROVIDER;
} else if (location.getAccuracy() < Constants.LOCATION_MAX_ACCURACY
&& currentProvider.equals(LocationManager.GPS_PROVIDER)) {
System.out.println(this);
mLastKnownLocation = location;
mHandler.sendEmptyMessage(0);
mLocationManager.removeUpdates(this);
Log.i("CustomLocationListener", "Got a rough location, removing the gps listener ");
Toast.makeText(PoiActivity.this, "GPS found and removed", Toast.LENGTH_LONG).show();
}
}
}
@Override
public void onProviderDisabled(String provider) {}
@Override
public void onProviderEnabled(String provider) {}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {}
}
根据 Toast 和 LogCat 信息,侦听器已被删除,并且在除 ICS 之外的每个版本上,我都看到 GPS 图标消失了。在 ICS 上,该图标会在几秒钟后重新出现,但我从未多次收到 Toast,因此我的侦听器已成功删除。
使用任务管理器或通过应用程序信息杀死应用程序并不会阻止 GPS 图标一次又一次地出现。
我猜这是一个特定的 ICS 问题,但我找不到关于该问题或类似问题描述的错误报告。
有人有解决方法吗?因为我不希望用户有这样的感觉,我拉了好几次,没有任何好处消耗电池......
【问题讨论】:
标签: android gps android-4.0-ice-cream-sandwich locationmanager