Example usage for android.location GpsStatus getSatellites

List of usage examples for android.location GpsStatus getSatellites

Introduction

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

Prototype

public Iterable<GpsSatellite> getSatellites() 

Source Link

Document

Returns an array of GpsSatellite objects, which represent the current state of the GPS engine.

Usage

From source file:com.esri.cordova.geolocation.utils.JSONHelper.java

/**
 * Converts GpsStatus into JSON.//from w  w  w .j  av a2  s .c om
 * @param gpsStatus Send a GpsStatus whenever the GPS fires
 * @return JSON representation of the satellite data
 */
public static String satelliteDataJSON(GpsStatus gpsStatus) {

    final Calendar calendar = Calendar.getInstance();
    final JSONObject json = new JSONObject();

    try {
        json.put("provider", SATELLITE_PROVIDER);
        json.put("timestamp", calendar.getTimeInMillis());

        if (gpsStatus.getSatellites() != null) {
            int count = 0;
            final int timeToFirstFix = gpsStatus.getTimeToFirstFix();

            for (GpsSatellite sat : gpsStatus.getSatellites()) {
                final JSONObject satelliteInfo = new JSONObject();

                satelliteInfo.put("PRN", sat.getPrn());
                satelliteInfo.put("timeToFirstFix", timeToFirstFix);
                satelliteInfo.put("usedInFix", sat.usedInFix());
                satelliteInfo.put("azimuth", sat.getAzimuth());
                satelliteInfo.put("elevation", sat.getElevation());
                satelliteInfo.put("hasEphemeris", sat.hasEphemeris());
                satelliteInfo.put("hasAlmanac", sat.hasAlmanac());
                satelliteInfo.put("SNR", sat.getSnr());

                json.put(Integer.toString(count), satelliteInfo);

                count++;
            }
        }
    } catch (JSONException exc) {
        logJSONException(exc);
    }

    return json.toString();
}

From source file:com.vonglasow.michael.satstat.PasvLocListenerService.java

@Override
public void onGpsStatusChanged(int event) {
    GpsStatus status = mLocationManager.getGpsStatus(null);
    int satsUsed = 0;
    Iterable<GpsSatellite> sats = status.getSatellites();
    for (GpsSatellite sat : sats) {
        if (sat.usedInFix()) {
            satsUsed++;/*from   w  w  w. j a va  2 s . c o m*/
        }
    }
    if (satsUsed == 0) {
        if (mStatus != GPS_INACTIVE)
            mStatus = GPS_SEARCH;
        showStatusNoLocation();
    }
}

From source file:org.mozilla.mozstumbler.service.stumblerthread.scanners.GPSScanner.java

private void startActiveMode() {
    LocationManager lm = getLocationManager();
    if (!isGpsAvailable(lm)) {
        return;/*from www .  ja  v a 2  s. co m*/
    }

    lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, ACTIVE_MODE_GPS_MIN_UPDATE_TIME_MS,
            ACTIVE_MODE_GPS_MIN_UPDATE_DISTANCE_M, this);

    reportLocationLost();

    mGPSListener = new GpsStatus.Listener() {
        public void onGpsStatusChanged(int event) {
            if (event == GpsStatus.GPS_EVENT_SATELLITE_STATUS) {
                GpsStatus status = getLocationManager().getGpsStatus(null);
                Iterable<GpsSatellite> sats = status.getSatellites();

                int satellites = 0;
                int fixes = 0;

                for (GpsSatellite sat : sats) {
                    satellites++;
                    if (sat.usedInFix()) {
                        fixes++;
                    }
                }

                if (fixes < MIN_SAT_USED_IN_FIX) {
                    reportLocationLost();
                }
            } else if (event == GpsStatus.GPS_EVENT_STOPPED) {
                reportLocationLost();
            }
        }
    };

    lm.addGpsStatusListener(mGPSListener);
}

From source file:com.vonglasow.michael.satstat.PasvLocListenerService.java

