In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly explains "the method of monitoring network state in Android". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "the method of monitoring network state in Android".
When the state of the network changes, the system will send out an android.net.conn.CONNECTIVITY_CHANGE broadcast
When the phone is unlocked, the system will issue an android.intent.action.USER_PRESENT broadcast. Here, in order to get it when the phone is unlocked, I add the cell phone unlock event broadcast.
After registering for Receiver, you can receive broadcasts of network status changes and mobile phone unlocking actions in ConnctionChangeReceiver.
Secondly, we deal with the received broadcasts by adding network state judgment to onReceive.
ConnectivityManager connectMgr = (ConnectivityManager) context.getSystemService (Context.CONNECTIVITY_SERVICE); NetworkInfo mobNetInfo = connectMgr.getNetworkInfo (ConnectivityManager.TYPE_MOBILE); NetworkInfo wifiNetInfo = connectMgr.getNetworkInfo (ConnectivityManager.TYPE_WIFI)
ConnectivityManager gets the current system service information
GetNetworkInfo acquires the information of two networking methods, MOBILE and WIFI, respectively.
The current networking status is determined by judging the Boolean Boolean values returned by mobNetInfo.isConnected () and wifiNetInfo.isConnected ().
If (! mobNetInfo.isConnected () & &! wifiNetInfo.isConnected ()) {/ / unconnect network} else {/ / connect network}
Only whether it is currently connected to the network is added here. If you need to distinguish between data connection and WIFI connection, you can judge separately.
Note here that Android permission access is added
Thank you for your reading. the above is the content of "the method of monitoring network status in Android". After the study of this article, I believe you have a deeper understanding of the method of monitoring network status in Android, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.