You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何实现Android割草机控制APP的脚本自动化并对接HTTP服务器?

可行方案列表

方案一:Termux + Python + uiautomator2(推荐)

兼顾HTTP请求处理与APP界面控制,适配Android 11环境,灵活性高

  • 步骤1:Termux环境准备
    • 更新包管理器:pkg update && pkg upgrade
    • 安装Python:pkg install python
    • 安装依赖库:pip install requests uiautomator2
  • 步骤2:配置uiautomator2
    • 开启手机USB调试,执行python -m uiautomator2 init安装ATX服务,完成设备连接
  • 步骤3:编写自动化脚本
    • 用requests轮询HTTP服务器接口获取控制指令
    • 收到启动指令时,通过uiautomator2定位APP控件并模拟操作
    • 核心代码示例:
      import requests
      import uiautomator2 as u2
      import time
      
      d = u2.connect()
      APP_PKG = "com.husqvarna.automowerconnect"
      
      def fetch_control_cmd():
          resp = requests.get("http://你的服务器地址/control-endpoint")
          return resp.json().get("action")
      
      while True:
          cmd = fetch_control_cmd()
          if cmd == "start_mow":
              d.app_start(APP_PKG)
              # 需自行通过d.dump_hierarchy()获取割草按钮的资源ID替换下方内容
              d(resourceId="com.husqvarna.automowerconnect:id/start_mowing_btn").click()
          time.sleep(60)
      
  • 注意:使用d.dump_hierarchy()导出APP控件结构,精准定位目标按钮

方案二:Termux + Bash + adb + curl

适合熟悉Shell脚本的用户,轻量无依赖

  • 步骤1:Termux安装工具
    • 安装adb、curl与JSON解析工具:pkg install adb curl jq
  • 步骤2:配置adb连接
    • 开启USB调试,执行adb devices确认设备连接正常
  • 步骤3:编写Bash脚本
    • 用curl轮询服务器,jq解析返回的JSON指令
    • 收到指令后,通过adb启动APP并模拟点击
    • 核心代码示例:
      APP_PKG="com.husqvarna.automowerconnect"
      SERVER_URL="http://你的服务器地址/control-endpoint"
      
      while true; do
          ACTION=$(curl -s "$SERVER_URL" | jq -r '.action')
          if [ "$ACTION" = "start_mow" ]; then
              # 启动APP
              adb shell monkey -p "$APP_PKG" -c android.intent.category.LAUNCHER 1
              sleep 5
              # 替换为实际割草按钮的坐标,可通过adb shell uiautomator dump获取
              adb shell input tap 480 1200
          fi
          sleep 60
      done
      
  • 注意:坐标需通过adb shell uiautomator dump分析界面获取,或用adb shell getevent捕捉点击坐标

方案三:Tasker + AutoInput + HTTP插件

无需代码,可视化配置,适合非开发用户

  • 步骤1:安装工具
    • 安装Tasker、AutoInput(用于模拟APP操作)、Tasker HTTP请求插件
  • 步骤2:配置自动化任务
    • 添加「HTTP请求」动作,设置服务器接口地址,获取返回数据
    • 添加条件判断:若返回的action字段为start_mow
    • 添加AutoInput动作:启动Husqvarna Automower Connect,定位割草按钮并模拟点击
  • 步骤3:设置触发规则
    • 创建Tasker配置文件,设置定期触发(如每分钟一次)
  • 注意:需给AutoInput开启辅助功能权限,Tasker开启后台运行权限

内容的提问来源于stack exchange,提问作者Arhelyd

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.19 17:42:16