How to programmatically enable and disable Flight mode on Android 4.2?

Meroelyth picture Meroelyth · Dec 7, 2012 · Viewed 62.8k times · Source

Is there a way to disable or enable Flight Mode on Android 4.2?

I use this code that works only for previous Android versions:

android.provider.Settings.System.putInt(
    c.getContentResolver(),   
    android.provider.Settings.System.AIRPLANE_MODE_ON, enable ? 0 : 1
);

Answer

DavisNT picture DavisNT · Apr 8, 2013

There exist a simple workaround on rooted devices.

To enable Airplane Mode the following root shell commands can be used:

settings put global airplane_mode_on 1
am broadcast -a android.intent.action.AIRPLANE_MODE --ez state true

To disable Airplane Mode these root shell commands can be used:

settings put global airplane_mode_on 0
am broadcast -a android.intent.action.AIRPLANE_MODE --ez state false

Info taken from here

Disclaimer: This info is provided "as-is" without any form of warranty.