static boolean getAirplaneMode(Context context) { return Settings.System.getInt(context.getContentResolver(), Settings.System.AIRPLANE_MODE_ON, 0) != 0; } static void setAirplaneMode(Context context, boolean mode) { if (mode != getAirplaneMode(context)) { Settings.System.putInt(context.getContentResolver(), Settings.System.AIRPLANE_MODE_ON, mode ? 1 : 0); Intent newIntent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED); newIntent.putExtra("state", mode); context.sendBroadcast(newIntent); } }
4.2 之后的需要作为system 级别的软件 需要root。