Android: Get notification for “Mobile data” network type changes

蓝咒 提交于 2020-01-24 00:18:14

问题


Working on a Android network utility Know Your Android Network

I know that we can easily handle the changes in network state by creating our own Broadcast Receiver and check whether n/w switched from WiFi to Mobile data,

But is there a way to get notification when "Mobile Data" switches from one network type to the other. Basically I need to know when "mobile data" connection jumps from one network type to the other, Below can be the various network types:

NETWORK_TYPE_1xRTT
NETWORK_TYPE_CDMA
NETWORK_TYPE_EDGE
NETWORK_TYPE_EVDO_0
NETWORK_TYPE_EVDO_A
NETWORK_TYPE_GPRS
NETWORK_TYPE_HSDPA
NETWORK_TYPE_HSPA
NETWORK_TYPE_HSUPA
NETWORK_TYPE_UMTS
NETWORK_TYPE_EHRPD
NETWORK_TYPE_EVDO_B
NETWORK_TYPE_HSPAP
NETWORK_TYPE_IDEN
NETWORK_TYPE_LTE

For example, can i get a notification if a mobile data switches from EDGE to LTE.

Thanks!


回答1:


Here are the Broadcast Intent Actions you can put in your IntentFilter:

android.net.conn.BACKGROUND_DATA_SETTING_CHANGED

android.net.conn.CONNECTIVITY_CHANGE

android.net.nsd.STATE_CHANGED

android.net.wifi.NETWORK_IDS_CHANGED

android.net.wifi.RSSI_CHANGED

android.net.wifi.SCAN_RESULTS

android.net.wifi.STATE_CHANGE

android.net.wifi.WIFI_STATE_CHANGED

android.net.wifi.p2p.CONNECTION_STATE_CHANGE

android.net.wifi.p2p.DISCOVERY_STATE_CHANGE

android.net.wifi.p2p.PEERS_CHANGED

android.net.wifi.p2p.STATE_CHANGED

android.net.wifi.p2p.THIS_DEVICE_CHANGED

android.net.wifi.supplicant.CONNECTION_CHANGE

android.net.wifi.supplicant.STATE_CHANGE

You can use these to trigger your BroadcastReceiver and from there you can get a reference to the TelephonyManager and check the network type using getNetworkType().



来源:https://stackoverflow.com/questions/24191753/android-get-notification-for-mobile-data-network-type-changes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!