PackageCom.liucanwen.baidulocation.util;Importandroid.app.Activity;ImportAndroid.content.Context;ImportAndroid.net.ConnectivityManager;ImportAndroid.net.NetworkInfo;ImportAndroid.widget.Toast; Public classNetworkStatus { Public BooleanNetstatus =false; /** * @paramargs*/ /*Public NetworkStatus (context context) {try {Connectivitymanager Connectmanager = (connectivitymana GER) context. Getsystemservice (Context.connectivity_service); Networkinfo activenetworkinfo = Connectmanager. Getactivenetworkinfo (); if (activenetworkinfo! = null) {if (activenetworkinfo.isavailable () && acti Venetworkinfo.isconnected ()) {netstatus = true; }}} catch (Exception e) {e.printstacktrace (); } }*/ PublicNetworkStatus (Context context) {Connectivitymanager con=(Connectivitymanager) Context.getsystemservice (Activity.connectivity_service); BooleanWifi=Con.getnetworkinfo (Connectivitymanager.type_wifi). isconnectedorconnecting (); Booleaninternet=Con.getnetworkinfo (connectivitymanager.type_mobile). isconnectedorconnecting (); if(Internet) {//Perform related actionsnetstatus=true; Toast.maketext (Context,"The current mobile network is connected!" ", Toast.length_long). Show (); }Else if(WiFi) {netstatus=true; Toast.maketext (Context,"Current WiFi is connected", Toast.length_long). Show (); } Else{toast.maketext (context,"Pro, is the network connected?" ", Toast.length_long). Show (); }}}/** Additional permissions Required <uses-permission * android:name= "Android.permission.ACCESS_NETWORK_STATE"/>*/
Android to determine if the network is connected