package utils; //https://www.huaweicloud.com/articles/39c8580fd6d8eacb6b0b89082f9d15b4.html // public class AdbUtils { private static Runtime runtime; static { runtime = Runtime.getRuntime(); } /** * 两台手机点击一下 */ public stati
//https://www.huaweicloud.com/articles/39c8580fd6d8eacb6b0b89082f9d15b4.html
//
public class AdbUtils {
private static Runtime runtime;
static {
runtime = Runtime.getRuntime();
}
/**
* 两台手机点击一下
*/
public static void testTapForTwoAndroid() {
try {
runtime.exec("adb -s 13b6e4c4 shell input tap 400 400 ");
runtime.exec("adb -s 296ec3e2 shell input tap 400 400 ");
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 控制手机点击一下
*/
public static void click(String x, String y) {
try {
runtime.exec("adb shell input tap " + x + " " + y);
Thread.sleep(1000);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* //adb shell input swipe 100 100 100 100 1000 在 100 100 位置长按 1000毫秒 控制手机点击一下
*/
public static void longClick(String x, String y) {
try {
runtime.exec("adb shell input swipe " + x + " " + y + " " + x + " " + y);
Thread.sleep(1000);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 控制手机滑动
*/
public static void swipe(String satrtX, String satrtY, String endX, String endY) {
try {
runtime
.exec("adb shell input swipe " + satrtX + " " + satrtY + " " + endX + " " + endY);
Thread.sleep(1000);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 控制手机输入0-9
*/
public static void testInputStr() {
try {
runtime.exec("adb shell input keyevent 7");
Thread.sleep(1000);
runtime.exec("adb shell input keyevent 8");
Thread.sleep(1000);
runtime.exec("adb shell input keyevent 9");
Thread.sleep(1000);
runtime.exec("adb shell input keyevent 10");
Thread.sleep(1000);
runtime.exec("adb shell input keyevent 11");
Thread.sleep(1000);
runtime.exec("adb shell input keyevent 12");
Thread.sleep(1000);
runtime.exec("adb shell input keyevent 13");
Thread.sleep(1000);
runtime.exec("adb shell input keyevent 14");
Thread.sleep(1000);
runtime.exec("adb shell input keyevent 15");
Thread.sleep(1000);
runtime.exec("adb shell input keyevent 16");
} catch (Exception e) {
e.printStackTrace();
}
}
}