1

一部の Android デバイスで次のコードを使用しています。非常に頻繁に (90% の確率で) 75 秒以内に GPS の更新がありません。

問題に対する提案はありますか?

public class GPSLogger extends AbstractLoggerComponent {

    private static GPSLogger singleton = new GPSLogger();

    private LocationManager locationManager;
    private LocationListener locationListener;

    private Context context;

    /**
     * GPSLogger.
     */
    private GPSLogger() { 

    }

    /**
     * @return singleton instance
     */
    public static GPSLogger getInstance() {
        return singleton;
    }

    /** {@inheritDoc} */
    @Override
    public void initialise(Context context) {
        this.context = context;
        this.locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
        this.locationListener = new GPSLocationListener(); 
        super.initialise(context);
    }

    /** {@inheritDoc} */
    @Override
    protected void start() {
        new Thread((new Runnable() {
            /** {@inheritDoc} */
            @Override
            public void run() {
                Looper.prepare(); 
                locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 10000, 0, locationListener);
                Looper.loop();
            }
        })).start();
    }

    /** {@inheritDoc} */
    @Override
    protected void stop()
    {
        this.locationManager.removeUpdates(this.locationListener);
    }

    /**
     * GPSLocationListener.
     *
     * The custom GPSLocationListener
     */
    private class GPSLocationListener implements LocationListener {

        /** {@inheritDoc} */
        @Override
        public void onLocationChanged(Location location)
        {           
            GPSSample gpsSample = new GPSSample();
            gpsSample.setAccurracy(location.getAccuracy());
            gpsSample.setBearing(location.getBearing());
            gpsSample.setLatitude(location.getLatitude());
            gpsSample.setLongitude(location.getLongitude());
            gpsSample.setSpeed(location.getSpeed());
            gpsSample.setTimestamp(System.currentTimeMillis());
            gpsSample.setAltitude(location.getAltitude());
            gpsSample.setProvider(location.getProvider());

            singleton.setChanged();
            singleton.notifyObservers(gpsSample);
        }

        /** {@inheritDoc} */
        @Override
        public void onStatusChanged(String provider, int status, Bundle extras) { }

        /** {@inheritDoc} */
        @Override
        public void onProviderEnabled(String provider) { }

        /** {@inheritDoc} */
        @Override
        public void onProviderDisabled(String provider) { }
    }

    /** {@inheritDoc} */
    @Override
    protected String getName() {
        return "GPSLogger";
    }
}
4

0 に答える 0