澄清一下,我使用此代码为我的应用程序获取 super 用户权限,以便我可以访问 root 等等:
public String runProcess(String[] functs) {
DataOutputStream dos;
DataInputStream dis;
StringBuffer contents = new StringBuffer("");
String tempInput;
Process process;
try {
process = Runtime.getRuntime().exec(functs);
dos = new DataOutputStream(process.getOutputStream());
dis = new DataInputStream(process.getInputStream());
for (String command : functs) {
dos.writeBytes(command + "\n");
dos.flush();
while ((tempInput = dis.readLine()) != null)
contents.append(tempInput + "\n");
}
dos.writeBytes("exit\n");
dos.flush();
process.waitFor();
} catch (Exception e) {
e.printStackTrace();
}
return contents.toString();
}
虽然它工作得很好,但每当我调用 runProcess(new String[] { "su", "-c", "some other command"});
它总是要求 super 用户权限.我在市场上看到很多 root 应用程序每次启动时只需要获得一次 super 用户权限,但我认为我不需要在每次应用程序调用函数时都向用户询问 super 用户权限这需要苏。所以我的问题是,我如何在应用程序启动时提示用户给我一次 SU 权限,而不必为每个与 SU 相关的操作不断请求?
编辑:我知道我可以运行我的方法/Runtime.getRuntime().exec() 方法而无需每次都在其中键入“su”,但这只适用于非 su 相关操作(即 exec("ps") 或 exec("ls")。有什么想法吗?
最佳答案
您可以使用我的库来执行此操作。
https://code.google.com/p/roottools/
此外,如果您不想使用该库,可以使用源代码,这样您就可以撕掉我的代码并在您的应用程序中使用它。
这是源代码的链接:
关于Android "permanent"应用程序的 super 用户权限?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12430717/