How to turn on/of data/wifi in android device using appium

Hi all, i am testing a scenarios that i will test in case of wifi/ data is off and in case of wifi/data is on.
So now i have to automate the turn on/of data/wifi.
I search a lot on the forum and see the adb command
to turn of data :
adb shell am start -n io.appium.settings/.Settings -e data off
to turn on data :
adb shell am start -n io.appium.settings/.Settings -e data on
But there command does not work, after the command is executed , then the correct message is shown. but the data is not turn off or turn on.
can any one help here.

Java client has this utility function - Check this.

import io.appium.java_client.NetworkConnectionSetting;

NetworkConnectionSetting connection_wifi_off = new NetworkConnectionSetting(false, false, false);
NetworkConnectionSetting connection_wifi_on = new NetworkConnectionSetting(false, true, false);
1 Like

Hi RamS,

Actually, i tried to use NetworkConnectionSetting before. But IDE say that this API is deprecated and will deleted on next release.
So that i think Java does not support this API any more.
So we can still use it ? NetworkConnectionSetting?

1 Like

Hi Telmo_Cardoso,

How about Appium API version>4.0.0? In this case, what solution is applied for network connection?

Because, when we build automation test case, our customer will not know about the appium version …

They just care if the automation test case run successfully or not. And if they use apppium api version >4.0.0. What do you think about this case?

Please read the complete article. He talks how it was (<4.0.0) and how it is now (>=4.0.0)

Hi Telmo_Cardoso,

I see it now. Sorry because at first, it didnot have look on the link you provide.
Thanks so much Telmo_Cardoso.
And it works from my side now. thanks


Currently I am using this method to switch on/off wifi… It is working smoothly in my windows machine, but when I connect my device with Mac, it is not switching off the wifi.

P.S - I have setup the Android Home and path correctly, also I am able to see the device list while performing adb devices in terminal…

I am blocked, and any help would be appreciated here… @willosser


@mashkurm, please see this related discussion: Why Appium server restart ADB server often?

1 Like

Thanks! This solved my issue.

Hi Telmo_Cardoso
I tried adding the same in my project but its not recognizing the “Connection” .
I went through some of the other links, and there was one suggestion to add this Mvvn Repository to my project.
Have done that still its not working.
Can you please help me with Which Jar or Dependency to be added to make it work.

Thanks in advance.

Make sure you are using the last java client

Hey all, sorry if this the wrong thread or if this has been answered somewhere, I couldn’t find the exact use cases I had … But is there a way to use Appium to:

  1. scan all available WiFi, showing all MAC addresses, RSSI values, etc
  2. join a certain WiFi
  3. perform “Forget Network” UI action

I am trying to use logcat to track the appActivity values from manual actions. I’ve tried a few “for ActivityInfo” that proceeded “.Settings$ConnectionsSettingsActivity” in the log, but the script fails when I try to do things after “.Settings$ConnectionsSettingsActivity”.

Here’s how I set the Desired Capabilities:

// Set the Desired Capabilities
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability(“deviceName”, “Galaxy S9”);
caps.setCapability(“udid”, “38454a5631453498”); // Give Device ID of your mobile device
caps.setCapability(“platformName”, “Android”);
caps.setCapability(“platformVersion”, “9.0”);
caps.setCapability(“appPackage”, “”);
caps.setCapability(“appActivity”, “.Settings$ConnectionsSettingsActivity”);
//caps.setCapability(“appActivity”, “.SubSettings”);
//caps.setCapability(“appActivity”, “”);
//caps.setCapability(“appActivity”, “”);
//caps.setCapability(“appActivity”, “”);
caps.setCapability(“noReset”, “true”);

“.Settings$ConnectionsSettingsActivity” will successfully take me to Wi-Fi menu, but I can’t chain anything after that. Is there something I’m fundamentally missing? Like a
“sleep” between my action calls? I’m new to using Appium, bit n00b.

Let me know if I should start a new thread or provide further context, thanks all!