network-state

Broadcast Receiver to detect change in mobile network

半腔热情 提交于 2019-12-13 02:03:51
问题 I am looking for a way to make my Android app do something every time there is a change in mobile network , i.e. going from 2g to 3g, 4g to wifi etc. All I can find for broadcast receivers are the ones that execute on loss or gain of network connection. 回答1: Have you looked into using a PhoneStateListener? The LISTEN_DATA_CONNECTION_STATE and LISTEN_SERVICE_STATE flags look promising. 来源: https://stackoverflow.com/questions/5518719/broadcast-receiver-to-detect-change-in-mobile-network

How do you check the internet connection in android? [duplicate]

狂风中的少年 提交于 2019-11-26 14:57:45
This question already has an answer here: How to check internet access on Android? InetAddress never times out 51 answers I want to check the internet connectivity in each activity. If it is lost a message should be displayed. Can any one guide me how to achieve this? Dan You can use the ConnectivityManager to check the network state. ConnectivityManager conMgr = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE); if ( conMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState() == NetworkInfo.State.CONNECTED || conMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI)

How do you check the internet connection in android? [duplicate]

こ雲淡風輕ζ 提交于 2019-11-26 04:06:42
问题 This question already has answers here : How to check internet access on Android? InetAddress never times out (51 answers) Closed 3 years ago . I want to check the internet connectivity in each activity. If it is lost a message should be displayed. Can any one guide me how to achieve this? 回答1: You can use the ConnectivityManager to check the network state. ConnectivityManager conMgr = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE); if ( conMgr.getNetworkInfo