为什么我的应用程序在Linux eclipse构建时有效,但在Windows Eclipse上却没有?

时间:2015-03-13 14:45:41

标签: android linux eclipse windows shell

我无法理解为什么完全相同的代码在Linux上由Eclipse构建时运行得很好但在构建应用程序时无法正常运行 Windows Eclipse。两者都使用相同的eclipse版本。

它们都执行Runtime.getRuntime().exec(command);,但只有在Linux版本构建时才有效。

这是我的活动

package com.example.volt;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;


public class MainActivity extends Activity {

    String commandToExecute;

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_main);

        commandToExecute = "/system/xbin/su";
        executeShellCommand(commandToExecute);

        Button bt1 = (Button) findViewById(R.id.button1);
        Button bt2 = (Button) findViewById(R.id.Button01);


        bt1.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub


                commandToExecute = "/system/xbin/su -c /system/bin/service call activity 42 s16 com.android.systemui";
                executeShellCommand(commandToExecute);

            }
        });

        bt2.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {

                commandToExecute = "/system/xbin/su -c /system/bin/am startservice -n com.android.systemui/.SystemUIService";
                executeShellCommand(commandToExecute);

            }
        });



    }

    private boolean executeShellCommand(String command) {
        try {

            Runtime.getRuntime().exec(command);

            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;

        }
    }


}

0 个答案:

没有答案