I am planning to drop a call and I find this as one of workaround for that. Can someone help me and explain how to activate the airplane mode via code , this way I will drop the call based on some event. Thank you very much.
+2
A:
Searching Google for "android sdk airplane mode" came up with this blog article:
http://dustinbreese.blogspot.com/2009/04/andoid-controlling-airplane-mode.html
// 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.
Andrew Koester
2010-07-14 18:35:42
I was not able to deploy it. Does this code go in Broadcastreceiver class
2010-07-14 21:18:48
It goes wherever you need it to to perform the action. Don't forget you need the WRITE_SETTINGS permission to do this, though.
Andrew Koester
2010-07-15 05:08:28
I am still getting errors like Settings.System cannot be resolved
2010-07-15 21:01:12
A:
This code works fine for Android 2.2 platform, but unfortunately not for earlier platforms. If somebody succeed on 2.1, please respond how?
android.provider.Settings.System.putInt(context.getContentResolver(), android.provider.Settings.System.AIRPLANE_MODE_ON, 1);
Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
intent.putExtra("state", 1);
context.sendBroadcast(new Intent("android.intent.action.AIRPLANE_MODE"));
context.sendBroadcast(intent);
try {
Thread.sleep(500);
}
catch (InterruptedException e) {
}
android.provider.Settings.System.putInt(context.getContentResolver(), android.provider.Settings.System.AIRPLANE_MODE_ON, 0);
intent.putExtra("state", 0);
context.sendBroadcast(new Intent("android.intent.action.AIRPLANE_MODE"));
context.sendBroadcast(intent);
Tony
2010-08-31 11:39:24