名称: android-automation
描述: 通过 ADB 控制 Android 设备,支持 UI 布局分析(uiautomator)和视觉反馈(screencap)。适用于需要与 Android 应用交互、执行 UI 自动化、截图或运行复杂 ADB 命令序列的场景。
使用 ADB、uiautomator 和 screencap 控制和自动化 Android 设备。
adb devices 验证连接。adb pair <ip>:<配对端口> <配对码>adb connect <ip>:<连接端口>adb devices 验证连接。使用 monkey 工具通过包名启动应用:
adb shell monkey -p <包名> -c android.intent.category.LAUNCHER 1
导出并拉取 UI 层级以查找坐标:
adb shell uiautomator dump /sdcard/view.xml && adb pull /sdcard/view.xml ./view.xml
然后使用 grep 搜索文本或资源 ID 以找到 bounds="[x1,y1][x2,y2]"。
adb shell input tap <x> <y>adb shell input text "<文本>"(注意:在某些环境中,空格需使用 %\s 或小心处理引号)adb shell input keyevent <键码>(主页:3,返回:4,电源:26,搜索:84,回车:66)adb shell input swipe <x1> <y1> <x2> <y2> <持续时间_毫秒>截图以验证状态:
adb shell screencap -p /sdcard/screen.png && adb pull /sdcard/screen.png ./screen.png
input keyevent 84 可在许多应用中触发搜索功能。sleep <秒数> 以允许 UI 更新。[x1,y1][x2,y2] 的中心点可确保点击更可靠。