在我的应用程序中,我必须找出 GPS 强度。但是,当我使用下面的代码时,我只得到 0 表示卫星数。所以,我无法获得 GPS 强度。
我的代码:
public void onCreate(Bundle savedInstanceState) {
locMgr = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
locMgr.addGpsStatusListener(onGpsStatusChange) ;
onGpsStatusChange.onGpsStatusChanged(GpsStatus.GPS_EVENT_SATELLITE_STATUS);
// Listener for GPS Status...
}
final Listener onGpsStatusChange=new GpsStatus.Listener()
{
public void onGpsStatusChanged(int event)
{
Log.e("gps","in class");
switch(event)
{
case GpsStatus.GPS_EVENT_SATELLITE_STATUS:
GpsStatus xGpsStatus =locMgr.getGpsStatus(null) ;
Iterable<GpsSatellite> iSatellites =xGpsStatus.getSatellites();
Iterator<GpsSatellite> it = iSatellites.iterator();
int count=0;
while(it.hasNext()){
count=count+1;
GpsSatellite oSat = (GpsSatellite) it.next();
Log.e("gps",""+oSat.getSnr());
}
Log.e("count",""+count);
tv1.setText(""+count);
break;
}
}
};