tags:

views:

93

answers:

2

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
I was not able to deploy it. Does this code go in Broadcastreceiver class
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
I am still getting errors like Settings.System cannot be resolved
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