0

我想知道我的 GPS 应用程序中的卫星数量。但不知何故,onGpsStatusChanged 函数永远不会被调用。

有任何想法吗?

private class MyGpsStatusListener implements android.location.GpsStatus.Listener
{

    @Override
    public void onGpsStatusChanged(int arg0) {

        String strGpsStats = "";

        GpsStatus gpsStatus = mLocationManager.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++) + ": " + satellite.getPrn() + "," + satellite.usedInFix() + "," + satellite.getSnr() + "," + satellite.getAzimuth() + "," + satellite.getElevation()+ "\n\n";
            }

            Toast.makeText(getBaseContext(), strGpsStats, Toast.LENGTH_LONG).show();
            Log.i(T, "GPS STATUS HAS CHANGED:" + strGpsStats);
        }
    }

}
4

0 回答 0