This commit is contained in:
fengge 2026-07-15 13:47:21 +08:00
parent f3e6aae9c3
commit a6cd238330
1 changed files with 5 additions and 3 deletions

View File

@ -34,11 +34,13 @@ class UpdateManager(private val context: Context) {
private val fileName = "StandApp_Update.apk"
/**
* 获取应用缓存目录下的临时文件 URI避免申请外部存储权限
* 获取应用外部专属下载目录下的文件 URI避免申请外部存储权限的同时确保安装包能被系统安装器读取
*/
private fun getCacheFileUri(): Uri {
val cacheDir = context.externalCacheDir ?: context.cacheDir
val file = File(cacheDir, fileName)
val dir = context.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS)
?: context.externalCacheDir
?: context.cacheDir
val file = File(dir, fileName)
if (file.exists()) {
file.delete()
}