Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set the AIRPLANE_MODE_ON to "True" or ON?

Tags:

android

I am planning to drop a call and I find this as one of workaround for that. How do I activate the airplane mode via code?

This way I will drop the call based on some event.

like image 974
David Prun Avatar asked Dec 06 '22 02:12

David Prun


2 Answers

See the blog article Android: Controlling Airplane Mode ,

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.

like image 130
Jess Avatar answered Dec 18 '22 16:12

Jess


Please keep in mind that this is no longer possible starting from Android 4.2 and above.

http://developer.android.com/reference/android/provider/Settings.Global.html#AIRPLANE_MODE_ON

like image 34
Tommie Avatar answered Dec 18 '22 17:12

Tommie