【发布时间】: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 中输入“reboot”时,它也起作用了。为什么???
reboot 只是工具箱命令之一,我还运行其他可以从 shell 运行的命令。 但是,除了“ls”之外,它们都不能在 rt.exec 中工作。 有人能告诉我如何让它在 android 运行时运行吗? 谢谢
【问题讨论】:
-
在 shell 中也许它可以工作,因为你有一个 root shell。如果您在非 root shell 中执行此操作: $ reboot reboot: Operation not allowed
标签: android