我试图在Android中的每个GPS定位之间设置一个5分钟的间隔。我的代码如下所示:设置每个GPS定位之间的间隔
private void startMonitoring() {
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
locationListener = new LocListener();
if (locationManager.isProviderEnabled(locationManager.GPS_PROVIDER)){
startUpdates();
} else {
// I open here the preferences to force the user start the GPS
}
}
private void startUpdates(){
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);
}
public class LocListener implements LocationListener{
@Override
public void onLocationChanged(Location loc){
...
locationManager.removeUpdates(locationListener);
scheduleUpdates();
}
...
}
private void scheduleUpdates(){
// Wait 5 minutes
handler.sleep(5 * 60 * 1000);
startUpdates();
}
class WaitHandler extends Handler {
@Override
public void handleMessage(Message message) {}
public void sleep (long delayMillis){
this.removeMessages(0);
sendMessageDelayed(obtainMessage(0), delayMillis);
}
}
我一直在这几个小时,但我一直没能找到一个好的解决办法呢。任何帮助,将不胜感激,
非常感谢你,
它的作品!谢谢! – Ullfoll 2011-04-23 18:30:16