我犯了错误吗?它不起作用.
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);
}
Run Code Online (Sandbox Code Playgroud) 众所周知,在Android 4.2上,只有系统应用程序可以切换飞行模式.但我认为它必须适用于root设备.我希望在我的Build.VERSION.SDK_INT> = 17的root设备应用程序中实现它.如何在Android 4.2的root设备上切换飞行模式?
我发现了这个问题 ,我尝试如下:
settings put global airplane_mode_on 1
am broadcast -a android.intent.action.AIRPLANE_MODE --ez state true
Run Code Online (Sandbox Code Playgroud)
它在Android 4.4.1上运行得非常好
但在4.0.1中不起作用.(设置:未找到/它支持4.2或更高版本.)
所以,我再次尝试如下:
adb shell am start -a android.settings.AIRPLANE_MODE_SETTINGS
adb shell input keyevent 19
adb shell input keyevent 23
adb shell input keyevent 4
Run Code Online (Sandbox Code Playgroud)
而且,这项工作很奇怪
"AIRPLANE_MODE_SETTINGS"窗口弹出窗口 - >专注于飞行模式(不检查) - >音量调高........
它关闭了屏幕,不起作用
所以我认为这种方式并不好.
问:如何像4.1或更早版本中的'设置全局airplane_mode_on 1'一样工作?