gpt4 book ai didi

android - 如何在uiautomator中检查wifi是否已连接?

转载 作者:行者123 更新时间:2023-11-29 01:28:05 26 4
gpt4 key购买 nike

在我的 uiautomator 测试中,我想做类似的事情

if( wifi is connected) {
doSth();
} else {
doSthElse();
}

我可以检查一下吗?

最佳答案

从版本 21 (?) 开始,UiAutomator 可以访问 Instrumentation,从而访问 Context。

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

关于android - 如何在uiautomator中检查wifi是否已连接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32751463/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com