How to tell if the device is connected to WiFi

Source: Internet
Author: User

Here, I give a function

1  Public BooleanSale_connect_check (wificonfiguration wcg,context Context) {2         Booleanjudge_2 =false;//Boolean variable of double judgment3         intWcgid = Wifimanager.addnetwork (WCG);//Gets the network ID that was used4         BooleanJudge = Wifimanager.enablenetwork (Wcgid,true);//on the line to operate, note, many online even WiFi demo, and finally it is connected with the5         //here to illustrate, even if the return is true, it will not necessarily be connected, it will only go to the operation of the Wi-Fi6         Try{7LOG.D ("tag", "before sleep here");8Thread.Sleep (4000);//The thread pauses for 4 seconds, because the link WiFi is a process, we have to give the above operation time to do the connection9Connectivitymanager Connectivitymanager =(Connectivitymanager) Context.getsystemservice (context.connectivity_service);TenNetworkinfo Wifinetworkinfo =Connectivitymanager.getnetworkinfo (Connectivitymanager.type_wifi); One             if(Wifinetworkinfo.isconnected ()) {//At this point, here again to determine whether to connect, if 4 seconds enough, set their own ALOG.D ("tag", "is Do Connect"); -judge_2 =true;// -             } the}Catch(Exception e) { -LOG.D ("tag", e.tostring ()); -         } -Save_check_sale_judge = Judge && judge_2;//2 of them are true . +         returnSave_check_sale_judge;//it's connected. -}

How to tell if the device is connected to WiFi

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.