app

package
v0.0.0-...-54dc0dc Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 17, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package app 提供与其他应用交互的能力:启动应用、打开文件、发送意图、 查询/安装/卸载应用、无障碍服务管理等。

需要 PackageManager 的查询(GetName/GetIcon/GetVersion 等)通过 Java 守护 进程的 Rhino 引擎执行 app.js 完成;其余能力基于 shell 命令(pm/am/settings)。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Clear

func Clear(packageName string)

Clear 清除应用数据。

func CurrentActivity

func CurrentActivity() string

CurrentActivity 获取当前页面应用类名。

func CurrentPackage

func CurrentPackage() string

CurrentPackage 获取当前页面应用包名。

func Disable

func Disable(packageName string)

Disable 禁用应用。

func DisableAccessibility

func DisableAccessibility(packageName string)

DisableAccessibility 关闭指定应用的无障碍服务。

func EditFile

func EditFile(path string)

EditFile 用其他应用编辑文件。文件不存在的情况由编辑文件的应用处理。

func Enable

func Enable(packageName string)

Enable 启用应用。

func EnableAccessibility

func EnableAccessibility(packageName string)

EnableAccessibility 启用指定应用的无障碍服务。 自动查找应用内声明了 BIND_ACCESSIBILITY_SERVICE 权限的服务组件并加入 系统已启用列表;找不到无障碍服务时无操作。

func ForceStop

func ForceStop(packageName string)

ForceStop 强制停止应用。

func GetBrowserPackage

func GetBrowserPackage() string

GetBrowserPackage 获取系统默认浏览器包名。

func GetIcon

func GetIcon(packageName string) []byte

GetIcon 获取应用图标的 PNG 数据,失败返回 nil。

func GetList

func GetList(includeSystemApps bool) []string

GetList 获取手机中所有应用包名列表。 includeSystemApps 为 true 时包含系统应用,否则只返回第三方应用。

func GetName

func GetName(packageName string) string

GetName 获取指定包名应用的显示名称,失败返回空串。

func GetVersion

func GetVersion(packageName string) string

GetVersion 获取指定包名应用的版本号(versionName),失败返回空串。

func IgnoreBattOpt

func IgnoreBattOpt(packageName string)

IgnoreBattOpt 忽略应用电池优化。

func Install

func Install(path string)

Install 安装应用,支持 apk 与 xapk/apks/apkm(拆分包)格式。

func IsInstalled

func IsInstalled(packageName string) bool

IsInstalled 判断是否已经安装某个应用。

func Launch

func Launch(packageName string, displayId ...int) bool

Launch 通过应用包名启动应用,成功返回 true。

packageName 支持"包名"或"包名/类名"两种格式;displayId 为可选的屏幕 ID, 默认 0 表示主屏,可配合 vdisplay 创建的虚拟屏幕使用。

func OpenAppSetting deprecated

func OpenAppSetting(packageName string) bool

OpenAppSetting 打开应用的详情页(设置页)。

Deprecated: 请使用 OpenSetting。

func OpenSetting

func OpenSetting(packageName string) bool

OpenSetting 打开应用的详情页(设置页),成功返回 true。

func OpenUrl

func OpenUrl(url string)

OpenUrl 用浏览器打开网站url。

func SelfPackage

func SelfPackage() string

SelfPackage 获取当前宿主 APK 的包名;宿主控制服务不可用时返回空串。

func SendBroadcast

func SendBroadcast(options IntentOptions)

SendBroadcast 根据选项构造一个Intent,并发送该广播。

func StartActivity

func StartActivity(options IntentOptions)

StartActivity 根据选项构造一个Intent,并启动该Activity。

func StartService

func StartService(options IntentOptions)

StartService 根据选项构造一个Intent,并启动该服务。

func Uninstall

func Uninstall(packageName string)

Uninstall 卸载应用。

func ViewFile

func ViewFile(path string)

ViewFile 用其他应用查看文件。文件不存在的情况由查看文件的应用处理。

Types

type IntentOptions

type IntentOptions struct {
	Action      string
	Type        string
	Data        string
	Category    []string
	PackageName string
	ClassName   string
	Extras      map[string]string
	Flags       []string
}

IntentOptions 描述一个 Intent 的构造参数。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL