Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to turn off Wifi via ADB?

Im automating a testing procedure for wifi calling and I was wondering is there a way to turn off/on wifi via adb?

I would either like to disable/enable wifi or kill wifi calling (com.movial.wificall) and restart it.

Is it possible to do this all via adb and shell commands?

so far I have found:

android.net.wifi.WifiManager setWifiEnabled(true/false) 

Im just not sure how to put it together

like image 725
Nefariis Avatar asked Apr 05 '12 18:04

Nefariis


People also ask

How do I turn off wifi on my Android?

To turn off Wi-Fi – Hit the “Wi-Fi” icon. To Turn on Wi-Fi: Open Settings on your Android device. Hit “Network & internet.” Tap the toggle switch beside “Wi-Fi” to switch on Wi-Fi.


1 Answers

Using "svc" through ADB (rooted required):

Enable:

adb shell su -c 'svc wifi enable' 

Disable:

adb shell su -c 'svc wifi disable' 

Using Key Events through 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 

The first line launch "wifi.WifiSettings" activity which open the WiFi Settings page. The second line simulate key presses.

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.

More info about "keyevents" here.

like image 75
Jared Burrows Avatar answered Sep 25 '22 06:09

Jared Burrows