How to disable Wi-Fi via ADB?

I am automating a test procedure for a wifi call, and I was wondering if there is a way to disable / enable wifi via adb?

I would like to disable / enable Wi-Fi or kill Wi-Fi (com.movial.wificall) and restart it.

Is it possible to do this with adb and shell commands?

so far I have found:

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

I just don't know how to do this.

+43
android shell adb android wifi
Apr 05 '12 at 18:11
source share
8 answers

Using "svc" via ADB (root required):

Include:

 adb shell su -c 'svc wifi enable' 

Disable:

 adb shell su -c 'svc wifi disable' 

Using key events via 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 starts the action "wifi.WifiSettings", which opens the WiFi settings page. The second line simulates keystrokes.

I tested these two lines on Droid X. But the key events above probably need to be edited on other devices due to the different settings layout.

More on "keyevents" here .

+79
Apr 6 2018-12-12T00:
source share
β€” -

I was looking for the same thing to turn on / off bluetooth and I found this:

 adb shell svc wifi enable|disable 
+37
Jul 13 2018-12-14T00:
source share

An easy way to switch Wi-Fi to unloaded devices is to use a simple application:

 public class MainActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); WifiManager wfm = (WifiManager) getSystemService(Context.WIFI_SERVICE); try { wfm.setWifiEnabled(Boolean.parseBoolean(getIntent().getStringExtra("wifi"))); } catch (Exception e) { } System.exit(0); } } 

AndroidManifest.xml:

 <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" /> 

ADB Commands:

 $ adb shell am start -n org.mytools.config/.MainActivity -e wifi true $ adb shell am start -n org.mytools.config/.MainActivity -e wifi false 
+22
Sep 14 '12 at 8:18
source share
  • go to android/android-sdk/platform-tools location
  • shift + right click
  • open cmd and enter the following commands

    • adb shell
    • su
    • svc wifi enable/disable
  • done !!!!!

+4
Oct 29 '15 at 8:38
source share
 adb shell "svc wifi enable" 

This worked and it runs in the background without opening the corresponding option.

+2
May 09 '13 at 5:29
source share

I tested this command: adb shell am start -a android.intent.action.MAIN -n com.android.settings / .wifi.WifiSettings adb shell input key 19 and adb shell input key 19 and input input- adb 23 output

and only works in the invitation window, possibly due to some kind of driver

about adb shell svc wifi enable | disable I assume that only works as root

+1
Jun 08 '15 at 14:26
source share

use with quotation marks

ex: adb shell "svc wifi enable"

it will work :)

0
Jan 24 '13 at 14:02
source share

I can just do:

 settings put global wifi_on 0 settings put global wifi_scan_always_enabled 0 

Sometimes, if this is done at boot time (for example, to fix a bootloop such as this one ), this is not very good, and you can continue to turn on airplane mode first:

 settings put global airplane_mode_on 1 settings put global wifi_on 0 settings put global wifi_scan_always_enabled 0 

Another option is to force execution with:

 while true; do settings put global wifi_on 0; done 

Tested in Android 7 on LG G5 (SE) with a motive (non-root).

0
Nov 21 '17 at 18:49
source share



All Articles