How can I determine whether Android phones are connected to the Internet ?, Android current
If you want to develop a network application program, first consider whether to connect to the network and determine whether the network can pass through the Android mobile phone.
ConnectivityManager class isAvailable () method judgment,
First, obtain the network communication instance:
Java code
- ConnectivityManager cwjManager = (ConnectivityManager) getSystemService (Context. CONNECTIVITY_SERVICE );
, Use
Java code
- CwjManager. getActiveNetworkInfo (). isAvailable ();
If it is True, it indicates that the current Android phone is connected to the Internet, which may be WiFi, GPRS, HSDPA, etc,
You can use the getActiveNetworkInfo () method of the ConnectivityManager class to determine the detailed access method,
Note that you need to add
Xml Code
- <Uses-permission android: name = "android. permission. ACCESS_NETWORK_STATE"> </uses-permission>
This permission, android Development Network reminds everyone to use this method in both the Market and Browser programs on the real machine to determine whether to continue, when some network times out, you can also check whether the network connection exists to avoid wasting the power resources on the mobile phone.