[android开发篇][ wifi模块] [3] wifiConnectAndCheck

智者不为愚者谋,勇者不为怯者死。这篇文章主要讲述[android开发篇][ wifi模块] [3] wifiConnectAndCheck相关的知识,希望能为你提供帮助。

package com.softwinner.network.wifi; import android.content.Context; import android.net.wifi.ScanResult; import android.net.wifi.WifiConfiguration; import android.net.wifi.WifiManager; import android.support.test.InstrumentationRegistry; import android.support.test.uiautomator.UiDevice; import android.util.Log; import org.junit.Test; import java.util.List; import static org.junit.Assert.assertTrue; /** * @author liuzhipeng * Created by Administrator on 2017/7/24. */public class connectAndCheckByJavaInterface {private UiDevice mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()); private String ssid = "AW2"; private String password = "[email  protected]"; private String mLogTag = "testWifi"; private Context context = InstrumentationRegistry.getContext(); wifiBaseClass testWifi = new wifiBaseClass(context, mDevice, ssid, password, mLogTag); @Test public void addNetWorkAndConnect() throws Exception { Log.i(mLogTag, "start add network"); testWifi.addNetworkAndConnect(wifiBaseClass.Security.PSK); for(int i = 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开发篇][ wifi模块] [3] wifiConnectAndCheck】 

    推荐阅读