connectivitymanager - android.net.conn.CONNECTIVITY_CHANGE [英] connectivitymanager - android.net.conn.CONNECTIVITY_CHANGE
问题描述
我已经创建了一个过滤器<一个href=\"http://developer.android.com/reference/android/net/ConnectivityManager.html#CONNECTIVITY_ACTION\"相对=nofollow> android.net.conn.CONNECTIVITY_CHANGE
。结果
我确实收到意向到我的广播接收器。
I have created an filter for android.net.conn.CONNECTIVITY_CHANGE
.
I do receive intents to my broadcastreceiver.
我的问题是关于什么提高了 connectivity_change
。
该API描述说:
My question is regarding what raises the connectivity_change
.
The API description says:
在网络连通性的变化已经发生。一个连接要么
已经建立或丢失。所述的NetworkInfo为受影响的网络是
派作为一个额外的;应该咨询,看看是什么样的
连通性事件发生。
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.
这似乎在移动网络连接/断开(PDP坏了)我的BroadcastReceiver才会被调用。它不会引发时例2G切换到3G网络。
It seems my broadcastreceiver is only called when mobile network is connected/disconnected (pdp is broken). It is not raised when for example 2g switches to 3g.
我能赶不上2G到3G互换这个广播接收器?结果
我必须用一个phonestatelistener而是可以捕捉到例如,2G互换到3G?
Can I not catch 2g to 3g swaps with this broadcastreceiver?
Do I have to use a phonestatelistener instead to catch swaps from e.g, 2g to 3g?
推荐答案
您需要:
许可android.permission.READ_PHONE_STATE
//获取连接的变化(2G / 3G /等)许可android.permission.ACCESS_COARSE_LOCATION
//获取细胞/塔变化
permission "android.permission.READ_PHONE_STATE"
//to get connection changes (2G/3G/etc)
permission "android.permission.ACCESS_COARSE_LOCATION"
//to get Cell/Tower changes
和
//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
);
这篇关于connectivitymanager - android.net.conn.CONNECTIVITY_CHANGE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!