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
}