fix(mobile): use external storage for APK download and close app on install
- Change download path from getApplicationDocumentsDirectory to getExternalStorageDirectory for proper FileProvider support - Add finishAffinity() after starting APK install intent 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
fea90b7616
commit
88c59e92fd
|
|
@ -81,5 +81,8 @@ class MainActivity : FlutterActivity() {
|
|||
|
||||
intent.setDataAndType(apkUri, "application/vnd.android.package-archive")
|
||||
startActivity(intent)
|
||||
|
||||
// 关闭当前应用,让系统完成安装
|
||||
finishAffinity()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,8 +48,8 @@ class DownloadManager {
|
|||
_status = DownloadStatus.downloading;
|
||||
_cancelToken = CancelToken();
|
||||
|
||||
// 使用应用专属目录(无需额外权限)
|
||||
final dir = await getApplicationDocumentsDirectory();
|
||||
// 使用外部缓存目录(FileProvider 标准支持路径)
|
||||
final dir = await getExternalStorageDirectory() ?? await getApplicationSupportDirectory();
|
||||
final savePath = '${dir.path}/app_update.apk';
|
||||
final tempPath = '${dir.path}/app_update.apk.tmp';
|
||||
final file = File(savePath);
|
||||
|
|
@ -186,7 +186,7 @@ class DownloadManager {
|
|||
/// 删除已下载的 APK 文件和临时文件
|
||||
Future<void> cleanupDownloadedApk() async {
|
||||
try {
|
||||
final dir = await getApplicationDocumentsDirectory();
|
||||
final dir = await getExternalStorageDirectory() ?? await getApplicationSupportDirectory();
|
||||
final file = File('${dir.path}/app_update.apk');
|
||||
final tempFile = File('${dir.path}/app_update.apk.tmp');
|
||||
|
||||
|
|
@ -206,7 +206,7 @@ class DownloadManager {
|
|||
/// 清除断点续传的临时文件(用于强制重新下载)
|
||||
Future<void> clearPartialDownload() async {
|
||||
try {
|
||||
final dir = await getApplicationDocumentsDirectory();
|
||||
final dir = await getExternalStorageDirectory() ?? await getApplicationSupportDirectory();
|
||||
final tempFile = File('${dir.path}/app_update.apk.tmp');
|
||||
if (await tempFile.exists()) {
|
||||
await tempFile.delete();
|
||||
|
|
|
|||
Loading…
Reference in New Issue