如何通过 ADB 关闭 Wifi? [英] How to turn off Wifi via ADB?
问题描述
我正在自动执行 wifi 调用的测试程序,我想知道有没有办法通过 adb 关闭/打开 wifi?
Im automating a testing procedure for wifi calling and I was wondering is there a way to turn off/on wifi via adb?
我想禁用/启用 wifi 或终止 wifi 呼叫 (com.movial.wificall) 并重新启动它.
I would either like to disable/enable wifi or kill wifi calling (com.movial.wificall) and restart it.
是否可以通过 adb 和 shell 命令来完成这一切?
Is it possible to do this all via adb and shell commands?
到目前为止我发现:
android.net.wifi.WifiManager
setWifiEnabled(true/false)
我只是不知道如何把它放在一起
Im just not sure how to put it together
推荐答案
通过 ADB 使用svc"(需要 root):
启用:
adb shell su -c 'svc wifi enable'
禁用:
adb shell su -c 'svc wifi disable'
通过 ADB 使用关键事件:
adb shell am start -a android.intent.action.MAIN -n com.android.settings/.wifi.WifiSettings
adb shell input keyevent 20 & adb shell input keyevent 23
第一行启动wifi.WifiSettings"活动,打开WiFi设置页面.第二行模拟按键操作.
The first line launch "wifi.WifiSettings" activity which open the WiFi Settings page. The second line simulate key presses.
我在 Droid X 上测试了这两行.但由于不同的设置布局,上面的关键事件可能需要在其他设备中进行编辑.
I tested those two lines on a Droid X. But Key Events above probably need to edit in other devices because of different Settings layout.
有关keyevents"的更多信息此处.
More info about "keyevents" here.
这篇关于如何通过 ADB 关闭 Wifi?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!