I want to enable/disable an Android phone's GSM connection. I need to disable/enable calls and SMS as required. How might I do this?
EDIT: This solution will also turn off wifi, bluetooth, etc...
If you want to turn off radio only, I think it's related to this issue: http://code.google.com/p/android/issues/detail?id=1065 I am really pessimistic about finding a good solution, but curious to see other answers.
See the blog article Android: Controlling Airplane Mode ,
// 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.
Don't forget you need the WRITE_SETTINGS permission to do this, though.