我写的是这样的。但我总是0。请纠正我错在哪里。
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我称之为
int satellites=gps.getSatellites();
答案 0 :(得分:1)
可能会导致问题的一些事情:
ACCESS_COARSE_LOCATION
权限。GpsStatus.Listener
并等待onGpsStatusChanged
事件。