Sim*_*mon 2 java permissions android root
我正在创建我的第一个Android应用程序,它正在更改您的MAC地址和设备主机名.但是,我只想要一次请求超级用户访问权限.
这就是我当前正在执行su命令的方式:
String[] cmdHost = { "su", "-c", "/system/bin/setprop net.hostname " + strHostname};
execute = Runtime.getRuntime().exec(cmdHost);
Run Code Online (Sandbox Code Playgroud)
每次用户按下按钮更改主机名或MAC地址时,都会再次请求超级用户访问.
有什么办法可以解决这个问题吗?另外,我看到一些应用程序只在SuperUser应用程序日志中执行/ system/bin/sh.我显示了整个命令.
非常感谢你!
查看库RootTools - 它支持以下操作:
if (RootTools.isAccessGiven()) { /* magic root code here */ }
Run Code Online (Sandbox Code Playgroud)
您可以像这样向shell发送命令
try {
List<String> output = RootTools.sendShell(command);
String[] commands = new String[] { command1, command2 };
List<String> otherOutput = RootTools.sendShell(commands);
} catch (IOException e) {
// something went wrong, deal with it here
}
Run Code Online (Sandbox Code Playgroud)