Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disconnect from a wifi network through adb?

I understand we could turn off Wifi through the "adb shell svc wifi disable" command but I don't want to completely turn off Wifi. I want to disconnect from a particular ssid through adb. Is it possible?

Edit: I got a notification saying this question is identified as a dupe of this question: How to turn off Wifi via ADB?. It actually is not. As mentioned clearly in the first paragraph, I don't want to turn off wifi but want to simply disconnect from a particular network. This is like long pressing a network and tapping "Forget network". Essentially I want to simulate a condition of the user moving out of a wifi network without having to turn off wifi.

like image 571
Ganesh Subramanian Avatar asked Dec 15 '16 01:12

Ganesh Subramanian


People also ask

How to execute ADB command over WiFi without USB cable?

Another useful ADB command that could be executed over WiFi without using a USB cable. It is used to install an APK to your Android device directly from the PC. Just make sure to move the APk file inside the platform-tools folder before executing the below code. If the name of the file is game.apk, then the command will be:

How to disable ADB over Wi-Fi on broken Android devices?

Disable ADB over Wi-Fi on broken Android devices. Step 1: Open the application again and click on the green button to disable ADB via WiFi. With all this, he has learned how to enable and disable ADB over Wi-Fi on rooted and unrooted Android devices.

How do I enable ADB on Android with no root?

Enabling ADB over Wifi on Android no root Step 1: Enable USB debugging (Android Settings> Developer options> Check Enable USB debugging). Step 2: Connect your device to the PC via USB. Step 3: Open the command prompt> navigate to the folder that contains ADB and type: Step 4: Now find the IP address of your Android in Settings> Wifi> Advanced.

Why won't my Android device connect to windows over ADB?

If your Android device won't connect to Windows over ADB (ie. you are getting errors in the command line), you can try installing Minimal ADB and Fastboot from xda-developers. This package installs the necessary Android drivers and might help you get rid of any command line error.


2 Answers

If you have root access, you can make it by using wpa_cli.

First, you can use the wpa_cli`s list_networks to get the network id of the network that you want to disconnect

$ adb shell
# wpa_cli
> list_networks
**network id** / ssid / bssid / flags
0   001aLinksys14081-2G any [CURRENT]

and then you just need to run the wpa_cli remove_network {network id}, where the {network id} parameter is the one that you got on the list_networks method.

like image 197
chgsilva Avatar answered Oct 13 '22 01:10

chgsilva


One option is to use cmd wifi. For disconnecting from a Wi-Fi network, you can "forget" it like so:

adb shell cmd wifi list-networks
adb shell cmd wifi forget-network <networkId from list-networks>

You can view the help documentation for cmd wifi with:

adb shell cmd wifi -h
like image 45
Always Learning Avatar answered Oct 13 '22 03:10

Always Learning