测试用的 9.0 android机台,执行的shell命令为模拟滑动操作,手机不用root就可执行。
有些shell命令无法执行,比如打开其他应用的Activity am start -n 包名/类名。
String commend = "input swipe 100 250 200 280";
ProcessBuilder pb = new ProcessBuilder("/system/bin/sh");
pb.directory(new File("/"));
Process proc = null;
try {
proc = pb.start();
PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(proc
.getOutputStream())), true);
out.write(commend);
out.flush();
out.close();
} catch (IOException e) {
e.printStackTrace();
}