在Android中切换飞行模式

在Android中切换飞行模式

我犯了错误吗?它不起作用。

public void airplane() {
    boolean isEnabled = Settings.System.getInt(this.getApplicationContext().getContentResolver(), Settings.System.AIRPLANE_MODE_ON, 0) == 1;
    Settings.System.putInt(context.getContentResolver(),Settings.System.AIRPLANE_MODE_ON,isEnabled ? 0 : 1);
    //Settings.System.putInt(this.getApplicationContext().getContentResolver(),Settings.System.AIRPLANE_MODE_ON,isEnabled ? 0 : 1);
    Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);}


HUX布斯
浏览 1359回答 3
3回答

哔哔one

改编自控制飞行模式:// read the airplane mode settingboolean isEnabled = Settings.System.getInt(      getContentResolver(),       Settings.System.AIRPLANE_MODE_ON, 0) == 1;// toggle airplane modeSettings.System.putInt(      getContentResolver(),      Settings.System.AIRPLANE_MODE_ON, isEnabled ? 0 : 1);// Post an intent to reloadIntent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);intent.putExtra("state", !isEnabled);sendBroadcast(intent);

潇湘沐

以下内容可用于root设备。在命令行中,您可以使用以下方法打开/关闭飞行模式:ON:settings put global airplane_mode_on 1am broadcast -a android.intent.action.AIRPLANE_MODE --ez state trueOFF:settings put global airplane_mode_on 0am broadcast -a android.intent.action.AIRPLANE_MODE --ez state false这适用于android 4.4.2+
打开App,查看更多内容
随时随地看视频慕课网APP