2015-09-24 36 views

回答

0

方法-1

转到无线上网的页面 - 勾选 “Conncted” 你的SSID下面的字符串。

方法-2

退房的adb shell netcfg放和grep为WiFi接口有效ip地址,mostly- wlan0

方法-3(但它只是对根植电话)

退房看跌adb shell wpa_cli ifname=wlan0 status,它提供了无线网络连接与否的信息。

以上所有方法都可以使用uiautomator进行编码。

1

由于版本21(?)UiAutomator可以访问Instrumentation,因此可以访问上下文。

Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation(); 
Context context = instrumentation.getContext(); 
WifiManager wManager = context.getSystemService(Context.WIFI_SERVICE); //this works for other services as well 

现在你可以使用所有WifiManager方法,如:

wManager.isWifiEnabled() 
wManager.setWifiEnabled(boolean) //turn wifi on and off