Android 设置飞行模式

static void toggle(Context context) {
        Log.i(TAG, "toggle airplane");

        // We need to toggle the mode and also broadcast the fact.
        ContentResolver cr = context.getContentResolver();
        boolean on = Settings.System.getInt(cr, Settings.System.AIRPLANE_MODE_ON, 0) != 0;
        Settings.System.putInt(cr,
                               Settings.System.AIRPLANE_MODE_ON, 
                               on ? 0 : 1);

        // Post the intent.
        Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
        intent.putExtra("state", !on);
        context.sendBroadcast(intent);
    }

你可能感兴趣的:(Android 设置飞行模式)