2

何らかの理由で、Runtime.getRuntime().exec("/system/bin/reboot"); を使用して Android デバイスを再起動できません。現在、3 つのデバイスで次のコードを試してみましたが、うまくいきませんでした。1 つは、rowboat-android ソースからビルドされました。他の 2 つは Motorola Droid Pro (Rooted、ストック) と HTC Ledgent (Rooted、Cynogen Mod) です。すべてのデバイスで Android 2.2 Froyo が実行されています。

誰かが理由を知っていますか?su は機能し、スーパー ユーザー アプリケーションが表示されます。netcfg (chmod' to 777) や ls など、他のさまざまなシェル コマンドが機能することに注意してください。

public static boolean executeCommand(SHELL_CMD iShellCmd){
        String cmd = null;
        String line = null;
        String fullResponse = null;
        Process lPs = null;

        Log.d(Global.TAG,"--> !!!!! Running shell command");

        if (iShellCmd == SHELL_CMD.restart_device){
            cmd = "reboot";
        }

        Log.d(Global.TAG,"--> About to exec: " + cmd);

        try {
            lPs = Runtime.getRuntime().exec("su");
            lPs = Runtime.getRuntime().exec("/system/bin/reboot");
        } catch (Exception e) {
            e.printStackTrace();
        }

        BufferedWriter out = new BufferedWriter(new OutputStreamWriter(lPs.getOutputStream()));
        BufferedReader in = new BufferedReader(new InputStreamReader(lPs.getInputStream()));

        try {
            while ((line = in.readLine()) != null) {
                Log.d(Global.TAG,"--> Command result line: " + line);
                if (fullResponse == null){
                    fullResponse = line;
                }else{
                    fullResponse = fullResponse + "\n" + line;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        Log.d(Global.TAG,"--> Full response was: " + fullResponse);

        return true;
    }
4

5 に答える 5

2

デバイスでルート権限を取得した方法に応じて、次のいずれかを実行できます。

Runtime.getRuntime().exec(new String[]{"/system/xbin/su","-c","reboot"});

また

Runtime.getRuntime().exec(new String[]{"/system/bin/su","-c","reboot"});

また

Runtime.getRuntime().exec(new String[]{"su","-c","reboot"});

アプリケーションで 3 つのシナリオすべてをテストすることをお勧めします。

于 2013-02-05T08:36:23.883 に答える
1

最後に数週間の検索の後:

Runtime.getRuntime().exec(new String[]{"/system/bin/su","-c","reboot now"});
于 2011-04-24T18:53:50.673 に答える
0

ボタンを押したい場合は、次を試してください。

final Button button = (Button) findViewById(R.id.button1);
    button.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            // Perform action on click
             try {
                 Runtime.getRuntime().exec(new String[]{"/system/bin/su","-c","reboot"});              
            } catch (IOException e) {
            }               
        }
    });

ちなみに、このコードが機能するには、ボタンをbutton1と呼ぶ必要があります。

于 2011-05-08T03:05:36.617 に答える
0

代わりに、その部分をちょうどに{"/system/bin/su","-c","reboot"}変更したところ、うまくいきました。"/system/bin/su""su"

このようなRuntime.getRuntime().exec(new String[]{"su","-c","reboot"});

于 2011-11-07T03:57:45.017 に答える
0

su とコマンドを別の行で実行する代わりに、「su /system/bin/reboot」を実行してみてください。それは役立つかもしれません:)

于 2011-04-11T19:58:32.603 に答える