[英]How to make your android app ask for superuser access only once?
I'm creating my first android app which is changing your MAC address and the device hostname. 我正在创建我的第一个android应用程序,它正在更改您的MAC地址和设备主机名。 However, I want to only have to request for superuser access once.
但是,我只需要请求一次超级用户访问。
This is how I'm currently executing my su commands: 这是我当前执行su命令的方式:
String[] cmdHost = { "su", "-c", "/system/bin/setprop net.hostname " + strHostname};
execute = Runtime.getRuntime().exec(cmdHost);
Every time the user presses on the button to change the hostname or the MAC address, it asks for superuser access again. 每次用户按下按钮更改主机名或MAC地址时,它都会再次要求超级用户访问。
Is there any way I can solve this? 有什么办法可以解决这个问题? Also, I see that some apps only execute /system/bin/sh in the SuperUser app logs.
另外,我看到一些应用仅在SuperUser应用日志中执行/ system / bin / sh。 Mine shows the whole command.
我的显示整个命令。
Thank you very much! 非常感谢你!
Check out the library RootTools - it supports operations like the following: 签出RootTools库-它支持如下操作:
if (RootTools.isAccessGiven()) { /* magic root code here */ }
You can send commands to the shell like this 您可以像这样向外壳发送命令
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
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.