Longarm REST API
longarm 的 HTTP 服务器通过 /api/... 提供 REST 接口。
基础 URL
HTTP 服务器启动后,应用会显示当前可用的服务器地址。
http://192.168.1.23:8080
认证
如果启用了 Require token,请求需要包含:
Authorization: Bearer <token>
Token 缺失或无效时,longarm 会返回:
{ "error": "Missing or invalid bearer token" }
通用行为
POST和PUT请求体必须是 JSON。- 请求体最大为
64 KiB。 - 截图响应使用
image/png。 - 批处理导出响应使用
application/zip。 - CORS 已启用。
状态和屏幕信息
GET /api/statusGET /api/screen/info
屏幕信息示例:
{ "width": 1080, "height": 2400, "density": 3.0 }
手势
POST /api/gesture/tap
{ "x": 540, "y": 1200, "duration": 50 }
POST /api/gesture/long_press
{ "x": 540, "y": 1200, "duration": 1000 }
Plus 手势:
POST /api/gesture/swipePOST /api/gesture/pinchPOST /api/gesture/two_finger_swipePOST /api/gesture/rotate
启用 UI 检查时,部分手势可以使用 target 代替直接坐标。
截图
GET /api/screenshot
返回 PNG 数据。
curl -H "Authorization: Bearer <token>" \
http://<host>:<port>/api/screenshot > screenshot.png
还支持 gridSize、gridColor、gridWidth、coordinates 和 scale 等网格选项。
应用与 Intent
POST /api/app/open
{ "packageName": "com.android.settings" }
POST /api/intent/open
{
"action": "android.intent.action.VIEW",
"data": "https://example.com"
}
UI 检查
以下接口需要 bearer token 认证和 Allow UI inspection:
GET /api/ui/treeGET /api/ui/windowsPOST /api/ui/findPOST /api/ui/waitPOST /api/ui/actionPOST /api/ui/set_textPOST /api/ui/scroll
批处理接口
批处理任务使用 /api/batch 下的接口,包括创建、更新、运行、状态、历史记录、导出和截图下载。
任务 JSON 和运行行为见 批处理任务。