【发布时间】:2014-11-09 20:10:14
【问题描述】:
我正在开发一个在不同时间执行多个 shell 命令的应用程序。 我正在使用以下方法:
public void RunAsRoot(String[] cmds){
Process p = Runtime.getRuntime().exec("su");
DataOutputStream os = new DataOutputStream(p.getOutputStream());
for (String tmpCmd : cmds) {
os.writeBytes(tmpCmd+"\n");
}
os.writeBytes("exit\n");
os.flush();
}
此方法工作正常,但每次我需要调用它时它总是打开一个新外壳,因此它显示烦人的吐司“应用程序已被授予 root 权限”。 我认为这是因为它总是打开和关闭具有 SU 访问权限的新外壳。我的问题是:有没有办法让 SU shell 始终打开,以便我可以在需要时运行我的命令而不会收到 SU toast?
【问题讨论】:
-
我实际上使用的是来自chainfire的libsuperuser,但是Shell.SU.run总是打开一个新的shell!