Android Studio 执行 su shell 并多次使用它以避免“su”吐司
我目前正在使用此代码发送 su 命令:
private void execShellCmd(String cmd) {
try {
Process process = Runtime.getRuntime().exec("su");
OutputStream outputStream = process.getOutputStream();
DataOutputStream dataOutputStream = new DataOutputStream(outputStream);
dataOutputStream.writeBytes(cmd);
dataOutputStream.flush();
dataOutputStream.close();
outputStream.close();
} catch (Throwable e) {
}
}
在应用程序运行时期间,我需要执行多个命令,但使用我的代码,每次都会弹出 su toast 并阻止视图 3 秒。
如何使用 su 会话执行多个命令?
例如
private void initexecShell()
private void execShellCmd(String cmd)
private void execShellCmd(String cmd)
private void execShellCmd(String cmd)
private void closeexecShell()
非常感谢您的帮助!
编辑:例如我尝试了以下方法,但不起作用:
private void test() {
initexecShell();
execShellCmd("command1");
//do something else
execShellCmd("command2");
//do something
execShellCmd("command3");
closeexecShell();
}
Process process;
private void initexecShell()
{
Process process = Runtime.getRuntime().exec("su");
}
private void execShellCmd(String cmd) {
try {
OutputStream outputStream = process.getOutputStream();
DataOutputStream dataOutputStream = new DataOutputStream(outputStream);
dataOutputStream.writeBytes(cmd);
dataOutputStream.flush();
dataOutputStream.close();
outputStream.close();
} catch (Throwable e) {
}
}
private void closeexecShell()
{
//?? no idea
}
I`m currently using the this code to send su commands:
private void execShellCmd(String cmd) {
try {
Process process = Runtime.getRuntime().exec("su");
OutputStream outputStream = process.getOutputStream();
DataOutputStream dataOutputStream = new DataOutputStream(outputStream);
dataOutputStream.writeBytes(cmd);
dataOutputStream.flush();
dataOutputStream.close();
outputStream.close();
} catch (Throwable e) {
}
}
During App Runtime i need to execute several commands, but with my code the su toast popup every time and is blocking view for 3 seconds.
How can I use the su session for multiple commands?
e.g.
private void initexecShell()
private void execShellCmd(String cmd)
private void execShellCmd(String cmd)
private void execShellCmd(String cmd)
private void closeexecShell()
Thanks a lot for you help!
Edit: for example I tried the following, but does not work:
private void test() {
initexecShell();
execShellCmd("command1");
//do something else
execShellCmd("command2");
//do something
execShellCmd("command3");
closeexecShell();
}
Process process;
private void initexecShell()
{
Process process = Runtime.getRuntime().exec("su");
}
private void execShellCmd(String cmd) {
try {
OutputStream outputStream = process.getOutputStream();
DataOutputStream dataOutputStream = new DataOutputStream(outputStream);
dataOutputStream.writeBytes(cmd);
dataOutputStream.flush();
dataOutputStream.close();
outputStream.close();
} catch (Throwable e) {
}
}
private void closeexecShell()
{
//?? no idea
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)