Permissions:
<uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name= "android.permission.ACCESS_NETWORK_STATE"/>
Mainactivity
determine if the network is unblocked plus permissions if (networkutil.isnetavailable (mainactivity). This) {// network unblocked//Start request data }else{toast.maketext (mainactivity.") currently no network Check network permissions 0). Show ();
Networkutil
PublicClass Networkutil {public Boolean isnetavailable (context context) {//< Span style= "color: #008000;" > Get network manager Connectivitymanager connm = (Connectivitymanager) Context.getsystemservice ( Context.connectivity_service); Networkinfo netInfo = Connm.getactivenetworkinfo (); // get network details if (NetInfo = null | |! netinfo.isavailable ()) return falsereturn true
Android to determine whether the network is unblocked and permissions