Im automating wifi off/on via adb.
I would either like to disable/enable wifi based on the test case
so far I have found good information here
However I want to test the connection before executing following command
adb shell am start -a android.intent.action.MAIN -n com.android.settings/.wifi.WifiSettings adb shell input keyevent 19 & adb shell input keyevent 19 & adb shell input keyevent 23
Above command disables wifi if enabled, enables wifi if disabled. I want to first test the connection and take action if required. I am wondering if there is a way to do using adb command. This can be achieved programatically but I want it to be done through adb for making it more reliable.
Also following command works only if device is rooted
adb shell "svc wifi enable"
Also following command launches test on screen but provides no info via adb
adb shell am start -n com.android.settings/.wifi.WifiStatusTest
Below command will give you the internet status and connectivity mode(cellular or Wi-Fi)
adb shell dumpsys connectivity
To know everything about Wifi status of the device:
adb shell dumpsys wifi
To just know whether it's enabled or not:
adb shell dumpsys wifi | grep "Wi-Fi is"
To know more detailed status:
adb shell dumpsys wifi | grep "mNetworkInfo"
If you're trying to determine whether or not WiFi is turned on you can run adb shell settings get global wifi_on
which returns 1 if it's on and 0 if it's off.
If you have multiple devices connected you can run adb -s [UDID_HERE] shell settings get global wifi_on
to get the WiFi status of an individual phone. To find the UDID you can run adb devices
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With