diff --git a/uni_modules/uni-installApk/changelog.md b/uni_modules/uni-installApk/changelog.md index d67eb701ef976498949ebb5d5eec4b9531e0834e..774de0e520a45915a5e2b72bda9a5425d314ec31 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 2270fe2ab7e79516176a637fa9536ccfc1a60111..fb1195a2681a60f5bdcf707bcf90c2b524bd2767 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 64e7b6bdc7698fee1d7ddce32329aede1e619ed7..2803a54351eff0d965e08b5475e9ad83a37d4baf 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) { + } +}