首页 > 代码库 > [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 = "1qaz@WSX"; 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
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。