您好我需要知道如何使用Android中的GPS监听以下内容,以便我可以在PreferenceActivity中更新UI.我没有尝试过Gpsstatus.Listener.
> Gpsstatus.GPS_EVENT_STARTED
> Gpsstatus.GPS_EVENT_StopPED
任何建议都会很棒.
解决方法:
mLocationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); // define a Listener that responds to location updates mGPsstatusListener = new Gpsstatus.Listener() { public voID onGpsstatusChanged(int event) { switch (event) { case Gpsstatus.GPS_EVENT_SATELliTE_STATUS: satelliteStatus = mLocationManager.getGpsstatus(null); Iterable<GpsSatellite> iSatellites = satelliteStatus .getSatellites(); Iterator<GpsSatellite> it = iSatellites.iterator(); maxsatellites = 0; while (it.hasNext()) { GpsSatellite oSat = (GpsSatellite) it.next(); statArray[maxsatellites][0] = oSat.getPrn(); statArray[maxsatellites][1] = oSat.getAzimuth(); statArray[maxsatellites][2] = oSat.getPrn(); statArray[maxsatellites][3] = oSat.getElevation(); statArray[maxsatellites][4] = oSat.getSnr(); if (oSat.usedInFix()) { statArray[maxsatellites][5] = 1; } else { statArray[maxsatellites][5] = 0; } maxsatellites++; } if (mLastLocation != null) if ((SystemClock.elapsedRealtime() - mLastLocationMillis) < 3000) { isGPSFix = 7; // Enumeration for ONC_STAT_3D } else { isGPSFix = 2; // Enumeration for ONC_STAT_BAD_COVER } } if (isGPSFix == 1) { // A fix has been acquired. // Do something. } else { // The fix has been lost. // Do something. } break; case Gpsstatus.GPS_EVENT_FirsT_FIX: // Do something. isGPSFix = 1; break; case Gpsstatus.GPS_EVENT_StopPED: if ((mLastLocation = mLocationManager .getLastKNownLocation(LocationManager.GPS_PROVIDER)) != null) { isGPSFix = 5; // Enumeration for } else { isGPSFix = 2; // Enumeration for } } } }; mGPSLocationListener = new LocationListener() { public voID onLocationChanged(Location location) { // Called when a new location is found by the location // provIDer. if (location == null) return; mLastLocationMillis = SystemClock.elapsedRealtime(); // Do something. mLastLocation = location; } } public voID onProvIDerDisabled(String provIDer) { // Todo auto-generated method stub } public voID onProvIDerEnabled(String provIDer) { // Todo auto-generated method stub } public voID onStatusChanged(String provIDer, int status, Bundle extras) { // Todo auto-generated method stub } }; mLocationManager.addGpsstatusListener(mGPsstatusListener); // Register the Listener with the Location Manager to receive location // updates mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, mUpdateIntervalinMillis, 0, mGPSLocationListener);
总结 以上是内存溢出为你收集整理的Android收听GPS状态的变化?全部内容,希望文章能够帮你解决Android收听GPS状态的变化?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)