GpsStatus.Listener not firing on network status changes(GpsStatus.Listener 未在网络状态更改时触发)
问题描述
我希望我的 RTT 应用能够控制我们何时/是否接收位置更新,无论是来自 GPS 还是网络.我可以使用 GpsStatus.Listener 轻松控制 GPS 状态,但我找不到网络更新的等价物.例如,如果我们进入一个没有网络或 wifi 的区域,该事件会触发,或者会像 GpsStatus.GPS_EVENT_SATELLITE_STATUS 所涵盖的情况那样发生超时
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
这里的代码片段:
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);
推荐答案
创建一个接收网络更新的 BroadCastReceiver.
Create a BroadCastReceiver that receives network updates.
这篇关于GpsStatus.Listener 未在网络状态更改时触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:GpsStatus.Listener 未在网络状态更改时触发
基础教程推荐
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01