Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello uni-app x
提交
6a7b7910
H
hello uni-app x
项目概览
DCloud
/
hello uni-app x
通知
5994
Star
90
Fork
162
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
18
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
hello uni-app x
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
18
Issue
18
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
6a7b7910
编写于
10月 27, 2023
作者:
taohebin@dcloud.io
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: installApk示例
上级
18b0bdfd
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
304 addition
and
1 deletion
+304
-1
pages.json
pages.json
+8
-0
pages/API/install-apk/install-apk.uvue
pages/API/install-apk/install-apk.uvue
+47
-0
pages/tabBar/API.uvue
pages/tabBar/API.uvue
+5
-1
static/test-apk/test.apk
static/test-apk/test.apk
+0
-0
uni_modules/uni-installApk/changelog.md
uni_modules/uni-installApk/changelog.md
+6
-0
uni_modules/uni-installApk/package.json
uni_modules/uni-installApk/package.json
+93
-0
uni_modules/uni-installApk/readme.md
uni_modules/uni-installApk/readme.md
+37
-0
uni_modules/uni-installApk/utssdk/app-android/AndroidManifest.xml
...les/uni-installApk/utssdk/app-android/AndroidManifest.xml
+5
-0
uni_modules/uni-installApk/utssdk/app-android/index.uts
uni_modules/uni-installApk/utssdk/app-android/index.uts
+38
-0
uni_modules/uni-installApk/utssdk/app-ios/index.uts
uni_modules/uni-installApk/utssdk/app-ios/index.uts
+0
-0
uni_modules/uni-installApk/utssdk/interface.uts
uni_modules/uni-installApk/utssdk/interface.uts
+65
-0
未找到文件。
pages.json
浏览文件 @
6a7b7910
...
@@ -1015,6 +1015,14 @@
...
@@ -1015,6 +1015,14 @@
"navigationBarTitleText"
:
"transitionend事件"
,
"navigationBarTitleText"
:
"transitionend事件"
,
"enablePullDownRefresh"
:
false
"enablePullDownRefresh"
:
false
}
}
},
{
"path"
:
"pages/API/install-apk/install-apk"
,
"style"
:
{
"navigationBarTitleText"
:
"install-apk"
,
"enablePullDownRefresh"
:
false
}
}
}
],
],
...
...
pages/API/install-apk/install-apk.uvue
0 → 100644
浏览文件 @
6a7b7910
<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>
.uni-pd {
padding-left: 30rpx;
}
</style>
pages/tabBar/API.uvue
浏览文件 @
6a7b7910
...
@@ -248,7 +248,11 @@
...
@@ -248,7 +248,11 @@
{
{
name: '电量',
name: '电量',
url: 'get-battery-info',
url: 'get-battery-info',
},
},
{
name: '安装Apk',
url: 'install-apk'
}
/* {
/* {
name: "打电话",
name: "打电话",
url: "make-phone-call",
url: "make-phone-call",
...
...
static/test-apk/test.apk
0 → 100644
浏览文件 @
6a7b7910
文件已添加
uni_modules/uni-installApk/changelog.md
0 → 100644
浏览文件 @
6a7b7910
## 1.0.2(2023-10-27)
修改文档
## 1.0.1(2023-10-27)
支持js层调用
## 1.0.0(2023-10-26)
安装apk的插件
uni_modules/uni-installApk/package.json
0 → 100644
浏览文件 @
6a7b7910
{
"id"
:
"uni-installApk"
,
"displayName"
:
"uni-installApk"
,
"version"
:
"1.0.2"
,
"description"
:
"uni-installApk"
,
"keywords"
:
[
"uni-installApk"
],
"repository"
:
""
,
"engines"
:
{
"HBuilderX"
:
"^3.94"
},
"dcloudext"
:
{
"type"
:
"uts"
,
"sale"
:
{
"regular"
:
{
"price"
:
"0.00"
},
"sourcecode"
:
{
"price"
:
"0.00"
}
},
"contact"
:
{
"qq"
:
""
},
"declaration"
:
{
"ads"
:
"无"
,
"data"
:
"无"
,
"permissions"
:
"android.permission.REQUEST_INSTALL_PACKAGES"
},
"npmurl"
:
""
},
"uni_modules"
:
{
"dependencies"
:
[],
"uni-ext-api"
:
{
"uni"
:
{
"installApk"
:
{
"name"
:
"installApk"
,
"app"
:
{
"js"
:
true
,
"kotlin"
:
true
,
"swift"
:
false
}
}
}
},
"encrypt"
:
[],
"platforms"
:
{
"cloud"
:
{
"tcb"
:
"y"
,
"aliyun"
:
"y"
},
"client"
:
{
"Vue"
:
{
"vue2"
:
"y"
,
"vue3"
:
"y"
},
"App"
:
{
"app-android"
:
"y"
,
"app-ios"
:
"n"
},
"H5-mobile"
:
{
"Safari"
:
"n"
,
"Android Browser"
:
"n"
,
"微信浏览器(Android)"
:
"n"
,
"QQ浏览器(Android)"
:
"n"
},
"H5-pc"
:
{
"Chrome"
:
"n"
,
"IE"
:
"n"
,
"Edge"
:
"n"
,
"Firefox"
:
"n"
,
"Safari"
:
"n"
},
"小程序"
:
{
"微信"
:
"n"
,
"阿里"
:
"n"
,
"百度"
:
"n"
,
"字节跳动"
:
"n"
,
"QQ"
:
"n"
,
"钉钉"
:
"n"
,
"快手"
:
"n"
,
"飞书"
:
"n"
,
"京东"
:
"n"
},
"快应用"
:
{
"华为"
:
"n"
,
"联盟"
:
"n"
}
}
}
}
}
\ No newline at end of file
uni_modules/uni-installApk/readme.md
0 → 100644
浏览文件 @
6a7b7910
# uni-installApk
## 使用说明
Android平台安装Apk
**注意: 3.95以下需要自定义基座**
### uni.installApk(options : InstallApkOptions):void
安装apk
参数说明
```
type InstallApkOptions = {
/**
* apk文件地址
*/
filePath : string,
/**
* 接口调用成功的回调函数
* @defaultValue null
*/
success ?: (res : any) => void,
/**
* 接口调用失败的回调函数
* @defaultValue null
*/
fail ?: (err : any) => void,
/**
* 接口调用结束的回调函数(调用成功、失败都会执行)
* @defaultValue null
*/
complete ?: (res : any) => void,
}
```
\ No newline at end of file
uni_modules/uni-installApk/utssdk/app-android/AndroidManifest.xml
0 → 100644
浏览文件 @
6a7b7910
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:tools=
"http://schemas.android.com/tools"
package=
"io.dcloud.uni.installApk"
>
<uses-permission
android:name=
"android.permission.REQUEST_INSTALL_PACKAGES"
/>
</manifest>
\ No newline at end of file
uni_modules/uni-installApk/utssdk/app-android/index.uts
0 → 100644
浏览文件 @
6a7b7910
import { InstallApkOptions, InstallApkSuccess } from "../interface.uts"
import Intent from 'android.content.Intent';
import Build from 'android.os.Build';
import File from 'java.io.File';
import FileProvider from 'androidx.core.content.FileProvider';
import Context from 'android.content.Context';
import Uri from 'android.net.Uri';
export function installApk(options : InstallApkOptions) : void {
const context = UTSAndroid.getAppContext() as Context
const filePath = UTSAndroid.convert2AbsFullPath(options.filePath)
const apkFile = new File(filePath)
if (!apkFile.exists() && !apkFile.isFile()) {
let error = new UniError("uni-installApk", -1, "filePath is illegal");
options.fail?.(error)
options.complete?.(error)
return
}
const intent = new Intent()
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
intent.setAction(Intent.ACTION_VIEW)
if (Build.VERSION.SDK_INT >= 24) {
const authority = context.getPackageName() + ".dc.fileprovider"
const apkUri = FileProvider.getUriForFile(context, authority, apkFile)
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.setDataAndType(apkUri, "application/vnd.android.package-archive");
} else {
intent.setDataAndType(Uri.fromFile(apkFile), "application/vnd.android.package-archive");
}
context.startActivity(intent)
const success : InstallApkSuccess = {
errMsg: "success"
}
options.success?.(success)
options.complete?.(success)
}
\ No newline at end of file
uni_modules/uni-installApk/utssdk/app-ios/index.uts
0 → 100644
浏览文件 @
6a7b7910
uni_modules/uni-installApk/utssdk/interface.uts
0 → 100644
浏览文件 @
6a7b7910
export interface Uni {
/**
* installApk()
* @description
* 安装apk
* @param {InstallApkOptions}
* @return {void}
* @uniPlatform {
* "app": {
* "android": {
* "osVer": "4.4",
* "uniVer": "3.94+",
* "unixVer": "3.94+"
* },
* "ios": {
* "osVer": "x",
* "uniVer": "x",
* "unixVer": "x"
* }
* }
* }
* @example
```typescript
uni.installApk({
filePath: "/xx/xx/xx.apk",
complete: (res: any) => {
console.log("complete => " + JSON.stringify(res));
}
});
```
*/
installApk(options : InstallApkOptions) : void
}
export type InstallApkSuccess = {
/**
* 安装成功消息
*/
errMsg : string
}
export type InstallApkComplete = any
export type InstallApkSuccessCallback = (res : InstallApkSuccess) => void
export type InstallApkFailCallback = (err : UniError) => void
export type InstallApkCompleteCallback = (res : InstallApkComplete) => void
export type InstallApkOptions = {
/**
* apk文件地址
*/
filePath : string,
/**
* 接口调用成功的回调函数
* @defaultValue null
*/
success ?: InstallApkSuccessCallback | null,
/**
* 接口调用失败的回调函数
* @defaultValue null
*/
fail ?: InstallApkFailCallback | null,
/**
* 接口调用结束的回调函数(调用成功、失败都会执行)
* @defaultValue null
*/
complete ?: InstallApkCompleteCallback | null
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录