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 可空(空则由系统推断)。