问题描述
我希望我的RTT的应用程序,以便能够在/我们是否正在接收位置更新,无论从GPS或网络控制。我可以很容易地控制GPS状态与GpsStatus.Listener,但我无法找到相当于网络中的更新。例如,该事件将触发,如果我们进入一个地区,没有网络或无线网络,或将出现超时像覆盖GpsStatus.GPS_EVENT_SATELLITE_STATUS的情况下
codeS片段在这里:
mGPSReceiver =(LocationManager)this.getSystemService(Context.LOCATION_SERVICE);
mLocationListener =新LocationListener的(){
私人的位置mLastLocation;
@覆盖
公共无效onLocationChanged(最终位置定位){
// 东东
}
@覆盖
公共无效onProviderDisabled(最后弦乐提供商){
如果(mGPSReceiver.getProviders(真).size()== 0){// WRONG
PhoneStatusService.this.setGPSStatus(假);
}
}
@覆盖
公共无效onProviderEnabled(最后弦乐提供商){
}
@覆盖
公共无效onStatusChanged(最后弦乐供应商,最终诠释状态,最终捆绑演员){
}
};
mGPSListener =新GpsStatus.Listener(){
@覆盖
公共无效onGpsStatusChanged(最终诠释事件){
开关(事件){
案例GpsStatus.GPS_EVENT_STARTED:
打破;
案例GpsStatus.GPS_EVENT_FIRST_FIX:
setGPSStatus(真正的);
打破;
案例GpsStatus.GPS_EVENT_STOPPED:
打破;
案例GpsStatus.GPS_EVENT_SATELLITE_STATUS:
最终布尔isGPSFixing =(SystemClock.elapsedRealtime() - mLastLocationMillis)所述; GPS_TIMEOUT;
setGPSStatus(isGPSFixing);
打破;
默认:
打破;
}
}
};
mGPSReceiver.addGpsStatusListener(mGPSListener);
mGPSReceiver.requestLocationUpdates(LocationManager.GPS_PROVIDER,GPS_FIX_TIME,0,
mLocationListener);
mGPSReceiver.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,GPS_FIX_TIME,0,
mLocationListener);
创建接收网络更新一个BroadcastReceiver。
I want my RTT app to be able to control when/whether we are receiving location updates, no matter from GPS or network. I can easily control GPS status with a GpsStatus.Listener but I cannot find the equivalent for network updates. For example, the event would fire if we enter an area with no network or wifi, or a timeout will occur like in the case covered by GpsStatus.GPS_EVENT_SATELLITE_STATUS
Codes snippets here:
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);
Create a BroadCastReceiver that receives network updates.
这篇关于GpsStatus.Listener不触发对网络状态的变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!