Android programming to determine whether the network is available and how to invoke system settings _android

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.