使用 Termux 中的 uiautomator2 或 Tasker 自动化 Android 应用,实现点击、滑动、截图、文本提取、价格追踪和定时任务。
让 MiniMax(或其他 MCP Client)通过 MCP 协议直接调用 uiautomator2,像真人一样控制 Android 手机屏幕。
text
MiniMax API (MCP Client)
↓ MCP 调用
uiautomator2-mcp (在 Termux 里跑)
↓ uiautomator2
Android 手机屏幕 ← USB/无线 ADB
核心优势:
tap_sequence(复合步骤序列)bash
pkg install python python-pip
pip install uiautomator2 uiautomator2-mcp pillow requests schedule
python -m uiautomator2 init
bash
# 方式A: 直接运行(stdio 模式,AI 通过 stdin/stdout 调用)
uiautomator2-mcp
# 方式B: SSH 远程调用(从其他机器连接手机)
ssh user@phone-ip 'cd /path/to/project && uiautomator2-mcp'
在 MiniMax MCP 配置里添加:
json
{
"mcpServers": {
"android": {
"command": "ssh",
"args": ["user@phone-ip", "uiautomator2-mcp"]
}
}
}
Tool说明list_devices列出 ADB 可见的所有设备connect连接设备(IP:5555 或自动发现)device_info获取机型/屏幕/系统版本current_app获取当前前台 APP
Tool说明tap点击坐标double_tap双击坐标long_tap长按坐标multi_tap多次点击swipe滑动(两点之间)drag拖拽press_key按键(home/back/enter/power)
Tool说明input_text输入文字set_element_text设置元素文字
Tool说明find_element查找元素(text/resourceID/class/xpath)tap_element查找并点击元素double_tap_element查找并双击元素element_exists检查元素是否存在wait_element等待元素出现
Tool说明tap_sequence一次执行多步操作序列json
// tap_sequence 示例:淘宝搜索 iPhone
{
"action": "tap_sequence",
"steps": [
{"action": "tap_element", "text": "搜索"},
{"action": "wait", "timeout": 2},
{"action": "input_text", "text": "iPhone 16 256GB"},
{"action": "press_key", "key": "enter"},
{"action": "wait", "timeout": 3},
{"action": "screenshot", "save_path": "/sdcard/result.png"}
]
}
Tool说明screenshot截图(可返回 base64 给 AI 分析)dump_hierarchy获取 XML 界面结构get_ui_tree获取 JSON 格式完整 UI 树
Tool说明app_start启动 APPapp_stop停止 APPapp_install安装 APKapp_clear清空 APP 数据app_info获取 APP 信息
Tool说明screen_on亮屏screen_off灭屏unlock解锁open_notification打开通知栏get_clipboard读剪贴板set_clipboard写剪贴板
Tool说明push_file推文件到手机pull_file从手机拉文件shell在手机上执行 shell
Tool说明get_logs读取 logcat 日志clear_logs清空日志
text
用户: "帮我去淘宝搜 iPhone 16 多少钱"
MiniMax MCP 调用:
1. tap_sequence([
{action:"tap_element", text:"搜索"},
{action:"input_text", text:"iPhone 16 256GB"},
{action:"press_key", key:"enter"},
{action:"wait", timeout:3}
])
2. screenshot(inline=true) → AI 视觉读价格
text
用户: "帮我发一条小红书,内容是今天发现超好用的AI工具"
MiniMax MCP 调用:
tap_sequence([
{action:"tap_element", text:"发布"},
{action:"wait", timeout:2},
{action:"tap_element", text:"选择照片"},
{action:"wait", timeout:1},
{action:"tap", x:540, y:960}, // 选第一张
{action:"tap_element", text:"完成"},
{action:"wait", timeout:1},
{action:"input_text", text:"今天发现一个超好用的AI工具!#AI工具"},
{action:"tap_element", text:"发布"},
{action:"wait", timeout:3}
])
text
用户: "帮我对比 iPhone 16 在淘宝、拼多多、京东的价格"
MiniMax 循环调用3次:
for platform in [taobao, pinduoduo, jd]:
1. app_start(package=platform)
2. tap_sequence([搜索 → 输入iPhone16 → 等待结果])
3. screenshot(inline=true) → AI 读价格
汇总 → 生成对比 → 发 Telegram
APP包名搜索比价发帖淘宝com.taobao.taobao✅✅✅拼多多com.xunmeng.pinduoduo✅✅❌小红书com.xingin.xhs✅✅✅抖音com.ss.android.ugc.aweme✅⚠️✅京东com.jingdong.app.mall✅✅❌微信com.tencent.mm✅❌✅
bash
# crontab 定时执行(Termux 里)
0 9,20 * * * python3 price_monitor.py >> ~/logs/price.log 2>&1
python
# price_monitor.py — 用 MCP call 包装
import subprocess, json
def mcp_call(tool, **kwargs):
req = {"jsonrpc":"2.0","method":"tools/call",
"params":{"name":tool,"arguments":kwargs},"id":1}
proc = subprocess.Popen(
["ssh", "phone-ip", "uiautomator2-mcp"],
stdin=subprocess.PIPE, stdout=subprocess.PIPE, text=True
)
out, _ = proc.communicate(input=json.dumps(req)+"\n")
return json.loads(out)
场景支持标准 UI APP✅游戏/Unity APP❌银行加固 APP⚠️滑动验证码⚠️ 需打码平台人脸验证❌
scripts/android_automation.py(独立 Python 版,无需 MCP)