在android中自动关闭飞机模式

时间:2015-03-23 09:43:26

标签: 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 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);
        }   
    }

我需要使用上面的android 4.2

0 个答案:

没有答案