I have written like this. But i am getting 0 always.Please correct me where i am wrong.
public int getSatellites() {
GpsStatus gpsStatus = locationManager.getGpsStatus(null);
int count=0;
if(gpsStatus != null) {
Iterable<GpsSatellite>satellites = gpsStatus.getSatellites();
Iterator<GpsSatellite>sat = satellites.iterator();
int i=0;
while (sat.hasNext()) {
count++;
GpsSatellite satellite = sat.next();
strGpsStats+= (i++) + ": " + satellite.getPrn() + "," + satellite.usedInFix() + ","
+ satellite.getSnr() + "," + satellite.getAzimuth() + "," + satellite.getElevation()+ "\n\n";
Log.v("value:"+"-", strGpsStats+= (i++) + ": " + satellite.getPrn() + "," + satellite.usedInFix() + ","
+ satellite.getSnr() + "," + satellite.getAzimuth() + "," + satellite.getElevation()+ "\n\n");
}
//tv.setText(strGpsStats);
Log.v("satellite", "satellite " +count);
}
return count;
}
ANd in the main activity class i have called it like this
int satellites=gps.getSatellites();
A couple of things that could cause you problems:
ACCESS_COARSE_LOCATION
permission.GpsStatus.Listener
and waiting for the onGpsStatusChanged
event.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With