# uni.installApk(options)

安装apk

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

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

# 参数

名称 类型 必填 默认值 描述
options InstallApkOptions -
名称 类型 必备 默认值 描述
filePath string - apk文件地址
success (res: InstallApkSuccess) => void | null null 接口调用成功的回调函数
fail (err: InstallApkFail) => void | null null 接口调用失败的回调函数
complete (res: any) => void | null null 接口调用结束的回调函数(调用成功、失败都会执行)
# InstallApkSuccess 的属性值
名称 类型 必备 默认值 描述
errMsg string - 安装成功消息
# InstallApkFail 的属性值
名称 类型 必备 默认值 描述
errCode number - 错误码 - 1300002 找不到文件
errSubject string - 统一错误主题(模块)名称
data any | null - 错误信息中包含的数据
cause Error | null - 源错误信息,可以包含多个错误,详见SourceError
errMsg string - -

# installApk 兼容性

Android iOS web
3.94 x x

# 参见

相关 Bug

# 示例

hello uni-app x

<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>

# 通用类型

# GeneralCallbackResult

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