智者不为愚者谋,勇者不为怯者死。这篇文章主要讲述[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】
推荐阅读
- mac上使用jmeter录制web项目和手机app
- Android-DrawerLayout介绍
- [android开发篇][ wifi模块] [2] wifibase
- AndroidStudio 使用AIDL
- 关于idea中新建web项目webapp文件夹没有小蓝点 ,启动服务,访问不到解决方案
- Android群英传笔记——摘要,概述,新的出发点,温故而知新,能够为师矣!
- Android的简易圆形头像
- Android安装过程出现问题
- BwApp学习记录