我为 android.net.conn.CONNECTIVITY_CHANGE
创建了一个过滤器.
我确实收到了我的广播接收器的 Intent 。
我的问题是关于引发 connectivity_change
的原因。
API 描述说:
A change in network connectivity has occurred. A connection has either been established or lost. The NetworkInfo for the affected network is sent as an extra; it should be consulted to see what kind of connectivity event occurred.
我的 broadcastreceiver 似乎只在移动网络连接/断开时被调用(pdp 坏了)。它不会在例如 2g 切换到 3g 时引发。
我不能用这个广播接收器捕获 2g 到 3g 的交换吗?
我是否必须使用 phonestatelistener 来捕捉从 2g 到 3g 的交换?
最佳答案
你需要:
permission "android.permission.READ_PHONE_STATE"
//获取连接变化(2G/3G/等)
permission "android.permission.ACCESS_COARSE_LOCATION"
//获取 Cell/Tower 更改
和
//Make the listener
listener = new PhoneStateListener() {
public void onDataConnectionStateChanged(int state, int networkType)
{
//We have changed proticols, for example we have gone from HSDPA to GPRS
//HSDPA is an example of a 3G connection
//GPRS is an example of a 2G connection
}
public void onCellLocationChanged(CellLocation location) {
//We have changed to a different Tower/Cell
}
};
//Add the listener made above into the telephonyManager
telephonyManager.listen(listener,
PhoneStateListener.LISTEN_DATA_CONNECTION_STATE //connection changes 2G/3G/etc
| PhoneStateListener.LISTEN_CELL_LOCATION //or tower/cell changes
);
关于android - 连接管理器 - android.net.conn.CONNECTIVITY_CHANGE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8127324/