First, to get whether the current Android device is networked, Android itself provides us with a service.
Private Connectivitymanager connectivitymanager;//used to determine whether there is a network
Connectivitymanager = (Connectivitymanager) Getactivity (). Getsystemservice (Context.connectivity_service);//Get connection service for current network
First we have to get to the Android Web service, and we need to add a permission to the configuration file.
<!--get information about whether a user's phone is networked-->
uses-permission android:name= "Android.permission.ACCESS_NETWORK_STATE"/>
Then we get the service of the system through Context.getsystemservice (Context.connectivity_service).
Then we use Android to provide us with this networkinfo class to put the system back to our network service information.
if (info = = null) { //There is currently no active network connection (indicating that the user has turned off the data traffic service and that there are no data services to open WiFi)
toast.maketext (getactivity (), " Check that the network connection is turned on, Toast.length_short. Show ();
else { //There is currently an active network connection
of course, we can also use this code to determine whether our network connection is available. to return valid, if true means that the current Android phone is networked, possibly WiFi or GPRS, HSDPA, and so on. The detailed access method can be judged by the Getactivenetworkinfo () method of the Connectivitymanager class.
Connectivitymanager.getactivenetworkinfo (). isavailable ();
Above on the Android Service to judge the networking status of the data collation, follow-up continue to supplement the relevant information, thank you for your support to this site.