How to turn off Wifi via ADB?

前端 未结 13 2232
北荒
北荒 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 17:54

    Simple way to switch wifi on non-rooted devices is to use simple app:

    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:

    
    

    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
    

提交回复
热议问题