How to collect location data every 10 seconds in Android
<p>I wrote a GPSDataCollectService to collect location data every 10 seconds, but it did not report location in my HTC mobile phone, any wrong? could anyone help me?</p>

<pre><code>package com.android.example;

import java.util.Calendar;
import java.util.Timer;
import java.util.TimerTask;

import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.os.IBinder;
import android.util.Log;

public class GPSDataCollectorService extends Service {

    private static final String TAG = GPSDataCollectorService.class
            .getSimpleName();

    LocationManager locationManager;
    LocationListener gpsLocationListener;

    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }

    private Timer timer;

    private TimerTask collectTask = new TimerTask() {
        @Override
        public void run() {
            Log.i(TAG, "Timer task doing work: "
                    + Calendar.getInstance().getTimeInMillis());
            locationManager = (LocationManager)  getSystemService(Context.LOCATION_SERVICE);
            gpsLocationListener = new GPSLocationListener();
            locationManager.requestLocationUpdates(
                    LocationManager.GPS_PROVIDER, 10 * 1000L, 0,
                    gpsLocationListener);
        }
    };

    @Override
    public void onCreate() {
        super.onCreate();
        Log.i(TAG, "Service creating");
        timer = new Timer("GPSDataCollectorTimer");
        timer.schedule(collectTask, 1000L, 10 * 1000L);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        Log.i(TAG, "Service destroying");
        locationManager.removeUpdates(gpsLocationListener);
        timer.cancel();
        timer = null;
    }

    private class GPSLocationListener implements LocationListener {

        @Override
        public void onLocationChanged(Location location) {
            Log.d(TAG, "onLocationChanged: " + location.toString());
            locationManager.removeUpdates(gpsLocationListener);
        }

        @Override
        public void onStatusChanged(String provider, int status, Bundle extras) {
            Log.d(TAG, "onStatusChanged: " + status);
        }

        @Override
        public void onProviderEnabled(String provider) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onProviderDisabled(String provider) {
            // TODO Auto-generated method stub

        }

    }

}
</code></pre>
