Shell 模块
android.shell 用于执行设备端命令,适合查询系统状态、做自动授权辅助、执行后台任务。
常用方法
executeCommand(shell)
执行 Shell 命令并返回结果。
- 参数:
shell: string - 返回值:通常为命令输出字符串,具体取决于命令本身
const output = await android.shell.executeCommand('id')
console.log(output)executeCommandBackground(shell)
后台执行命令。
- 参数:
shell: string - 返回值:通常为执行状态或任务标识
await android.shell.executeCommandBackground('echo test')使用建议
- 只把 Shell 当辅助能力,不要把所有逻辑都下沉到命令行
- 需要长期维护的业务逻辑优先使用 SDK 模块方法
- 涉及权限申请、系统状态读取时,常和
android.auth配合使用
