Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
uni-api
提交
3b1c15d7
U
uni-api
项目概览
DCloud
/
uni-api
通知
670
Star
23
Fork
12
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
3
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-api
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
3
Issue
3
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
3b1c15d7
编写于
10月 26, 2023
作者:
taohebin@dcloud.io
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: uni-installApk
上级
21aa9c23
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
531 addition
and
298 deletion
+531
-298
pages/index/index.vue
pages/index/index.vue
+324
-298
uni_modules/uni-installApk/changelog.md
uni_modules/uni-installApk/changelog.md
+0
-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
+6
-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/index/index.vue
浏览文件 @
3b1c15d7
<
template
>
<view
class=
"content"
>
<button
@
tap=
"testStartWifi"
style=
"width: 100%;"
>
初始化wifi模块
</button>
<button
@
tap=
"testGetWifiList"
style=
"width: 100%;"
>
获取当前wifi列表
</button>
<button
@
tap=
"testOffGetWifiList"
style=
"width: 100%;"
>
移除wifi列表监听
</button>
<button
@
tap=
"testGetConnnectWifi"
style=
"width: 100%;"
>
获取当前连接的wifi
</button>
<button
@
tap=
"testConnnectWifi"
style=
"width: 100%;"
>
链接wifi
</button>
<button
@
tap=
"testStopWifi"
style=
"width: 100%;"
>
关闭wifi模块
</button>
<button
@
tap=
"onGetWifiList2_assert0"
style=
"width: 100%;"
>
onGetWifiList2_assert0
</button>
<button
@
tap=
"testScreenShotListen"
>
开启截屏监听
</button>
<button
@
tap=
"testScreenShotOff"
>
关闭截屏监听
</button>
<button
@
tap=
"testSetUserCaptureScreen"
>
{{
setUserCaptureScreenText
}}
</button>
<button
@
tap=
"testGetBatteryInfo"
>
获取电池电量
</button>
<button
@
tap=
"testGetBatteryInfoSync"
>
同步获取电池电量
</button>
<button
@
tap=
"testonMemoryWarning"
>
开启内存不足告警监听
</button>
<button
@
tap=
"testoffMemoryWarning"
>
关闭内存不足告警监听
</button>
<button
@
tap=
"getLocationTest"
style=
"width: 100%;"
>
获取定位
</button>
</view>
</
template
>
<
script
>
export
default
{
data
()
{
return
{
memListener
:
null
,
setUserCaptureScreenFlag
:
false
,
setUserCaptureScreenText
:
'
禁止截屏
'
,
permissionGranted
:
false
,
id
:
0
}
},
onLoad
()
{
},
methods
:
{
onMemoryWarning
:
function
(
res
){
console
.
log
(
res
);
},
fn
:
function
(
res
){
console
.
log
(
res
)
},
getLocationTest
()
{
console
.
log
(
"
------- getLocationTest:
"
);
uni
.
getLocation
({
type
:
'
gcj02
'
,
success
(
res
)
{
console
.
log
(
"
success
"
,
res
);
},
fail
(
res
)
{
console
.
log
(
"
fail
"
,
res
);
}
})
},
onGetWifiList2_assert0
()
{
console
.
log
(
"
------- onGetWifiList2_assert0:
"
,
this
.
id
);
const
fn
=
res
=>
console
.
log
(
'
onGetWifiList res
'
,
res
)
uni
.
startWifi
({
success
(){
uni
.
onGetWifiList
(
fn
)
uni
.
getWifiList
({
success
()
{
console
.
log
(
'
getWifiList success
'
);
uni
.
offGetWifiList
(
fn
)
uni
.
stopWifi
({
success
()
{},
fail
(
e
)
{
console
.
log
(
"
stopWifi fail:
"
,
e
);
}
})
}
})
}})
this
.
id
++
},
testConnnectWifi
(){
uni
.
startWifi
({
success
:(
res
)
=>
{
console
.
log
(
"
success:
"
+
JSON
.
stringify
(
res
));
// uni.connectWifi({
// maunal:false,
// SSID:"Xiaomi_20D0",
// password:"BBB111",
// complete:(res)=>{
// console.log(res);
// }
// });
},
fail
:(
res
)
=>
{
console
.
log
(
"
fail:
"
+
JSON
.
stringify
(
res
));
},
complete
:(
res
)
=>
{
console
.
log
(
"
complete:
"
+
JSON
.
stringify
(
res
));
}
})
},
testGetConnnectWifi
(){
uni
.
getConnectedWifi
({
partialInfo
:
false
,
complete
:(
res
)
=>
{
console
.
log
(
res
);
if
(
res
.
errCode
==
0
)
{
uni
.
showToast
({
icon
:
'
none
'
,
title
:
res
.
wifi
.
SSID
})
}
else
{
uni
.
showToast
({
icon
:
'
none
'
,
title
:
res
.
errMsg
})
}
}
});
},
testStartWifi
(){
uni
.
startWifi
({
success
:(
res
)
=>
{
console
.
log
(
"
success:
"
+
JSON
.
stringify
(
res
));
// wifi 开启成功后,注册wifi链接状态监听和wifi列表获取监听
uni
.
onGetWifiList
(
function
(
res
){
console
.
log
(
"
onGetWifiList
"
);
console
.
log
(
res
);
});
uni
.
onWifiConnected
(
function
(
res
){
console
.
log
(
"
onWifiConnected
"
);
console
.
log
(
res
);
});
uni
.
onWifiConnectedWithPartialInfo
(
function
(
res
){
console
.
log
(
"
onWifiConnectedWithPartialInfo
"
);
console
.
log
(
res
);
});
},
fail
:(
res
)
=>
{
console
.
log
(
"
fail:
"
+
JSON
.
stringify
(
res
));
},
complete
:(
res
)
=>
{
console
.
log
(
"
complete:
"
+
JSON
.
stringify
(
res
));
}
})
},
testStopWifi
()
{
uni
.
offWifiConnected
()
uni
.
offWifiConnectedWithPartialInfo
()
uni
.
stopWifi
({
success
:(
res
)
=>
{
console
.
log
(
"
success:
"
+
JSON
.
stringify
(
res
));
},
fail
:(
res
)
=>
{
console
.
log
(
"
fail:
"
+
JSON
.
stringify
(
res
));
},
complete
:(
res
)
=>
{
console
.
log
(
"
complete:
"
+
JSON
.
stringify
(
res
));
}
})
},
testGetWifiList
()
{
uni
.
getWifiList
({
success
:(
res
)
=>
{
console
.
log
(
"
success:
"
+
JSON
.
stringify
(
res
));
},
fail
:(
res
)
=>
{
console
.
log
(
"
fail:
"
+
JSON
.
stringify
(
res
));
},
complete
:(
res
)
=>
{
console
.
log
(
"
complete:
"
+
JSON
.
stringify
(
res
));
}
})
},
testOffGetWifiList
(){
uni
.
offGetWifiList
()
},
testonMemoryWarning
()
{
uni
.
onMemoryWarning
(
this
.
onMemoryWarning
)
uni
.
showToast
({
icon
:
'
none
'
,
title
:
'
已监听,注意控制台输出
'
})
},
testoffMemoryWarning
(){
uni
.
offMemoryWarning
(
this
.
onMemoryWarning
)
uni
.
showToast
({
icon
:
'
none
'
,
title
:
'
监听已移除
'
})
},
testScreenShotListen
()
{
var
that
=
this
;
uni
.
onUserCaptureScreen
(
function
(
res
)
{
console
.
log
(
res
);
uni
.
showToast
({
icon
:
"
none
"
,
title
:
'
捕获截屏事件
'
})
that
.
screenImage
=
res
.
path
});
if
(
uni
.
getSystemInfoSync
().
platform
!=
"
android
"
||
that
.
permissionGranted
)
{
// 除android 之外的平台,直接提示监听已开启
uni
.
showToast
({
icon
:
"
none
"
,
title
:
'
截屏监听已开启
'
})
}
},
testScreenShotOff
()
{
uni
.
offUserCaptureScreen
(
function
(
res
)
{
console
.
log
(
res
);
});
// 提示已经开始监听,注意观察
uni
.
showToast
({
icon
:
"
none
"
,
title
:
'
截屏监听已关闭
'
})
},
testGetBatteryInfo
()
{
uni
.
getBatteryInfo
({
success
(
res
)
{
console
.
log
(
res
);
uni
.
showToast
({
title
:
"
当前电量:
"
+
res
.
level
+
'
%
'
,
icon
:
'
none
'
});
}
})
},
testGetBatteryInfoSync
()
{
let
ret
=
uni
.
getBatteryInfoSync
()
console
.
log
(
ret
)
},
testSetUserCaptureScreen
()
{
let
flag
=
this
.
setUserCaptureScreenFlag
;
uni
.
setUserCaptureScreen
({
enable
:
flag
,
success
:
(
res
)
=>
{
console
.
log
(
"
setUserCaptureScreen enable:
"
+
flag
+
"
success:
"
+
JSON
.
stringify
(
res
));
},
fail
:
(
res
)
=>
{
console
.
log
(
"
setUserCaptureScreen enable:
"
+
flag
+
"
fail:
"
+
JSON
.
stringify
(
res
));
},
complete
:
(
res
)
=>
{
console
.
log
(
"
setUserCaptureScreen enable:
"
+
flag
+
"
complete:
"
+
JSON
.
stringify
(
res
));
}
});
uni
.
showToast
({
icon
:
"
none
"
,
title
:
this
.
setUserCaptureScreenText
});
this
.
setUserCaptureScreenFlag
=
!
this
.
setUserCaptureScreenFlag
;
if
(
this
.
setUserCaptureScreenFlag
)
{
this
.
setUserCaptureScreenText
=
'
允许截屏
'
;
}
else
{
this
.
setUserCaptureScreenText
=
'
禁止截屏
'
;
}
},
}
}
</
script
>
<
style
>
.content
{
display
:
flex
;
flex-direction
:
column
;
align-items
:
center
;
justify-content
:
center
;
}
.logo
{
height
:
200
rpx
;
width
:
200
rpx
;
margin-top
:
200
rpx
;
margin-left
:
auto
;
margin-right
:
auto
;
margin-bottom
:
50
rpx
;
}
.text-area
{
display
:
flex
;
justify-content
:
center
;
}
.title
{
font-size
:
36
rpx
;
color
:
#8f8f94
;
}
</
style
>
<
template
>
<view
class=
"content"
>
<button
@
tap=
"testStartWifi"
style=
"width: 100%;"
>
初始化wifi模块
</button>
<button
@
tap=
"testGetWifiList"
style=
"width: 100%;"
>
获取当前wifi列表
</button>
<button
@
tap=
"testOffGetWifiList"
style=
"width: 100%;"
>
移除wifi列表监听
</button>
<button
@
tap=
"testGetConnnectWifi"
style=
"width: 100%;"
>
获取当前连接的wifi
</button>
<button
@
tap=
"testConnnectWifi"
style=
"width: 100%;"
>
链接wifi
</button>
<button
@
tap=
"testStopWifi"
style=
"width: 100%;"
>
关闭wifi模块
</button>
<button
@
tap=
"onGetWifiList2_assert0"
style=
"width: 100%;"
>
onGetWifiList2_assert0
</button>
<button
@
tap=
"testScreenShotListen"
>
开启截屏监听
</button>
<button
@
tap=
"testScreenShotOff"
>
关闭截屏监听
</button>
<button
@
tap=
"testSetUserCaptureScreen"
>
{{
setUserCaptureScreenText
}}
</button>
<button
@
tap=
"testGetBatteryInfo"
>
获取电池电量
</button>
<button
@
tap=
"testGetBatteryInfoSync"
>
同步获取电池电量
</button>
<button
@
tap=
"testonMemoryWarning"
>
开启内存不足告警监听
</button>
<button
@
tap=
"testoffMemoryWarning"
>
关闭内存不足告警监听
</button>
<button
@
tap=
"getLocationTest"
style=
"width: 100%;"
>
获取定位
</button>
<button
type=
"default"
@
click=
"handleInstallApk"
>
安装apk
</button>
</view>
</
template
>
<
script
>
import
{
installApk
}
from
"
@/uni_modules/uni-installApk
"
export
default
{
data
()
{
return
{
memListener
:
null
,
setUserCaptureScreenFlag
:
false
,
setUserCaptureScreenText
:
'
禁止截屏
'
,
permissionGranted
:
false
,
id
:
0
}
},
onLoad
()
{
},
methods
:
{
onMemoryWarning
:
function
(
res
)
{
console
.
log
(
res
);
},
fn
:
function
(
res
)
{
console
.
log
(
res
)
},
getLocationTest
()
{
console
.
log
(
"
------- getLocationTest:
"
);
uni
.
getLocation
({
type
:
'
gcj02
'
,
success
(
res
)
{
console
.
log
(
"
success
"
,
res
);
},
fail
(
res
)
{
console
.
log
(
"
fail
"
,
res
);
}
})
},
onGetWifiList2_assert0
()
{
console
.
log
(
"
------- onGetWifiList2_assert0:
"
,
this
.
id
);
const
fn
=
res
=>
console
.
log
(
'
onGetWifiList res
'
,
res
)
uni
.
startWifi
({
success
()
{
uni
.
onGetWifiList
(
fn
)
uni
.
getWifiList
({
success
()
{
console
.
log
(
'
getWifiList success
'
);
uni
.
offGetWifiList
(
fn
)
uni
.
stopWifi
({
success
()
{},
fail
(
e
)
{
console
.
log
(
"
stopWifi fail:
"
,
e
);
}
})
}
})
}
})
this
.
id
++
},
testConnnectWifi
()
{
uni
.
startWifi
({
success
:
(
res
)
=>
{
console
.
log
(
"
success:
"
+
JSON
.
stringify
(
res
));
// uni.connectWifi({
// maunal:false,
// SSID:"Xiaomi_20D0",
// password:"BBB111",
// complete:(res)=>{
// console.log(res);
// }
// });
},
fail
:
(
res
)
=>
{
console
.
log
(
"
fail:
"
+
JSON
.
stringify
(
res
));
},
complete
:
(
res
)
=>
{
console
.
log
(
"
complete:
"
+
JSON
.
stringify
(
res
));
}
})
},
testGetConnnectWifi
()
{
uni
.
getConnectedWifi
({
partialInfo
:
false
,
complete
:
(
res
)
=>
{
console
.
log
(
res
);
if
(
res
.
errCode
==
0
)
{
uni
.
showToast
({
icon
:
'
none
'
,
title
:
res
.
wifi
.
SSID
})
}
else
{
uni
.
showToast
({
icon
:
'
none
'
,
title
:
res
.
errMsg
})
}
}
});
},
testStartWifi
()
{
uni
.
startWifi
({
success
:
(
res
)
=>
{
console
.
log
(
"
success:
"
+
JSON
.
stringify
(
res
));
// wifi 开启成功后,注册wifi链接状态监听和wifi列表获取监听
uni
.
onGetWifiList
(
function
(
res
)
{
console
.
log
(
"
onGetWifiList
"
);
console
.
log
(
res
);
});
uni
.
onWifiConnected
(
function
(
res
)
{
console
.
log
(
"
onWifiConnected
"
);
console
.
log
(
res
);
});
uni
.
onWifiConnectedWithPartialInfo
(
function
(
res
)
{
console
.
log
(
"
onWifiConnectedWithPartialInfo
"
);
console
.
log
(
res
);
});
},
fail
:
(
res
)
=>
{
console
.
log
(
"
fail:
"
+
JSON
.
stringify
(
res
));
},
complete
:
(
res
)
=>
{
console
.
log
(
"
complete:
"
+
JSON
.
stringify
(
res
));
}
})
},
testStopWifi
()
{
uni
.
offWifiConnected
()
uni
.
offWifiConnectedWithPartialInfo
()
uni
.
stopWifi
({
success
:
(
res
)
=>
{
console
.
log
(
"
success:
"
+
JSON
.
stringify
(
res
));
},
fail
:
(
res
)
=>
{
console
.
log
(
"
fail:
"
+
JSON
.
stringify
(
res
));
},
complete
:
(
res
)
=>
{
console
.
log
(
"
complete:
"
+
JSON
.
stringify
(
res
));
}
})
},
testGetWifiList
()
{
uni
.
getWifiList
({
success
:
(
res
)
=>
{
console
.
log
(
"
success:
"
+
JSON
.
stringify
(
res
));
},
fail
:
(
res
)
=>
{
console
.
log
(
"
fail:
"
+
JSON
.
stringify
(
res
));
},
complete
:
(
res
)
=>
{
console
.
log
(
"
complete:
"
+
JSON
.
stringify
(
res
));
}
})
},
testOffGetWifiList
()
{
uni
.
offGetWifiList
()
},
testonMemoryWarning
()
{
uni
.
onMemoryWarning
(
this
.
onMemoryWarning
)
uni
.
showToast
({
icon
:
'
none
'
,
title
:
'
已监听,注意控制台输出
'
})
},
testoffMemoryWarning
()
{
uni
.
offMemoryWarning
(
this
.
onMemoryWarning
)
uni
.
showToast
({
icon
:
'
none
'
,
title
:
'
监听已移除
'
})
},
testScreenShotListen
()
{
var
that
=
this
;
uni
.
onUserCaptureScreen
(
function
(
res
)
{
console
.
log
(
res
);
uni
.
showToast
({
icon
:
"
none
"
,
title
:
'
捕获截屏事件
'
})
that
.
screenImage
=
res
.
path
});
if
(
uni
.
getSystemInfoSync
().
platform
!=
"
android
"
||
that
.
permissionGranted
)
{
// 除android 之外的平台,直接提示监听已开启
uni
.
showToast
({
icon
:
"
none
"
,
title
:
'
截屏监听已开启
'
})
}
},
testScreenShotOff
()
{
uni
.
offUserCaptureScreen
(
function
(
res
)
{
console
.
log
(
res
);
});
// 提示已经开始监听,注意观察
uni
.
showToast
({
icon
:
"
none
"
,
title
:
'
截屏监听已关闭
'
})
},
testGetBatteryInfo
()
{
uni
.
getBatteryInfo
({
success
(
res
)
{
console
.
log
(
res
);
uni
.
showToast
({
title
:
"
当前电量:
"
+
res
.
level
+
'
%
'
,
icon
:
'
none
'
});
}
})
},
testGetBatteryInfoSync
()
{
let
ret
=
uni
.
getBatteryInfoSync
()
console
.
log
(
ret
)
},
testSetUserCaptureScreen
()
{
let
flag
=
this
.
setUserCaptureScreenFlag
;
uni
.
setUserCaptureScreen
({
enable
:
flag
,
success
:
(
res
)
=>
{
console
.
log
(
"
setUserCaptureScreen enable:
"
+
flag
+
"
success:
"
+
JSON
.
stringify
(
res
));
},
fail
:
(
res
)
=>
{
console
.
log
(
"
setUserCaptureScreen enable:
"
+
flag
+
"
fail:
"
+
JSON
.
stringify
(
res
));
},
complete
:
(
res
)
=>
{
console
.
log
(
"
setUserCaptureScreen enable:
"
+
flag
+
"
complete:
"
+
JSON
.
stringify
(
res
));
}
});
uni
.
showToast
({
icon
:
"
none
"
,
title
:
this
.
setUserCaptureScreenText
});
this
.
setUserCaptureScreenFlag
=
!
this
.
setUserCaptureScreenFlag
;
if
(
this
.
setUserCaptureScreenFlag
)
{
this
.
setUserCaptureScreenText
=
'
允许截屏
'
;
}
else
{
this
.
setUserCaptureScreenText
=
'
禁止截屏
'
;
}
},
handleInstallApk
()
{
installApk
({
filePath
:
"
/sdcard/Android/data/io.dcloud.HBuilder/apps/HBuilder/doc/ddd.apk
"
,
// filePath:"/static/ddd.apk",
complete
(
res
)
{
console
.
log
(
res
);
}
})
},
}
}
</
script
>
<
style
>
.content
{
display
:
flex
;
flex-direction
:
column
;
align-items
:
center
;
justify-content
:
center
;
}
.logo
{
height
:
200
rpx
;
width
:
200
rpx
;
margin-top
:
200
rpx
;
margin-left
:
auto
;
margin-right
:
auto
;
margin-bottom
:
50
rpx
;
}
.text-area
{
display
:
flex
;
justify-content
:
center
;
}
.title
{
font-size
:
36
rpx
;
color
:
#8f8f94
;
}
</
style
>
\ No newline at end of file
uni_modules/uni-installApk/changelog.md
0 → 100644
浏览文件 @
3b1c15d7
uni_modules/uni-installApk/package.json
0 → 100644
浏览文件 @
3b1c15d7
{
"id"
:
"uni-installApk"
,
"displayName"
:
"uni-installApk"
,
"version"
:
"1.0.0"
,
"description"
:
"uni-installApk"
,
"keywords"
:
[
"uni-installApk"
],
"repository"
:
""
,
"engines"
:
{
"HBuilderX"
:
"^3.6.8"
},
"dcloudext"
:
{
"type"
:
"uts"
,
"sale"
:
{
"regular"
:
{
"price"
:
"0.00"
},
"sourcecode"
:
{
"price"
:
"0.00"
}
},
"contact"
:
{
"qq"
:
""
},
"declaration"
:
{
"ads"
:
""
,
"data"
:
""
,
"permissions"
:
""
},
"npmurl"
:
""
},
"uni_modules"
:
{
"dependencies"
:
[],
"uni-ext-api"
:
{
"uni"
:
{
"installApk"
:
{
"name"
:
"installApk"
,
"app"
:
{
"js"
:
false
,
"kotlin"
:
true
,
"swift"
:
false
}
}
}
},
"encrypt"
:
[],
"platforms"
:
{
"cloud"
:
{
"tcb"
:
"u"
,
"aliyun"
:
"u"
},
"client"
:
{
"Vue"
:
{
"vue2"
:
"u"
,
"vue3"
:
"u"
},
"App"
:
{
"app-android"
:
"u"
,
"app-ios"
:
"u"
},
"H5-mobile"
:
{
"Safari"
:
"u"
,
"Android Browser"
:
"u"
,
"微信浏览器(Android)"
:
"u"
,
"QQ浏览器(Android)"
:
"u"
},
"H5-pc"
:
{
"Chrome"
:
"u"
,
"IE"
:
"u"
,
"Edge"
:
"u"
,
"Firefox"
:
"u"
,
"Safari"
:
"u"
},
"小程序"
:
{
"微信"
:
"u"
,
"阿里"
:
"u"
,
"百度"
:
"u"
,
"字节跳动"
:
"u"
,
"QQ"
:
"u"
,
"钉钉"
:
"u"
,
"快手"
:
"u"
,
"飞书"
:
"u"
,
"京东"
:
"u"
},
"快应用"
:
{
"华为"
:
"u"
,
"联盟"
:
"u"
}
}
}
}
}
\ No newline at end of file
uni_modules/uni-installApk/readme.md
0 → 100644
浏览文件 @
3b1c15d7
# uni-installApk
### 开发文档
[
UTS 语法
](
https://uniapp.dcloud.net.cn/tutorial/syntax-uts.html
)
[
UTS API插件
](
https://uniapp.dcloud.net.cn/plugin/uts-plugin.html
)
[
UTS 组件插件
](
https://uniapp.dcloud.net.cn/plugin/uts-component.html
)
[
Hello UTS
](
https://gitcode.net/dcloud/hello-uts
)
\ No newline at end of file
uni_modules/uni-installApk/utssdk/app-android/AndroidManifest.xml
0 → 100644
浏览文件 @
3b1c15d7
<?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
浏览文件 @
3b1c15d7
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 = {
message: "success"
}
options.success?.(success)
options.complete?.(success)
}
\ No newline at end of file
uni_modules/uni-installApk/utssdk/app-ios/index.uts
0 → 100644
浏览文件 @
3b1c15d7
uni_modules/uni-installApk/utssdk/interface.uts
0 → 100644
浏览文件 @
3b1c15d7
export interface Uni {
/**
* installApk()
* @description
* 安装apk
* @param {InstallApkOptions}
* @return {void}
* @uniPlatform {
* "app": {
* "android": {
* "osVer": "4.4",
* "uniVer": "3.96+",
* "unixVer": "3.96+"
* },
* "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 = {
/**
* 安装成功消息
*/
message : 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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录