您需要:
permission "android.permission.READ_PHONE_STATE"
//獲取連接的變化(2G/3G /等) permission "android.permission.ACCESS_COARSE_LOCATION"
//得到小區/大廈變化
和
//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
);
檢查這個話題。 http://stackoverflow.com/questions/1783117/network-listener-android –
在該線程的代碼看起來像我做了什麼,但似乎只趕上從移動網絡斷開連接(和多數民衆也什麼看起來像該線程中的人正在尋找),而不是從2g切換到3g – ziggestardust