Can any one tell me how to put a phone in Airplane mode programmatically with a single click on button in android?
Asked
Active
Viewed 2,364 times
2
Community
- 1
- 1
Born To Win
- 3,271
- 3
- 17
- 27
-
No Harshit..I want an airplane mode to be On programatically. – Born To Win Nov 13 '13 at 12:22
3 Answers
3
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.
kapil thadani
- 1,405
- 14
- 26
2
try this to put your phone on airplane mode.
// read the airplane mode setting
boolean isEnabled = Settings.System.getInt(
getContentResolver(),
Settings.System.AIRPLANE_MODE_ON, 0) == 1;
// toggle airplane mode
Settings.System.putInt(
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);
Also make sure you have the WRITE_SETTINGS permission
Harshit Rathi
- 2,273
- 2
- 17
- 26
-
Harshit..its not work can you please briefly tell me what will i do in my code..Thanks – Born To Win Nov 13 '13 at 13:03
-
-
Thank you so much Harshit..it works for me i just want to off the mode while clicking on other. – Born To Win Nov 13 '13 at 13:26
-2
this code to make phone silent
AudioManager am = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
am.setRingerMode(AudioManager.RINGER_MODE_SILENT);
there is also vibrate mode and normal mode
am.setRingerMode(AudioManager.RINGER_MODE_VIBRATE);
am.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
steevoo
- 621
- 6
- 18
-
Thanks steevoo..I know these things but i want to on an airplane mode via programatically. – Born To Win Nov 13 '13 at 12:20
-
check this link http://stackoverflow.com/questions/13766909/how-to-programmatically-enable-and-disable-flight-mode-on-android-4-2 – steevoo Nov 13 '13 at 12:23