【问题标题】:android runtime command problemandroid运行时命令问题
【发布时间】:2011-06-09 08:53:59
【问题描述】:

我正在尝试重新启动我的 android 设备(进行 android 移植)以进行测试。

我的代码:

try {
            Runtime rt = Runtime.getRuntime();
            Process proc = rt.exec("reboot");

            InputStream is = proc.getInputStream();
            InputStreamReader isr = new InputStreamReader(is);
            BufferedReader br = new BufferedReader(isr);
            String line;

            while ((line = br.readLine()) != null) {
                Log.i("runtime","line : " + line);
            }
        } catch (Throwable t) {
            t.printStackTrace();
        }

但设备没有自行重启。

如果我将命令更改为

Runtime rt = Runtime.getRuntime();
Process proc = rt.exec("ls");

运行良好,显示所有目录。

当我在 adb shell 中输入“rebo​​ot”时,它也起作用了。为什么???

reboot 只是工具箱命令之一,我还运行其他可以从 shell 运行的命令。 但是,除了“ls”之外,它们都不能在 rt.exec 中工作。 有人能告诉我如何让它在 android 运行时运行吗? 谢谢

【问题讨论】:

  • 在 shell 中也许它可以工作,因为你有一个 root shell。如果您在非 root shell 中执行此操作: $ reboot reboot: Operation not allowed

标签: android


【解决方案1】:

您不能在非 root 手机上执行此操作:

How to boot android phone programmatically?

【讨论】:

    【解决方案2】:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-02-16
      • 1970-01-01
      • 1970-01-01
      • 2012-10-02
      • 2017-02-23
      • 2022-01-12
      • 2011-06-29
      • 1970-01-01
      相关资源
      最近更新 更多