[Android Development Article] [WiFi Module] [3] Wificonnectandcheck

Source: Internet
Author: User

 PackageCom.softwinner.network.wifi;ImportAndroid.content.Context;ImportAndroid.net.wifi.ScanResult;Importandroid.net.wifi.WifiConfiguration;ImportAndroid.net.wifi.WifiManager;ImportAndroid.support.test.InstrumentationRegistry;ImportAndroid.support.test.uiautomator.UiDevice;ImportAndroid.util.Log;Importorg.junit.Test;Importjava.util.List;Import Staticorg.junit.Assert.assertTrue;/** * @authorLiuzhipeng * Created by Administrator on 2017/7/24.*/ Public classConnectandcheckbyjavainterface {PrivateUidevice Mdevice =uidevice.getinstance (Instrumentationregistry.getinstrumentation ()); PrivateString SSID = "AW2"; PrivateString password = "[Email protected]"; PrivateString Mlogtag = "Testwifi"; PrivateContext context =Instrumentationregistry.getcontext (); Wifibaseclass Testwifi=NewWifibaseclass (context, Mdevice, SSID, password, mlogtag); @Test Public voidAddnetworkandconnect ()throwsException {log.i (Mlogtag,"Start Add Network");        Testwifi.addnetworkandconnect (WifiBaseClass.Security.PSK);  for(inti = 1; I < 11; i++) {Thread.Sleep (6000); LOG.I (Mlogtag, String.Format ("Wait for WiFi connected, run time%d second", 6 *i)); if(wifibaseclass.iswificonnected ()) {log.i (Mlogtag,"WiFi isconnected =" +wifibaseclass.iswificonnected ());  Break; }            if(i = = 10) {log.i (Mlogtag,"WiFi Connected fail"); Asserttrue (false); }} String Wifiname=Testwifi.getnetworkname (); LOG.I (Mlogtag,"Wifiname =" +wifiname); Asserttrue ("WiFi Name Not equal" +SSID, Wifiname.equals (SSID)); String cmd= "Ping-c 4-w 5 www.baidu.com"; Boolean isnetworkavailable=testwifi.isnetworkavailablebydevice (CMD); Asserttrue ("Network is unavailable", isnetworkavailable); LOG.I (Mlogtag,"Isnetworkavailable =" +isnetworkavailable); }}

[Android Development Article] [WiFi Module] [3] Wificonnectandcheck

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.