- How to turn off Wifi via ADB?
- 13 Answers 13
- Using «svc» through ADB (rooted required):
- Using Key Events through ADB:
- Via cmd command on Android 11 & 12 (no-root-required)
- How To Disable the Wi-Fi on Android
- Disabling the Wi-Fi on Android
- Method #1: Using the Settings App
- Method #2: Using Quick Settings
- Method #3: Disabling the Wi-Fi Network
- Method #4: Turning On Airplane Mode
- Method #5: Using Third-Party Apps
- Turning Off Automatic Wi-Fi Settings
- Disabling Mobile Data
- Summary
- Frequently Asked Questions
- Can I turn off wifi, GPS, etc. on Android phone overnight?
- 8 Answers 8
How to turn off Wifi via ADB?
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 wifi calling (com.movial.wificall) and restart it. Is it possible to do this all via adb and shell commands? so far I have found:
android.net.wifi.WifiManager setWifiEnabled(true/false)
13 Answers 13
Using «svc» through ADB (rooted required):
adb shell su -c 'svc wifi enable'
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.
Thank you very much for the post. Its not quite the same on my phone, but since you posted the input events I figured out it is key events 19 and 23. Thanks Again. : )
to use those keyevents to toggle wifi in Android 5.0 you would probably have to hit different events then in answer. I would say adb shell input keyevent 19 & adb shell input keyevent 19 & adb shell input keyevent 23 (the first one can be 20 as well) — this is working if there is no option selected when you enter the wifi settings screen (if there is, you should skip the first event)
I was searching for the same to turn bluetooth on/off, and I found this:
adb shell svc wifi enable|disable
I’ve tried using this code on 6 different devices ranging from Gingerbread to JellyBean, rooted to non-rooted and I couldn’t get it to work on any of them. What devices are you able to get this to work on?
@Nefarii — for this I needed to request adb shell into the device. then request su permission. then I was able to run these commands properly.
this works on my Samsung S8 non-rooted, the adb shell su -c ‘svc wifi enable’ didn’t (since it wasn’t rooted)
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); > >
$ adb shell am start -n org.mytools.config/.MainActivity -e wifi true $ adb shell am start -n org.mytools.config/.MainActivity -e wifi false
I tweaked this a little bit and changed the activity for a BroadcastReceiver so it can be added to any app and It won’t show any GUI.
Via cmd command on Android 11 & 12 (no-root-required)
adb shell cmd -w wifi set-wifi-enabled enabled
adb shell cmd -w wifi set-wifi-enabled disabled
the command returns the Invalid args for set-wifi-enabled: java.lang.IllegalArgumentException: Expected ‘enabled’ or ‘disabled’ as next arg but got ‘disable’ / [. ] but got ‘enable’ error if running enable / disable instead of enabled / disabled .
- go to location android/android-sdk/platform-tools
- shift +right click
- open cmd here and type the following commands
- adb shell
- su
- svc wifi enable/disable
adb shell am start -a android.intent.action.MAIN -n com.android.settings/.wifi.WifiSettings adb shell input keyevent 19 && adb shell input keyevent 19 && adb shell input keyevent 23
and only works on window’s prompt, maybe because of some driver
The adb shell svc wifi enable|disable solution only works with root permissions.
This was particularly useful: my Genymotion emulators randomly start up with the wifi available but sometimes not selected. I used this: shell ‘am start -a android.intent.action.MAIN -n com.android.settings/.wifi.WifiSettings; input keyevent 20; input keyevent 23’
It will work if you use with quotes:
adb shell "svc wifi enable"
if you try this in a command prompt it will work.. It will not open anything.. the action will be performed in background
settings put global wifi_on 0 settings put global wifi_scan_always_enabled 0
Sometimes, if done during boot (i.e. to fix bootloop such as this), it doesn’t apply well and you can proceed also enabling airplane mode first:
settings put global airplane_mode_on 1 settings put global wifi_on 0 settings put global wifi_scan_always_enabled 0
Other option is to force this with:
while true; do settings put global wifi_on 0; done
Tested in Android 7 on LG G5 (SE) with (unrooted) stock mod.
All these input keyevent combinations are SO android/hardware dependent, it’s a pain.
However, I finally found the combination for my old android 4.1 device :
adb shell am start -a android.intent.action.MAIN -n com.android.settings/.wifi.WifiSettings adb shell "input keyevent KEYCODE_DPAD_LEFT;input keyevent KEYCODE_DPAD_RIGHT;input keyevent KEYCODE_DPAD_CENTER"
The following method doesn’t require root and should work anywhere (according to docs, even on Android Q+, if you keep targetSdkVersion = 28 ).
- Make a blank app.
- Create a ContentProvider :
class ApiProvider : ContentProvider() < private val wifiManager: WifiManager? by lazy(LazyThreadSafetyMode.NONE) < requireContext().getSystemService(WIFI_SERVICE) as WifiManager? >private fun requireContext() = checkNotNull(context) private val matcher = UriMatcher(UriMatcher.NO_MATCH).apply < addURI("wifi", "enable", 0) addURI("wifi", "disable", 1) >override fun query(uri: Uri, projection: Array?, selection: String?, selectionArgs: Array?, sortOrder: String?): Cursor? < when (matcher.match(uri)) < 0 -> < enforceAdb() withClearCallingIdentity < wifiManager?.isWifiEnabled = true >> 1 -> < enforceAdb() withClearCallingIdentity < wifiManager?.isWifiEnabled = false >> > return null > private fun enforceAdb() < val callingUid = Binder.getCallingUid() if (callingUid != 2000 && callingUid != 0) < throw SecurityException("Only shell or root allowed.") >> private inline fun withClearCallingIdentity(block: () -> T): T < val token = Binder.clearCallingIdentity() try < return block() >finally < Binder.restoreCallingIdentity(token) >> override fun onCreate(): Boolean = true override fun insert(uri: Uri, values: ContentValues?): Uri? = null override fun update(uri: Uri, values: ContentValues?, selection: String?, selectionArgs: Array?): Int = 0 override fun delete(uri: Uri, selection: String?, selectionArgs: Array?): Int = 0 override fun getType(uri: Uri): String? = null >
adb shell content query --uri content://wifi/enable adb shell content query --uri content://wifi/disable
Depending on your device you may need additional permissions.
How To Disable the Wi-Fi on Android
Are you trying to restrict your mobile phone usage to prioritize your mental health? The best thing you can do is to disable the internet connection on your Android, which is a straightforward process.
To disable the Wi-Fi on your Android device, launch Settings, open “Connections”, and select “Wi-Fi”. Tap the toggle next to “Wi-Fi” to disable it completely. You can also swipe down from the top of your device’s screen and tap the Wi-Fi icon to disable it.
To help make things easier, we have written a comprehensive guide on how to disable Wi-Fi on your Android in a straightforward manner. We will also discuss disabling your Wi-Fi network and cellular data and turning off automatic Wi-Fi settings.
- Disabling the Wi-Fi on Android
- Method #1: Using the Settings App
- Method #2: Using Quick Settings
- Method #3: Disabling the Wi-Fi Network
- Method #4: Turning On Airplane Mode
- Method #5: Using Third-Party Apps
- Turning Off Automatic Wi-Fi Settings
- Disabling Mobile Data
- Summary
- Frequently Asked Questions
Disabling the Wi-Fi on Android
If you don’t know how to disable the Wi-Fi on your Android, our following 4 step-by-step methods will help you accomplish this task with minimal effort.
Method #1: Using the Settings App
To disable the Wi-Fi on your Android device through the Settings menu, follow these simple steps.
- Open Settings.
- Tap “Connections”.
- Tap the toggle next to “Wi-Fi” to disable internet access on your Android.
These settings might differ based on your Android device’s brand and model.
Method #2: Using Quick Settings
With these steps, you can stop yourself from accessing the internet on your Android phone by disabling the Wi-Fi quickly from the Home screen.
- Swipe down from the top of your Android Home screen to open Quick Settings.
- Tap “Wi-Fi”.
You can simply tap the Wi-Fi icon again to enable it whenever needed.
Method #3: Disabling the Wi-Fi Network
To disconnect your Android phone from the internet to minimize distractions, try disabling your personal Wi-Fi network instead of the feature in the following way.
- Launch Settings.
- Open “Connections”.
- Tap “Wi-Fi” and turn it on with the toggle to show the available networks.
- Tap the gear icon next to your Wi-Fi network to open its settings.
- Tap “Forget”, and you’re done.
Method #4: Turning On Airplane Mode
If you wish to temporarily stop using Wi-Fi on your Android, you can turn on the Airplane mode using these steps.
- Access Settings.
- Tap “Connection”.
- Tap “Airplane mode” or “Flight mode” to disable your Wi-Fi and mobile networks immediately.
Airplane mode is also accessible from the Quick Settings menu by swiping down from the top of the Home screen.
Method #5: Using Third-Party Apps
You can download a third-party app called Netguard – no root firewall to disable Wi-Fi on the apps present on your Android.
- Launch the Play Store.
- Search for Netguard – no root firewall and install the app.
- Launch the app and agree to the privacy policy.
- Tap the toggle at the top-left and tap “OK” to set up a VPN connection using the app.
- Deactivatebattery optimization from your apps.
- Tap the Wi-Fi icon on your desired apps to disable their access to the internet.
You can also disable mobile data similarly by tapping the data icon on the app.
Turning Off Automatic Wi-Fi Settings
If you have difficulty disabling Wi-Fi, you might have previously activated automatic Wi-Fi settings on your Android. Turn it off in the Settings app using the following simple steps.
- Open Settings.
- Tap “Connections”.
- Tap “Wi-Fi”.
- Tap the three dots in the top-left corner and open “Advanced”.
- Tap the toggle on “Turn on Wi-Fi automatically” to stop the Wi-Fi from automatically turning on in your Android.
Disabling Mobile Data
After you’ve disabled the Wi-Fi on your Android, turn off cellular data with these steps to completely disconnect your phone from the internet.
- Launch Settings.
- Open “Connections”.
- Tap “Data usage”.
- Tap the toggle next to “Mobile data” to turn it off.
Summary
In this guide, we have discussed how to disable Wi-Fi on Android. We have also discussed turning off cellular data and automatic Wi-Fi settings on the device to ensure complete disconnection from the internet.
Hopefully, your question has been answered, and you can cut off your Android from the internet and live more at the moment.
Frequently Asked Questions
If your Wi-Fi keeps turning on by itself, you might’ve turned on the Google Wi-Fi wakeup feature, which immediately connects your device to the internet after searching for a strong Wi-Fi signal, even when you’ve turned it off.
Your battery will discharge faster if your mobile data is turned on, as it continually looks for a signal. Things only get worse if there is a weak signal where you are because this search consumes more battery power on your phone.
Thus, it is better to turn celullar data off when not needed.
Can I turn off wifi, GPS, etc. on Android phone overnight?
I don’t need any fancy idle detection. I’d be happy with the ability to do this from, say, 12am to 6am.
What Android apps are good for this sort of thing?
8 Answers 8
If you don’t mind paying for an app, then this is very similar to the sort of thing that Locale for Android does, you can set it to switch stuff on or off, or run apps on your phone when certain conditions like fine/coarse location, etc are met. There are also quite a few Locale plugins (many of them free) available on the market that give it loads of extra functionality.
I believe Tasker is more powerful and cheaper ($6 instead of $11). And Locale cutting off all their beta testers wasn’t very nice. tasker.dinglisch.net
You can definitely use Tasker to do this. It takes a while to get used to their interface, but there is a decent wiki that has step-by-step examples for many scenarios.
I use Tasker to do exactly that, and much (much) more. Whether or not it can switch between 2G and 3G seems to depend on the handset, which you don’t mention. Here is an example from the Tasker Wiki, showing how to set the phone into Airplane mode at night.
Note that the GPS only uses power if something uses it, so turning it off is highly unlikely to make any meaningful difference to your battery life.
Maybe SweetDreams can do the work for you. According to a ruleset it will turn off bluetooth, wifi and select the ringtone configuration of your choice during a determinate time range.
I use Llama to do similar things on a schedule, e.g. put my phone on silent while I’m at work during working hours, turn off Wi-Fi when I leave home, and so on.
You can set events to occur based on where you are among other conditions such as time/date, screen on/off, battery level, etc. Llama learns locations based on the cell towers that are in range rather than your Wi-Fi or GPS location, so it does not eat into your battery at all. Llama does not require root. I find it very easy to use and now that I have it configured the way I want, I don’t ever look at it unless I want to change something.