Search in sources :

Example 1 with NmeaListener

use of android.location.GpsStatus.NmeaListener in project android-gps-test-tool by Esri.

the class SatelliteDataActivityController method setLocationListenerGPSProvider.

private void setLocationListenerGPSProvider() {
    _locationListenerGPSProvider = new LocationListener() {

        @Override
        public void onLocationChanged(Location location) {
        // TODO Auto-generated method stub
        }

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

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

        @Override
        public void onStatusChanged(String provider, int status, Bundle extras) {
        // TODO Auto-generated method stub
        }
    };
    _nmeaListener = new NmeaListener() {

        @Override
        public void onNmeaReceived(long timestamp, String nmea) {
            String time = _elapsedTimer.convertMillisToMDYHMSS(timestamp);
            _gpsNMEAText = "<b><font color='yellow'>GPS NMEA</b></font>" + "<br><b>Timestamp:</b> " + time + "<br><b>NMEA code:</b> " + nmea;
            _gpsNMEATextView.setText(Html.fromHtml(_gpsNMEAText));
        }
    };
    _locationManager.addNmeaListener(_nmeaListener);
    _gpsStatusListener = new GpsStatus.Listener() {

        String seconds;

        String minutes;

        String hours;

        String ms;

        String satelliteHMS;

        String usedInFix = "false";

        int t;

        @Override
        public void onGpsStatusChanged(int event) {
            _satelliteList = "";
            satelliteHMS = "N/A";
            //Occasionally there may be null values if GPS hiccups
            try {
                t = _locationManager.getGpsStatus(null).getTimeToFirstFix();
                //String seconds = String.format(_format, t/1000 % 60);
                seconds = String.format(_format, TimeUnit.MILLISECONDS.toSeconds(t));
                minutes = String.format(_format, TimeUnit.MILLISECONDS.toMinutes(t));
                hours = String.format(_format, TimeUnit.MILLISECONDS.toHours(t));
                ms = String.format(_format, t % 1000);
                satelliteHMS = hours + ":" + minutes + ":" + seconds + ":" + ms;
                _satellites = _locationManager.getGpsStatus(null).getSatellites();
                if (_satellites != null) {
                    for (GpsSatellite sat : _satellites) {
                        if (sat.usedInFix() == true) {
                            usedInFix = "<font color='red'>true</font>";
                        } else {
                            usedInFix = "false";
                        }
                        _satelliteList = _satelliteList + "<br>" + sat.getPrn() + ", " + sat.getSnr() + ", " + usedInFix;
                    }
                }
            } catch (Exception exc) {
                Log.d("GPSTester", "GPS Status error (onGpsStatusChanged): " + exc.getMessage());
            }
            if (_satelliteList != "") {
                _gpsSatelliteTextView.setText(Html.fromHtml("<b><font color='yellow'>GPS Satellite Info (No., SNR, Used in fix)</b></font>" + "<br><b>Time to 1st fix:</b> " + satelliteHMS + _satelliteList));
            }
        }
    };
    _locationManager.addGpsStatusListener(_gpsStatusListener);
    try {
        long minDistance = Long.valueOf(_preferences.getString("pref_key_updateGPSMinDistance", "0"));
        long minTime = Long.valueOf(_preferences.getString("pref_key_updateGPSMinTime", "0"));
        // Register the listener with the Location Manager to receive location updates
        _locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, minTime, minDistance, _locationListenerGPSProvider);
    } catch (Exception exc) {
        Log.d("GPSTester", "Unable to start GPS provider. Bad value. " + exc.getMessage());
    }
}
Also used : NmeaListener(android.location.GpsStatus.NmeaListener) GpsStatus(android.location.GpsStatus) GpsSatellite(android.location.GpsSatellite) Bundle(android.os.Bundle) LocationListener(android.location.LocationListener) Location(android.location.Location)

Aggregations

GpsSatellite (android.location.GpsSatellite)1 GpsStatus (android.location.GpsStatus)1 NmeaListener (android.location.GpsStatus.NmeaListener)1 Location (android.location.Location)1 LocationListener (android.location.LocationListener)1 Bundle (android.os.Bundle)1