- Solution one for this problem:
adb shell "svc wifi enable" #打开wifi
adb shell "svc wifi disable" #关闭wifi
Reference document: https://stackoverflow.com/questions/10033757/how-to-turn-off-wifi-via-adb?rq=1
- Solution two for this problem:
Reference document: https://www.jianshu.com/p/4e3f80adaeb1
https://www.jianshu.com/p/685037cc2883
- How to judge whether wifi is connected or closed by adb command
Execute on linux or Mac
adb shell "dumpsys wifi |grep 'Wi-Fi is'"
Execute on Windows:
adb shell "dumpsys wifi |grep 'Wi-Fi is'"
Wi-Fi is disabled or Wi-Fi is enabled
Reference documentation: https://stackoverflow.com/questions/31604610/how-to-test-wifi-connection-via-adb
- The mobile phone does not need to be rooted, and the above commands can take effect. I have tried it on Huawei P20 (os8.1.0, os9.1.0), Xiaomi mix3 (os10), OPPO Reno Z (os10), and they all work.