Permissions:
<uses-permission android:name="android.permission.INTERNET"/> < Uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
Mainactivity
// Determine whether the network is unblocked and authorized if (networkutil. isnetavailable (mainactivity. this) {// network unblocked //Start request data }else{ Toast.maketext ( Mainactivity. This " there's no net. Check network Permissions " 0 ). Show (); }
Networkutil
Public classNetworkutil { Public StaticBoolean isnetavailable (context context) {//Get network managerConnectivitymanager connm =(Connectivitymanager) Context.getsystemservice (Context.connectivity_service); Networkinfo NetInfo= Connm.getactivenetworkinfo ();//Get Network Details if(NetInfo = =NULL|| !netinfo.isavailable ())return false; return true; }}
Android to determine whether the network is unblocked and permissions