提交 7d61842c 编写于 作者: taohebin@dcloud.io's avatar taohebin@dcloud.io

update: install-apk

上级 6c0049b1
## 1.0.5(2024-04-28)
解决Android API 24版本以下设备,安装apk失败的问题。
## 1.0.4(2023-12-08) ## 1.0.4(2023-12-08)
兼容asset目录文件的处理 兼容asset目录文件的处理
## 1.0.3(2023-10-27) ## 1.0.3(2023-10-27)
......
{ {
"id": "uni-installApk", "id": "uni-installApk",
"displayName": "uni-installApk", "displayName": "uni-installApk",
"version": "1.0.4", "version": "1.0.5",
"description": "uni-installApk", "description": "uni-installApk",
"keywords": [ "keywords": [
"uni-installApk" "uni-installApk"
...@@ -48,7 +48,8 @@ ...@@ -48,7 +48,8 @@
"platforms": { "platforms": {
"cloud": { "cloud": {
"tcb": "y", "tcb": "y",
"aliyun": "y" "aliyun": "y",
"alipay": "n"
}, },
"client": { "client": {
"Vue": { "Vue": {
......
...@@ -7,6 +7,7 @@ import FileProvider from 'androidx.core.content.FileProvider'; ...@@ -7,6 +7,7 @@ import FileProvider from 'androidx.core.content.FileProvider';
import Context from 'android.content.Context'; import Context from 'android.content.Context';
import Uri from 'android.net.Uri'; import Uri from 'android.net.Uri';
import FileOutputStream from 'java.io.FileOutputStream'; import FileOutputStream from 'java.io.FileOutputStream';
import IOException from 'java.io.IOException';
export function installApk(options : InstallApkOptions) : void { export function installApk(options : InstallApkOptions) : void {
const context = UTSAndroid.getAppContext() as Context const context = UTSAndroid.getAppContext() as Context
...@@ -74,6 +75,11 @@ function copyAssetFileToPrivateDir(context : Context, fileName : string) : File ...@@ -74,6 +75,11 @@ function copyAssetFileToPrivateDir(context : Context, fileName : string) : File
inputStream.close() inputStream.close()
outputStream.close() outputStream.close()
if (Build.VERSION.SDK_INT < 24) {
changePermissionRecursive(new File(context.getCacheDir().getPath() + "/apks/"))
}
return outFile return outFile
} catch (e : Exception) { } catch (e : Exception) {
e.printStackTrace() e.printStackTrace()
...@@ -81,3 +87,12 @@ function copyAssetFileToPrivateDir(context : Context, fileName : string) : File ...@@ -81,3 +87,12 @@ function copyAssetFileToPrivateDir(context : Context, fileName : string) : File
return null return null
} }
function changePermissionRecursive(file: File){
const cmd = "chmod -R 777 " + file.getAbsolutePath()
const runtime = Runtime.getRuntime()
try {
runtime.exec(cmd)
} catch (e: IOException) {
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册