Example usage for android.location GpsStatus GPS_EVENT_STOPPED

List of usage examples for android.location GpsStatus GPS_EVENT_STOPPED

Introduction

In this page you can find the example usage for android.location GpsStatus GPS_EVENT_STOPPED.

Prototype

int GPS_EVENT_STOPPED

To view the source code for android.location GpsStatus GPS_EVENT_STOPPED.

Click Source Link

Document

Event sent when the GPS system has stopped.

Usage

From source file:com.androzic.location.LocationService.java

@Override
public void onGpsStatusChanged(int event) {
    switch (event) {
    case GpsStatus.GPS_EVENT_STARTED:
        updateProvider(LocationManager.GPS_PROVIDER, true);
        updateGpsStatus(GPS_SEARCHING, 0, 0);
        break;//from   w w w  .ja v a2s.  c o  m
    case GpsStatus.GPS_EVENT_FIRST_FIX:
        isContinous = false;
        break;
    case GpsStatus.GPS_EVENT_STOPPED:
        tearTrack();
        updateGpsStatus(GPS_OFF, 0, 0);
        updateProvider(LocationManager.GPS_PROVIDER, false);
        break;
    case GpsStatus.GPS_EVENT_SATELLITE_STATUS:
        if (locationManager == null)
            return;
        GpsStatus gpsStatus = locationManager.getGpsStatus(null);
        Iterator<GpsSatellite> it = gpsStatus.getSatellites().iterator();
        int tSats = 0;
        int fSats = 0;
        while (it.hasNext()) {
            tSats++;
            GpsSatellite sat = (GpsSatellite) it.next();
            if (sat.usedInFix())
                fSats++;
        }
        if (SystemClock.elapsedRealtime() - lastLocationMillis < 3000) {
            updateGpsStatus(GPS_OK, fSats, tSats);
        } else {
            tearTrack();
            updateGpsStatus(GPS_SEARCHING, fSats, tSats);
        }
        break;
    }
}

From source file:de.bogutzky.psychophysiocollector.app.MainActivity.java

private void startStreamingInternalSensorData() {
    internalSensorManager = new InternalSensorManager(root, new int[] { 1000, 1000, 1000 }, this);
    internalSensorManager.startStreaming();

    locationListener = new GPSListener(getString(R.string.file_name_gps_position), this.directoryName, 25,
            this);
    if (ContextCompat.checkSelfPermission(this,
            Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
            && ContextCompat.checkSelfPermission(this,
                    Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
        ActivityCompat.requestPermissions(this, new String[] {
                android.Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION },
                PERMISSIONS_REQUEST);//from w  w w .ja v  a 2s . c  o  m

    } else {
        locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);
        locationManager.addGpsStatusListener(new GpsStatus.Listener() {
            @Override
            public void onGpsStatusChanged(int event) {
                switch (event) {
                case GpsStatus.GPS_EVENT_STARTED:
                    gpsStatusText = getString(R.string.info_connected);
                    break;
                case GpsStatus.GPS_EVENT_STOPPED:
                    gpsStatusText = getString(R.string.info_not_connected);
                    break;
                case GpsStatus.GPS_EVENT_FIRST_FIX:
                    gpsStatusText = getString(R.string.info_connected_fix_received);
                    break;
                }
            }
        });
    }
}