无法使用runtime.exec重新启动设备 [英] Can't reboot device using runtime.exec

查看:260
本文介绍了无法使用runtime.exec重新启动设备的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于某种原因,我无法使用Runtime.getRuntime().exec("/system/bin/reboot");重新启动Android设备.我已经在3种设备上尝试了以下代码,但没有运气.其中一个是从rowboat-android来源构建的.其他两个是Motorola Droid Pro(Rooted,股票)和HTC Ledgent(Rooted,Cynogen Mod).所有设备都运行Android 2.2 Froyo.

For some reason I cannot reboot Android devices using Runtime.getRuntime().exec("/system/bin/reboot");. I have tried the following code on 3 devices now without luck. One was built from rowboat-android source. The other two are the Motorola Droid Pro (Rooted, stock) and the HTC Ledgent (Rooted, Cynogen Mod). All devices are running Android 2.2 Froyo.

有人知道为什么吗? su和超级用户应用程序一样可见.我应该注意其他各种Shell命令也可以工作,例如netcfg(chmod'至777)和ls.

Does anyone know why? su works as well as the Super User application is visible. I should note various other shell commands do work, like netcfg (chmod' to 777) and 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;
    }

推荐答案

最后经过几周的搜索:

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

这篇关于无法使用runtime.exec重新启动设备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