The example in this article describes how Android programming determines whether a network is available and invokes system setup items. Share to everyone for your reference, specific as follows:
Private Boolean Checknetwork () {Boolean flag = false;
Connectivitymanager manager = (Connectivitymanager) getsystemservice (Context.connectivity_service);
if (manager.getactivenetworkinfo ()!= null) flag = Manager.getactivenetworkinfo (). isavailable (); if (!flag) {Builder b = new Alertdialog.builder (this). Settitle (No network available). Setmessage ("Please turn on GPRS or WiFi network connection")
; B.setpositivebutton (OK), new Dialoginterface.onclicklistener () {public void OnClick (dialoginterface dialog, int
Whichbutton) {Intent mintent = new Intent ("/");
ComponentName comp = new ComponentName ("Com.android.settings", "com.android.settings.WirelessSettings");
Mintent.setcomponent (comp);
Mintent.setaction ("Android.intent.action.VIEW");
StartActivity (mintent); }). Setneutralbutton ("Cancel", new Dialoginterface.onclicklistener () {public void OnClick (Dialoginterface dial
OG, int whichbutton) { Dialog.cancel ();
). Create ();
B.show ();
return flag;
}
Permissions are unavoidable:
<uses-permission android:name= "Android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android: Name= "Android.permission.ACCESS_WIFI_STATE"/>
For more information on Android-related content readers can view the site topics: "Android Debugging techniques and common problems solution summary", "Android Development introduction and Advanced Course", "Android Multimedia operating skills Summary (audio, video, recording, etc.)", " Android Basic Components Usage Summary, Android View tips Summary, Android layout layout tips and Android Control usage summary
I hope this article will help you with the Android program.