提交 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)
兼容asset目录文件的处理
## 1.0.3(2023-10-27)
......
{
"id": "uni-installApk",
"displayName": "uni-installApk",
"version": "1.0.4",
"version": "1.0.5",
"description": "uni-installApk",
"keywords": [
"uni-installApk"
......@@ -48,7 +48,8 @@
"platforms": {
"cloud": {
"tcb": "y",
"aliyun": "y"
"aliyun": "y",
"alipay": "n"
},
"client": {
"Vue": {
......
......@@ -6,7 +6,8 @@ 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';
import FileOutputStream from 'java.io.FileOutputStream';
import FileOutputStream from 'java.io.FileOutputStream';
import IOException from 'java.io.IOException';
export function installApk(options : InstallApkOptions) : void {
const context = UTSAndroid.getAppContext() as Context
......@@ -34,7 +35,7 @@ export function installApk(options : InstallApkOptions) : void {
const apkUri = FileProvider.getUriForFile(context, authority, apkFile!!)
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.setDataAndType(apkUri, "application/vnd.android.package-archive");
} else {
} else {
intent.setDataAndType(Uri.fromFile(apkFile!!), "application/vnd.android.package-archive");
}
......@@ -59,7 +60,7 @@ function copyAssetFileToPrivateDir(context : Context, fileName : string) : File
}
if (!outFile.exists()) {
outFile.createNewFile()
}
}
const inputStream = context.getAssets().open(fileName)
const outputStream = new FileOutputStream(outFile)
let buffer = new ByteArray(1024);
......@@ -72,8 +73,13 @@ function copyAssetFileToPrivateDir(context : Context, fileName : string) : File
} while (true)
inputStream.close()
outputStream.close()
outputStream.close()
if (Build.VERSION.SDK_INT < 24) {
changePermissionRecursive(new File(context.getCacheDir().getPath() + "/apks/"))
}
return outFile
} catch (e : Exception) {
e.printStackTrace()
......@@ -81,3 +87,12 @@ function copyAssetFileToPrivateDir(context : Context, fileName : string) : File
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.
先完成此消息的编辑!
想要评论请 注册