Gomaton
指南
API
GitHub
指南
API
GitHub
  • 前言

    • 快速开始
    • 能力速查
    • 工作原理
    • 硬件输入后端(ESP32 HID)
  • API 参考

    • motion - 触控 / 输入
    • images - 找图找色 / 截图
    • uiacc - 控件(UI 树)
    • device - 设备
    • app - 应用
    • ime - 输入法
    • ocr - 文字识别
    • yolo - 目标检测
    • files - 文件
    • storages - 键值存储
    • https - 网络
    • media - 媒体
    • system - 系统
    • utils - 工具

app — 应用

import "gomaton.dev/sdk/app"

Package app 应用控制(胶水:monkey/am/pm/cmd/dumpsys)。

能力总览:

  • 启动/前台:Launch 按包名启动、CurrentPackage / CurrentActivity 查前台、GetBrowserPackage 默认浏览器。
  • 安装管理:Install / Uninstall、Enable / Disable、Clear 清数据、ForceStop 强停。
  • 查询:Installed 是否已装、Version 版本名、Name 显示名、List 列应用(第三方/含系统、可过滤)。
  • 打开:OpenUrl 打开网址、OpenSetting 应用详情页、ViewFile 用 VIEW Intent 打开本地文件。
  • Intent:StartActivity / SendBroadcast / StartService 按 IntentOptions 发任意 Intent。
  • 其他:IgnoreBattOpt 加电池优化白名单(免 Doze)。

Clear

func Clear(pkg string) error

Clear 清除应用数据(pm clear)。

CurrentActivity

func CurrentActivity() string

CurrentActivity 当前前台 "pkg/Activity"。

CurrentPackage

func CurrentPackage() string

CurrentPackage 当前前台应用包名。

Disable

func Disable(pkg string) error

Disable 对当前用户停用应用(pm disable-user)。

Enable

func Enable(pkg string) error

Enable 启用应用组件(pm enable)。

ForceStop

func ForceStop(pkg string) error

ForceStop 强制停止应用(am force-stop)。

GetBrowserPackage

func GetBrowserPackage() string

GetBrowserPackage 默认浏览器包名。

IgnoreBattOpt

func IgnoreBattOpt(pkg string) error

IgnoreBattOpt 把应用加入电池优化白名单(免 Doze 限制)。

Install

func Install(path string) error

Install 安装 APK(-r 覆盖安装)。

Installed

func Installed(pkg string) bool

Installed 是否已安装。

Launch

func Launch(pkg string) bool

Launch 按包名启动应用(桌面入口)。

List

func List(includeSystem bool, filter string) []AppInfo

List 列应用:includeSystem=false 只列第三方;filter 为子串过滤(可空)。

Name

func Name(pkg string) string

Name 应用显示名(需 aapt,常取不到时返回包名)。

OpenSetting

func OpenSetting(pkg string) error

OpenSetting 打开该应用的「应用详情」系统设置页。

OpenUrl

func OpenUrl(url string) error

OpenUrl 用系统默认应用打开一个 URL(VIEW Intent)。

SendBroadcast

func SendBroadcast(o IntentOptions) error

SendBroadcast 按 IntentOptions 发送广播(am broadcast)。

StartActivity

func StartActivity(o IntentOptions) error

StartActivity 按 IntentOptions 发 Intent 启动 Activity(am start)。

StartService

func StartService(o IntentOptions) error

StartService 按 IntentOptions 启动 Service(am startservice)。

Uninstall

func Uninstall(pkg string) error

Uninstall 卸载应用。

Version

func Version(pkg string) string

Version 应用版本名。

ViewFile

func ViewFile(path, mime string) error

ViewFile 用 VIEW Intent 打开本地文件;mime 可空(空则由系统推断)。

上次更新: 2026/9/2 06:21
贡献者: hb
Prev
device - 设备
Next
ime - 输入法