Search code examples
androidgpssatellite

How to avoid repeat the same satellite information in list?


I create a simple application for shows GPS sensor satellite informations. Informations shows as text and list never stop to updated with same repeat informations. How i keep the unique sattelites infos?Not repeat the same infos.

public void onGpsStatusChanged() {

  GpsStatus gpsStatus = locationManager.getGpsStatus(null);
  if(gpsStatus != null) {
      Iterable<GpsSatellite>satellites = gpsStatus.getSatellites();
      Iterator<GpsSatellite>sat = satellites.iterator();
      int i=0;
      while (sat.hasNext()) {
          GpsSatellite satellite = sat.next();
           strGpsStats+= (i++) + ": " + "Pseudo-random number for the satellite:  "+satellite.getPrn() + "," + "Satellite was used by the GPS calculation: " + satellite.usedInFix() + "," + "Signal to noise ratio for the satellite: "+satellite.getSnr() + "," + "Azimuth of the satellite in degrees: "+satellite.getAzimuth() + "," +"Elevation of the satellite in degrees: "+satellite.getElevation()+ "\n\n";
      }

      Satinfos.setText(strGpsStats);
  }
}

Solution

  • I think your problem is that you're not clearing your strGpsStats between each call to the onGpsStatusChanged; although not sure because your question is not very clear. Try this:

    public void onGpsStatusChanged() {
      strGpsStats = "";
      GpsStatus gpsStatus = locationManager.getGpsStatus(null);
      if(gpsStatus != null) {
          Iterable<GpsSatellite>satellites = gpsStatus.getSatellites();
          Iterator<GpsSatellite>sat = satellites.iterator();
          int i=0;
          while (sat.hasNext()) {
              GpsSatellite satellite = sat.next();
               strGpsStats+= (i++) + ": " + "Pseudo-random number for the satellite:  "+satellite.getPrn() + "," + "Satellite was used by the GPS calculation: " + satellite.usedInFix() + "," + "Signal to noise ratio for the satellite: "+satellite.getSnr() + "," + "Azimuth of the satellite in degrees: "+satellite.getAzimuth() + "," +"Elevation of the satellite in degrees: "+satellite.getElevation()+ "\n\n";
          }
    
          Satinfos.setText(strGpsStats);
      }
    }