How to turn off Wifi via ADB?

前端 未结 13 2224
北荒
北荒 2020-11-29 17:37

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

13条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-29 18:03

    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.

提交回复
热议问题