Android examples for Phone:Airplane Mode
toggle Airplane Mode
import android.content.Context; import android.content.Intent; import android.os.SystemClock; import android.provider.Settings; public class Main { @SuppressWarnings("deprecation") public static void toggleAirplane(Context context, boolean isEnabled, long delay) { int sdkVersion = android.os.Build.VERSION.SDK_INT; if (delay > 0) { SystemClock.sleep(delay);/*from w w w. j ava2 s.com*/ } if (sdkVersion >= 17) { Settings.System.putInt(context.getContentResolver(), Settings.Global.AIRPLANE_MODE_ON, isEnabled ? 1 : 0); } else { Settings.System.putInt(context.getContentResolver(), Settings.System.AIRPLANE_MODE_ON, isEnabled ? 1 : 0); } Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED); intent.putExtra("state", isEnabled); context.sendBroadcast(intent); } }