Java 在android中自动关闭飞机模式

Java 在android中自动关闭飞机模式,java,android,Java,Android,我需要自动关闭飞行模式。我使用了以下代码。但它不工作 java.io.IOException: Error running exec(). Command: [su, -c, settings put global airplane_mode_on 0] Working Directory: null Environment: null 我的代码 public void modifyAirplanemode(boolean mode) { /* Intent intent = new

我需要自动关闭飞行模式。我使用了以下代码。但它不工作

java.io.IOException: Error running exec(). Command: [su, -c, settings put global airplane_mode_on 0] Working Directory: null Environment: null
我的代码

public void modifyAirplanemode(boolean mode) {

    /* Intent intent = new Intent(Settings.ACTION_AIRPLANE_MODE_SETTINGS);
     intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
     getActivity().startActivity(intent);*/

    String command = COMMAND_FLIGHT_MODE_1+" "+0;
    executeCommandWithoutWait(getActivity(), "-c", command);
    command = COMMAND_FLIGHT_MODE_2 + " " +false;
    executeCommandWithoutWait(getActivity(), "-c", command);

}
private void executeCommandWithoutWait(Context context, String option, String command) {
    boolean success = false;
    String su = "su";
    for (int i=0; i < 3; i++) {
        // "su" command executed successfully.
        if (success) {
            // Stop executing alternative su commands below. 
            break;
        }
        if (i == 1) {
            su = "/system/xbin/su";
        } else if (i == 2) {
            su = "/system/bin/su";
        }       
        try {
            // execute command
            Runtime.getRuntime().exec(new String[]{su, option, command});
        } catch (IOException e) {
            System.out.println(e);
        }   
    }
public void modifyAirplanemode(布尔模式){
/*意向意向=新意向(设置、动作、飞机、模式、设置);
intent.addFlags(intent.FLAG\u活动\u新任务);
getActivity().startActivity(意图)*/
字符串命令=命令飞行模式1+“”+0;
executeCommandWithoutWait(getActivity(),“-c”,命令);
命令=命令飞行模式2+“”+错误;
executeCommandWithoutWait(getActivity(),“-c”,命令);
}
私有void executecommand without wait(上下文上下文、字符串选项、字符串命令){
布尔成功=假;
字符串su=“su”;
对于(int i=0;i<3;i++){
//“su”命令已成功执行。
如果(成功){
//停止执行下面的替代su命令。
打破
}
如果(i==1){
su=“/system/xbin/su”;
}else如果(i==2){
su=“/system/bin/su”;
}       
试一试{
//执行命令
Runtime.getRuntime().exec(新字符串[]{su,option,command});
}捕获(IOE异常){
系统输出打印ln(e);
}   
}

我需要使用上面的android 4.2

您没有使用传递给
modifyAirplanemode
的参数。这是正确的行为吗?自动关闭飞行模式似乎是一个非常非常糟糕的主意。想想看。。。