set Airplane Mode - Android android.provider

Android examples for android.provider:Settings

Description

set Airplane Mode

Demo Code

import android.content.Context;
import android.content.Intent;
import android.provider.Settings;

public class Main {

  public static boolean setAirplaneMode(Context context, boolean enable) {
    boolean result = true;
    if (isAirplaneModeOpen(context) != enable) {
      result = Settings.System.putInt(context.getContentResolver(), Settings.System.AIRPLANE_MODE_ON, enable ? 1 : 0);
      context.sendBroadcast(new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED));
    }/*  www .  j  av  a  2  s. co  m*/
    return result;
  }

  public static boolean isAirplaneModeOpen(Context context) {
    return getAirplaneModeState(context) == 1 ? true : false;
  }
  public static int getAirplaneModeState(Context context) {
    return Settings.System.getInt(context.getContentResolver(),
            Settings.System.AIRPLANE_MODE_ON, 0);
}
}

Related Tutorials