From ea904008717a4f8c7410860f3e78e36d78060797 Mon Sep 17 00:00:00 2001 From: taohebin Date: Sun, 28 Apr 2024 18:27:54 +0800 Subject: [PATCH] =?UTF-8?q?update=EF=BC=9A=20install-apk?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- uni_modules/uni-installApk/changelog.md | 2 ++ uni_modules/uni-installApk/package.json | 5 ++-- .../utssdk/app-android/index.uts | 25 +++++++++++++++---- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/uni_modules/uni-installApk/changelog.md b/uni_modules/uni-installApk/changelog.md index d67eb70..774de0e 100644 --- a/uni_modules/uni-installApk/changelog.md +++ b/uni_modules/uni-installApk/changelog.md @@ -1,3 +1,5 @@ +## 1.0.5(2024-04-28) +解决Android API 24版本以下设备,安装apk失败的问题。 ## 1.0.4(2023-12-08) 兼容asset目录文件的处理 ## 1.0.3(2023-10-27) diff --git a/uni_modules/uni-installApk/package.json b/uni_modules/uni-installApk/package.json index 2270fe2..fb1195a 100644 --- a/uni_modules/uni-installApk/package.json +++ b/uni_modules/uni-installApk/package.json @@ -1,7 +1,7 @@ { "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": { diff --git a/uni_modules/uni-installApk/utssdk/app-android/index.uts b/uni_modules/uni-installApk/utssdk/app-android/index.uts index 64e7b6b..2803a54 100644 --- a/uni_modules/uni-installApk/utssdk/app-android/index.uts +++ b/uni_modules/uni-installApk/utssdk/app-android/index.uts @@ -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) { + } +} -- GitLab