1
我希望我的RTT應用能夠控制我們何時/是否接收位置更新,無論是來自GPS還是網絡。我可以使用GpsStatus.Listener輕鬆控制GPS狀態,但我無法找到網絡更新的等同物。例如,如果我們沒有網絡或WiFi進入一個區域的事件將觸發,或者超時將通過GpsStatus.GPS_EVENT_SATELLITE_STATUS覆蓋的情況下發生像GpsStatus.Listener未觸發網絡狀態更改
代碼網頁摘要這裏:
mGPSReceiver = (LocationManager)this.getSystemService(Context.LOCATION_SERVICE);
mLocationListener = new LocationListener() {
private Location mLastLocation;
@Override
public void onLocationChanged(final Location location) {
// STUFF
}
@Override
public void onProviderDisabled(final String provider) {
if (mGPSReceiver.getProviders(true).size() == 0) { // WRONG
PhoneStatusService.this.setGPSStatus(false);
}
}
@Override
public void onProviderEnabled(final String provider) {
}
@Override
public void onStatusChanged(final String provider, final int status, final Bundle extras) {
}
};
mGPSListener = new GpsStatus.Listener() {
@Override
public void onGpsStatusChanged(final int event) {
switch (event) {
case GpsStatus.GPS_EVENT_STARTED:
break;
case GpsStatus.GPS_EVENT_FIRST_FIX:
setGPSStatus(true);
break;
case GpsStatus.GPS_EVENT_STOPPED:
break;
case GpsStatus.GPS_EVENT_SATELLITE_STATUS:
final boolean isGPSFixing = (SystemClock.elapsedRealtime() - mLastLocationMillis) < GPS_TIMEOUT;
setGPSStatus(isGPSFixing);
break;
default:
break;
}
}
};
mGPSReceiver.addGpsStatusListener(mGPSListener);
mGPSReceiver.requestLocationUpdates(LocationManager.GPS_PROVIDER, GPS_FIX_TIME, 0,
mLocationListener);
mGPSReceiver.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, GPS_FIX_TIME, 0,
mLocationListener);
您可以使用該功能來檢查連通性,但不能檢查GPS狀態/更新本身。 –
不完整但正確,需要我自己的邏輯。 –