我試圖在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