First, define a method to check the network status in Activity:/*** determine the network connection status ** @ return true, available; false, */private boolean isOpenNetwork () {ConnectivityManager connManager = (ConnectivityManager) getSystemService (Context. CONNECTIVITY_SERVICE); if (connManager. getActiveNetworkInfo ()! = Null) {return connManager. getActiveNetworkInfo (). isAvailable ();} return false;} Then/*** call the method to be performed next when the Network is available. If the network is unavailable, Set */private void initIntener () {// determine whether the Network is available if (isOpenNetwork () = true) {// if the Network is available, load the network. InitPross (); // here is how my personal program loads the network. It can be flexibly used according to your own program .} Else {AlertDialog. Builder builder = new AlertDialog. Builder (MainActivity. this); builder. setTitle ("no available network"). setMessage ("do you want to set the network? "); Builder. setPositiveButton ("yes", new DialogInterface. onClickListener () {@ Overridepublic void onClick (DialogInterface dialog, int which) {Intent intent = null; try {String sdkVersion = android. OS. build. VERSION. SDK; if (Integer. valueOf (sdkVersion)> 10) {intent = new Intent (android. provider. settings. ACTION_WIRELESS_SETTINGS);} else {intent = new Intent (); ComponentName comp = new ComponentName ("com. a Ndroid. settings "," com. android. settings. wirelessSettings "); intent. setComponent (comp); intent. setAction ("android. intent. action. VIEW ");} MainActivity. this. startActivity (intent);} catch (Exception e) {// Log. w (TAG, // "open network settings failed, please check... "); e. printStackTrace ();}}}). setNegativeButton ("no", new DialogInterface. onClickListener () {@ Overridepublic void onClick (DialogInterface dialog, Int which) {dialog. cancel (); // finish (); // because the network is unavailable, the running of your program is not allowed. This is set according to your individual needs. Toast. makeText (MainActivity. this, "network exception, loading failed! ", Toast. LENGTH_SHORT ). show (); initAll (); // if there is no network and you do not need to set it manually, a static page is displayed based on your needs .}}). Show () ;}} then implement the initIntener (); Method in the initialization method of the Activity. To start the Activity, perform network detection first, and then execute other methods. @ Overridepublic void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); requestWindowFeature (Window. FEATURE_NO_TITLE); // remove the title bar setContentView (R. layout. main); // check whether the Network is available initIntener ();} finally, you need to go to AndroidManifest. add related permissions in xml: <uses-permission android: name = "android. permission. ACCESS_NETWORK_STATE "/> <uses-permission android: name =" android. permission. INTERNET "/> if something is wrong, please give me more advice.