How to disable GSM connection in Android programmatically

Ram picture Ram · Sep 9, 2011 · Viewed 11.3k times · Source

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?

Answer

Waza_Be picture Waza_Be · Sep 9, 2011

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.