Fix SettingsScreen auto-install after download

This commit is contained in:
sanjeok77
2026-03-07 07:21:01 +09:00
parent 34889742c9
commit 99ae871d53
4 changed files with 1170 additions and 11 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 213 KiB

View File

@@ -45,6 +45,7 @@ import com.hotdeal.alarm.presentation.components.PermissionDialog
import com.hotdeal.alarm.presentation.main.MainUiState
import com.hotdeal.alarm.presentation.main.MainViewModel
import com.hotdeal.alarm.ui.theme.getSiteColor
import com.hotdeal.alarm.util.ApkDownloadManager
import com.hotdeal.alarm.util.PermissionHelper
import com.hotdeal.alarm.util.VersionManager
import kotlinx.coroutines.launch
@@ -477,17 +478,20 @@ private fun MoreTab(viewModel: MainViewModel) {
}
private fun downloadAndInstallApk(context: Context, updateInfo: com.hotdeal.alarm.util.UpdateInfo) {
val downloadManager = context.getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager
val request = DownloadManager.Request(Uri.parse(updateInfo.updateUrl))
.setTitle("핫딜 알람 업데이트")
.setDescription("버전 ${updateInfo.version} 다운로드 중...")
.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED)
.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "hotdeal_alarm_${updateInfo.version}.apk")
.setAllowedOverMetered(true)
.setAllowedOverRoaming(true)
downloadManager.enqueue(request)
Toast.makeText(context, "다운로드가 시작되었습니다", Toast.LENGTH_SHORT).show()
// ApkDownloadManager를 사용하여 다운로드 시작 및 자동 설치
val downloadId = ApkDownloadManager.downloadApk(context, updateInfo)
// 다운로드 완료 리시버 등록 - 완료 시 자동 설치
ApkDownloadManager.registerDownloadCompleteReceiver(
context = context,
downloadId = downloadId,
onComplete = {
ApkDownloadManager.installApk(context)
},
onFailed = {
Toast.makeText(context, "다운로드 실패. 다시 시도해주세요.", Toast.LENGTH_SHORT).show()
}
)
}
// ==================== 공통 컴포넌트 ====================

1155
index.html Normal file

File diff suppressed because it is too large Load Diff

BIN
index.html:Zone.Identifier Normal file

Binary file not shown.