我尝试了以下方式,但它不适合我:
public void RunAsRoot(String cmnd){
Process p = Runtime.getRuntime().exec("su");
DataOutputStream os = new DataOutputStream(p.getOutputStream());
os.writeBytes(cmnd +"\n");
os.writeBytes("exit\n");
os.flush();
p.waitFor();
}
我也试过这个:
public void RunAsRoot(String cmds){
Process p = Runtime.getRuntime().exec("su -c " + cmds);
p.waitFor();
}
但是上述方法都不起作用。但是,以下命令通过 adb 在 shell 中为我工作:
su -c "input" " keyevent" " 3"
所以我什至试过这个:
public void RunAsRoot(String cmds){
Process p = Runtime.getRuntime().exec("su -c \"input\" \" keyevent\" \" 3\"");
p.waitFor();
}
但即使这样也没有用。谁能帮帮我吗!!!!