Public static Boolean getnetworkinfo (context cont) {try {connectivitymanager manager = (connectivitymanager) cont. getapplicationcontext (). getsystemservice (context. connectivity_service); If (Manager = NULL) {return false;} networkinfo = manager. getactivenetworkinfo (); If (networkinfo = NULL |! Networkinfo. isavailable () |! Networkinfo. isconnectedorconnecting () {return false;} else {// if there is a network connection, determine whether the Internet can be accessed normally. If (Openurl ()) {// normal return true;} else {return false ;}} catch (exception e) {e. printstacktrace (); Return false ;}} public static Boolean Openurl () {string mystring = ""; try {URL url = new URL ("http: // www.baidu.com/index.html "); urlconnection urlcon = URL. openconnection (); urlcon. setconnecttimeout (1500); inputstream Is = urlcon. getinputstream (); bufferedinputstream Bis = new bufferedinputstream (is); // use bytearraybuffer to cache bytearraybuffer BAF = new bytearraybuffer (50); int current = 0; while (current = bis. read ())! =-1) {BAF. append (byte) Current);} mystring = encodingutils. getstring (BAF. tobytearray (), "UTF-8"); bis. close (); is. close ();} catch (exception e) {e. printstacktrace (); Return false;} If (mystring. indexof ("www.baidu.com")>-1) {return true;} else {return false;} public Boolean iswificonnected (context) {If (context! = NULL) {return getnetworkinfo (context);} return false ;}