Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Turning airplane mode on via ADB

Tags:

I've looked all over and I haven't found a concrete answer to this question. I'm hoping to find a way to toggle airplane mode from ADB that doesn't involve the GUI in any way. I've found and used the method that calls up the menu and then using keyevents turns airplane mode on, but due to needing to account for possible changes in UI layout, this method is only a temporary solution.

I'm beginning to think there isn't a way to just toggle airplane mode on or off via intent, but if you have any information, I'd greatly appreciate it.

like image 283
Charles Daily Avatar asked May 08 '12 21:05

Charles Daily


People also ask

How do I get adb mode?

Boot your phone into Android, then connect it to your desktop computer with a USB cable. On your computer, launch the Command Prompt and change the directory to point to the platform-tools folder. Type adb devices and hit Enter.

Can airplane mode be turned on automatically?

YES!.. Few years ago even I was in search of such an app which would help me schedule Airplane mode toggle on my smartphone. Then I found this app - MacroDroid - Device Automation - Android Apps on Google Play . You can automate your phone to a whole different level using this app.


2 Answers

First, I would never rely on solutions which are blindly navigating through the UI as suggested in most answers here. More in a note below.

I like the G murali's first answer which suggests the following to enable the airplane mode:

adb shell settings put global airplane_mode_on 1 

Unfortunately, it doesn't work. It just changes the state of the Airplane mode icon, but all radios are still active.

It's missing one very important part, which is broadcasting the intent right after the setting has been changed to inform applications that the Airplane mode state has changed.

To enable the Airplane mode use the following commands:

adb shell settings put global airplane_mode_on 1 adb shell am broadcast -a android.intent.action.AIRPLANE_MODE 

To disable the Airplane mode, you have to chnage the setting to 0 and broadcast the intent again:

adb shell settings put global airplane_mode_on 0 adb shell am broadcast -a android.intent.action.AIRPLANE_MODE 

It's tested and working on Android 6.


Note

Many answers suggest to use an activity to open the Airplane mode settings and then simulate some key presses to navigate through the UI. I don't recommend to rely on that. There may be just a short lag on the device and keys will be pressed before the Settings dialog is opened or for example some unexpected dialog will appear meanwhile. In both cases the key presses will cause something unintended, possibly harmful.

Also the UI may be different on devices of various brands, models, Android versions, etc. I have tested it on Samsung Galaxy S4 (Android 6.0.1) and it didn't work there. It may be by a difference between the Samsung's and the default UI.

The settings manipulation method should be perfectly safe.

like image 172
David Ferenczy Rogožan Avatar answered Mar 19 '23 07:03

David Ferenczy Rogožan


For newer android this en/disables wifi. Not quite your task, but i would've been happy to find it here:

adb shell svc wifi disable 

or

adb shell svc wifi enable 

Credit goes to this answer: https://stackoverflow.com/a/27228962/1021872

like image 22
cdanzmann Avatar answered Mar 19 '23 05:03

cdanzmann