If you want to develop a network application program, first consider whether to access the network, in the Android phone to determine whether the Internet can be
The IsAvailable () method of the Connectivitymanager class is judged,
First get an example of a network communication class:
Java code
- Connectivitymanager cwjmanager= (Connectivitymanager) Getsystemservice (Context.connectivity_service);
Use
Java code
- Cwjmanager.getactivenetworkinfo (). isavailable ();
To return is valid, if True indicates that the current Android phone is connected, possibly WiFi or GPRS, HSDPA, etc.
The detailed access method can be judged by the Getactivenetworkinfo () method of the Connectivitymanager class,
Note that the call needs to be added to the
XML code
- <uses-permission android:name="Android.permission.ACCESS_NETWORK_STATE"></ Uses-permission>
This permission, the Android Development network reminds everyone on the real computer market and the browser program used this method to determine whether to continue, while some network time-out can also check the presence of network connections, so as not to waste the power resources on the phone.
How can I tell if my Android phone is currently connected?