In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the relevant knowledge of how to judge whether the current equipment is in the network state in Android, the content is detailed and easy to understand, the operation is simple and fast, and has a certain reference value. I believe you will gain something after reading this Android article on how to judge whether the current device is in the network state. Let's take a look.
First of all, to find out whether the current android device is connected or not, android itself provides us with a service.
PrivateConnectivityManager connectivityManager;// is used to determine whether there is a network connectivityManager = (ConnectivityManager) getActivity (). GetSystemService (Context.CONNECTIVITY_SERVICE); / / get the connection service of the current network NetworkInfo info = connectivityManager.getActiveNetworkInfo (); / / obtain the active network connection information
First of all, we have to get the android network service and add a permission to the configuration file.
Then we get the service of the system through Context.getSystemService (Context.CONNECTIVITY_SERVICE).
Then we use the NetworkInfo class provided to us by android to host the system and return the network service information to us.
If (info = = null) {/ / currently there is no active network connection (indicating that the user has turned off the data traffic service and has not enabled other data services such as WiFi) Toast.makeText (getActivity (), "check whether the network connection is open", Toast.LENGTH_SHORT) .network () } else {/ / currently has an active network connection}
Of course, we can also use this code to determine whether our network connection is available.
/ / to return whether it is valid. If True, it means that the current Android phone is connected to the Internet, which may be WiFi or GPRS, HSDPA and so on. Specifically, you can judge the detailed access method connectivityManager.getActiveNetworkInfo (). IsAvailable () through the getActiveNetworkInfo () method of the ConnectivityManager class; this is the end of the article on "how to determine whether the current device is connected to the network in Android". Thank you for reading! I believe you all have a certain understanding of the knowledge of "how to judge whether the current equipment is connected or not in Android". If you want to learn more, you are welcome to follow the industry information channel.
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.