@Override
public void onLocationChanged(Location location) {
    if (!location.getProvider().equals(LocationManager.GPS_PROVIDER))
        return;/*from   w  w w.j a v  a2s .  c o m*/
    if (mNotifyFix && (mStatus != GPS_INACTIVE)) {
        mStatus = GPS_FIX;
        GpsStatus status = mLocationManager.getGpsStatus(null);
        int satsInView = 0;
        int satsUsed = 0;
        Iterable<GpsSatellite> sats = status.getSatellites();
        for (GpsSatellite sat : sats) {
            satsInView++;
            if (sat.usedInFix()) {
                satsUsed++;
            }
        }
        double lat = Math.abs(location.getLatitude());
        double lon = Math.abs(location.getLongitude());
        String ns = (location.getLatitude() > 0) ? getString(R.string.value_N)
                : (location.getLatitude() < 0) ? getString(R.string.value_S) : "";
        String ew = (location.getLongitude() > 0) ? getString(R.string.value_E)
                : (location.getLongitude() < 0) ? getString(R.string.value_W) : "";
        String title = String.format("%.5f%s%s %.5f%s%s", lat, getString(R.string.unit_degree), ns, lon,
                getString(R.string.unit_degree), ew);
        String text = "";
        if (location.hasAltitude()) {
            text = text + String.format("%.0f%s", location.getAltitude(), getString(R.string.unit_meter));
        }
        if (location.hasSpeed()) {
            text = text + (text.equals("") ? "" : ", ")
                    + String.format("%.0f%s", (location.getSpeed() * 3.6), getString(R.string.unit_km_h));
        }
        if (location.hasAccuracy()) {
            text = text + (text.equals("") ? "" : ", ")
                    + String.format("\u03b5 = %.0f%s", location.getAccuracy(), getString(R.string.unit_meter));
        }
        text = text + (text.equals("") ? "" : ", ") + String.format("%d/%d", satsUsed, satsInView);
        text = text + (text.equals("") ? "" : ",\n")
                + String.format("TTFF %d s", status.getTimeToFirstFix() / 1000);
        mBuilder.setSmallIcon(R.drawable.ic_stat_notify_location);
        mBuilder.setContentTitle(title);
        mBuilder.setContentText(text);
        mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(text));

        startForeground(ONGOING_NOTIFICATION, mBuilder.build());
    } else {
        stopForeground(true);
    }
}

From source file:com.tritop.androsense2.fragments.GpsFragment.java

