# uni.installApk(options)

安装apk

# installApk 兼容性

Web 微信小程序 Android iOS
x - 3.94 x

安装Apk最常见的场景是App的升级,更推荐使用uni的App升级中心,这是一个云端一体开源项目,想达到该项目的体验细节需要大量代码,不如直接拿走使用。

# 参数

名称 类型 必填 默认值 兼容性 描述
options InstallApkOptions - - -
名称 类型 必备 默认值 兼容性 描述
filePath string - - apk文件地址
success (res: InstallApkSuccess) => void null - 接口调用成功的回调函数
fail (err: InstallApkFail) => void null - 接口调用失败的回调函数
complete (res: any) => void null - 接口调用结束的回调函数(调用成功、失败都会执行)

# InstallApkSuccess 的属性值

名称 类型 必备 默认值 兼容性 描述
errMsg string - - 安装成功消息

# InstallApkFail 的属性值

名称 类型 必备 默认值 兼容性 描述
errCode number - - 错误码
- 1300002 找不到文件
errSubject string - - 统一错误主题(模块)名称
data any - - 错误信息中包含的数据
cause Error - - 源错误信息,可以包含多个错误,详见SourceError
errMsg string - - -

# 参见

# 示例

hello uni-app x

该 API 不支持 Web,请运行 hello uni-app x 到 App 平台体验

扫码体验(手机浏览器跳转到App直达页)
<template>
  <!-- #ifdef APP -->
  <scroll-view style="flex: 1">
  <!-- #endif -->
    <view>
      <page-head :title="title"></page-head>
      <view class="uni-common-mt">
        <view class="uni-padding-wrap">
          <view class="uni-btn-v">
            <button type="primary" @tap="installApk">
              installApk
            </button>
          </view>
        </view>
      </view>
    </view>
  <!-- #ifdef APP -->
  </scroll-view>
  <!-- #endif -->
</template>
<script>
  export default {
    data() {
      return {
        title: 'installApk'
      }
    },
    onUnload: function () {
    },
    methods: {
      installApk: function () {
        uni.installApk({
          filePath: "/static/test-apk/test.apk",
          complete(res : any) {
            console.log(res);
          }
        })
      },
    }
  }
</script>
<style>
</style>

# Tips

  • HBuilderX 3.99以前,uni.install是ext api,需单独下载。从HBuilderX 3.99起 uni-app x 内置了该api,无需再单独下载。

# 通用类型

# GeneralCallbackResult

名称 类型 必备 默认值 兼容性 描述
errMsg string -
错误信息