【发布时间】:2012-09-26 06:27:08
【问题描述】:
我创建了一个BroadcastReceiver 来监听CONNECTIVITY_CHANGE 事件。现在,我只需打印出调用BroadcastReceiver 的Intent 及其附加功能的操作。我在马尼拉的办公室使用测试电话,SIM 卡来自丹麦。当onReceive() 被调用时,这就是在LogCat 中打印出来的内容:
action: android.net.conn.CONNECTIVITY_CHANGE
key: extraInfo, value: data.tre.dk
key: htcCurrentActiveNetwork, value: null
key: networkInfo, value: null
key: reason, value: roamingOn
key: noConnectivity, value: null
key: inetCondition, value: null
我需要知道漫游结束时reason 的值是多少——通过猜测可能是roamingOff,但我不能确定,除非我去丹麦。这是因为我需要在漫游服务关闭时执行一项任务,并且我从 LogCat 中注意到CONNECTIVITY_CHANGE 事件被触发的原因不是切换漫游模式。或者有没有更好的方法来检测何时关闭漫游?
广播接收器的代码:
public void onReceive(Context context, Intent intent) {
Log.d(This.LOGTAG, "action: " + intent.getAction());
Bundle extras = intent.getExtras();
for (String key : extras.keySet()) {
Log.d(This.LOGTAG, "key: " + key + ", value: " + extras.getString(key));
}
}
清单条目:
<receiver android:name=".listener.RoamingListener">
<intent-filter>
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
</intent-filter>
</receiver>
【问题讨论】:
标签: android broadcastreceiver roaming