Question

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);
  }
}
Was it helpful?

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);
  }
}

OTHER TIPS

After Entering into the while, need to check for repeated info.

    while (sat.hasNext()) {
          GpsSatellite satellite = sat.next();
            if(sat.Current != 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";
      }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top