@Override
public void onGpsStatusChanged(int arg0) {
    long triggerTime = System.currentTimeMillis();
    int gpsSatellitesCount = 0;
    int glonassSatellitesCount = 0;
    HashMap<String, String> mSatInfo;
    itemListGps.clear();//from w  w w.  java  2 s  .  c o m
    itemListGlonass.clear();
    GpsStatus gpsStatus = mLocationManager.getGpsStatus(null);
    Iterable<GpsSatellite> gpsSats = gpsStatus.getSatellites();
    for (GpsSatellite sat : gpsSats) {
        if (sat.getPrn() <= 32) {
            gpsSatellitesCount++;
            mSatInfo = new HashMap<String, String>();
            mSatInfo.put(SAT_PNR_KEY, String.valueOf(sat.getPrn()));
            String usedinfix = (sat.usedInFix()) ? "TRUE" : "FALSE";
            mSatInfo.put(SAT_FIX_KEY, usedinfix);
            itemListGps.add(mSatInfo);
        } else {
            glonassSatellitesCount++;
            mSatInfo = new HashMap<String, String>();
            mSatInfo.put(SAT_PNR_KEY, String.valueOf(sat.getPrn()));
            String usedinfix = (sat.usedInFix()) ? "TRUE" : "FALSE";
            mSatInfo.put(SAT_FIX_KEY, usedinfix);
            itemListGlonass.add(mSatInfo);
        }
    }
    if (isLogging && mGpsLog != null) {
        try {
            mGpsLog.logEvent(triggerTime, gpsSatellitesCount + glonassSatellitesCount, gpsSats, mLatitude,
                    mLongitude, mAltitude, mAccuracy);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    satView.setSatellites(gpsSats);
    mGpsListAdapter.notifyDataSetChanged();
    mGlonassListAdapter.notifyDataSetChanged();
    satView.invalidate();
}

From source file:org.destil.gpsaveraging.MainActivity.java

@SuppressWarnings("unused")
@Override/*from   w ww .jav  a 2s .c  om*/
public void onGpsStatusChanged(int status) {
    if (status == GpsStatus.GPS_EVENT_FIRST_FIX) {
        DisplayCoordsNoAveraging();
    } else if (status == GpsStatus.GPS_EVENT_SATELLITE_STATUS) {
        GpsStatus gpsStatus = locationManager.getGpsStatus(null);
        int all = 0;
        Iterable<GpsSatellite> satellites = gpsStatus.getSatellites();
        for (GpsSatellite satellite : satellites) {
            all++;
        }
        uiSatellites.setText(getString(R.string.satellites_info, all));
    } else if (status == GpsStatus.GPS_EVENT_STOPPED) {
        showError(R.string.gps_not_available);
    }
}

From source file:com.alexandreroman.nrelay.NmeaRelayService.java

@Override
public void onGpsStatusChanged(int event) {
    if (GpsStatus.GPS_EVENT_STARTED == event) {
        Log.i(TAG, "GPS started");
    } else if (GpsStatus.GPS_EVENT_STOPPED == event) {
        Log.i(TAG, "GPS stopped");
    } else if (GpsStatus.GPS_EVENT_FIRST_FIX == event) {
        Log.i(TAG, "GPS first fix");
    } else if (GpsStatus.GPS_EVENT_SATELLITE_STATUS == event) {
        if (locationManager != null) {
            final GpsStatus s = locationManager.getGpsStatus(null);
            context.satellitesInUse = 0;
            context.satellitesInView = 0;
            for (final GpsSatellite sat : s.getSatellites()) {
                if (sat.usedInFix()) {
                    context.satellitesInUse += 1;
                }/*from w  w w  . j a v a  2  s  . co m*/
                context.satellitesInView += 1;
            }
            if (BuildConfig.DEBUG) {
                Log.v(TAG, "GPS satellite status: " + context.satellitesInUse + " satellite(s) used in fix");
            }
            fireNmeaRelayContextChanged();
        }
    }
}

From source file:com.android.gpstest.GpsStatusFragment.java

private void updateStatus(GpsStatus status) {

    setStarted(true);//from w w  w. j  ava2s .c o  m
    // update the fix time regularly, since it is displaying relative time
    updateFixTime();

    Iterator<GpsSatellite> satellites = status.getSatellites().iterator();

    if (mPrns == null) {
        int length = status.getMaxSatellites();
        mPrns = new int[length];
        mSnrs = new float[length];
        mSvElevations = new float[length];
        mSvAzimuths = new float[length];
    }

    mSvCount = 0;
    mEphemerisMask = 0;
    mAlmanacMask = 0;
    mUsedInFixMask = 0;
    while (satellites.hasNext()) {
        GpsSatellite satellite = satellites.next();
        int prn = satellite.getPrn();
        int prnBit = (1 << (prn - 1));
        mPrns[mSvCount] = prn;
        mSnrs[mSvCount] = satellite.getSnr();
        mSvElevations[mSvCount] = satellite.getElevation();
        mSvAzimuths[mSvCount] = satellite.getAzimuth();
        if (satellite.hasEphemeris()) {
            mEphemerisMask |= prnBit;
        }
        if (satellite.hasAlmanac()) {
            mAlmanacMask |= prnBit;
        }
        if (satellite.usedInFix()) {
            mUsedInFixMask |= prnBit;
        }
        mSvCount++;
    }

    mAdapter.notifyDataSetChanged();
}

From source file:uk.ac.horizon.ubihelper.service.channel.GpsStatusChannel.java

public void onGpsStatusChanged(int type) {
    if (location != null) {
        GpsStatus status = location.getGpsStatus(null);
        JSONObject value = new JSONObject();
        try {/* ww w.ja  va  2s  .  c  o  m*/
            // event time is in nanoseconds
            value.put("timestamp", System.currentTimeMillis());
            value.put("status", type);
            value.put("maxSatellites", status.getMaxSatellites());
            value.put("timeToFirstFix", status.getTimeToFirstFix());
            JSONArray sats = new JSONArray();
            value.put("satellites", sats);
            for (GpsSatellite satellite : status.getSatellites()) {
                JSONObject s = new JSONObject();
                s.put("used", satellite.usedInFix());
                s.put("azimuth", satellite.getAzimuth());
                s.put("elevation", satellite.getElevation());
                s.put("prn", satellite.getPrn());
                s.put("snr", satellite.getSnr());
                sats.put(s);
            }
            onNewValue(value);

        } catch (JSONException e) {
            /* ignore */
        }
    }
}

From source file:biz.bokhorst.bpt.BPTService.java

@Override
public void onGpsStatusChanged(int event) {
    if (locating)
        if (event == GpsStatus.GPS_EVENT_SATELLITE_STATUS) {
            if (locationManager != null) {
                GpsStatus status = locationManager.getGpsStatus(null);
                if (status != null) {
                    int fix = 0;
                    int count = 0;
                    Iterable<GpsSatellite> sats = status.getSatellites();
                    Iterator<GpsSatellite> satI = sats.iterator();
                    while (satI.hasNext()) {
                        GpsSatellite gpssatellite = satI.next();
                        count++;//  w w w.  ja v a2s  .c  om
                        if (gpssatellite.usedInFix())
                            fix++;
                    }
                    sendSatellites(fix, count);
                }
            }

        } else {
            if (event == GpsStatus.GPS_EVENT_FIRST_FIX)
                sendStatus(getString(R.string.GpsFix));
            else if (event == GpsStatus.GPS_EVENT_STARTED)
                sendStatus(getString(R.string.GpsStarted));
            else if (event == GpsStatus.GPS_EVENT_STOPPED)
                sendStatus(getString(R.string.GpsStopped));
            else
                sendStatus(String.format("Event %d", event));
        }
}