Search code examples
androidaudioapplication-settingsappsettingsandroid-audiomanager

How to put a phone in Airplane mode programmatically in Android?


Can any one tell me how to put a phone in Airplane mode programmatically with a single click on button in android?


Solution

  • See the blog article http://dustinbreese.blogspot.in/2009/04/andoid-controlling-airplane-mode.html ,

    Works only upto API 16

    // Toggle airplane mode.
    Settings.System.putInt(
          context.getContentResolver(),
          Settings.System.AIRPLANE_MODE_ON, isEnabled ? 0 : 1);
    
    // Post an intent to reload.
    Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
    intent.putExtra("state", !isEnabled);
    sendBroadcast(intent);
    

    where isEnabled is whether airplane mode is enabled or not.