工具类:
public static void adb(Context context, String adb) {
if (adb.contains("adb shell")) {
adb = adb.replace("adb shell", "");
}
try {
Process process = Runtime.getRuntime().exec("su");
DataOutputStream os = new DataOutputStream(process.getOutputStream());
os.write(adb.getBytes());
os.writeBytes("\n");
os.flush();
os.writeBytes("exit\n");
os.flush();
os.close();
} catch (IOException e) {
Toast.makeText(context, "未获取到root权限", Toast.LENGTH_SHORT).show();
e.printStackTrace();
}
无需开头adb shell 仅需要后面的命令 常用命令如:
- 点击:input tap x y
- 滑动:input swipe x1 y1 x2 y2
- 模拟按键:input keyevent x
- 截屏:/system/bin/screencap -p filepath
- 。。。