From 207f8656ddfaf6267269919fa77798869680971d Mon Sep 17 00:00:00 2001 From: Damontecres Date: Sun, 12 Oct 2025 21:12:18 -0400 Subject: [PATCH] Updater fixes --- app/src/main/AndroidManifest.xml | 10 ++++++ .../damontecres/dolphin/util/UpdateChecker.kt | 36 +++++++++++++------ 2 files changed, 36 insertions(+), 10 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 741efb5b..20ae77cf 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -41,6 +41,16 @@ + + + + diff --git a/app/src/main/java/com/github/damontecres/dolphin/util/UpdateChecker.kt b/app/src/main/java/com/github/damontecres/dolphin/util/UpdateChecker.kt index 7fc35045..339d3b2a 100644 --- a/app/src/main/java/com/github/damontecres/dolphin/util/UpdateChecker.kt +++ b/app/src/main/java/com/github/damontecres/dolphin/util/UpdateChecker.kt @@ -31,6 +31,7 @@ import kotlinx.serialization.json.jsonObject import kotlinx.serialization.json.jsonPrimitive import okhttp3.OkHttpClient import okhttp3.Request +import okhttp3.Response import timber.log.Timber import java.io.File import java.util.Date @@ -212,8 +213,18 @@ class UpdateChecker intent.data = uri context.startActivity(intent) } else { - Timber.e("Resolver URI is null") - // TODO show error Toast + Timber.e("Resolver URI is null, trying fallback") +// showToast(context, "Unable to download the apk") + val targetFile = fallbackDownload(it) + val intent = Intent(Intent.ACTION_INSTALL_PACKAGE) + intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) + intent.data = + FileProvider.getUriForFile( + activity, + activity.packageName + ".provider", + targetFile, + ) + activity.startActivity(intent) } } else { if (ContextCompat.checkSelfPermission( @@ -234,13 +245,7 @@ class UpdateChecker PERMISSION_REQUEST_CODE, ) } else { - val downloadDir = - Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) - downloadDir.mkdirs() - val targetFile = File(downloadDir, ASSET_NAME) - targetFile.outputStream().use { output -> - it.body!!.byteStream().copyTo(output) - } + val targetFile = fallbackDownload(it) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { val intent = Intent(Intent.ACTION_INSTALL_PACKAGE) intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) @@ -261,12 +266,23 @@ class UpdateChecker } } else { Timber.v("Request failed for ${release.downloadUrl}: ${it.code}") - // TODO show error toast + showToast(context, "Error downloading the apk: ${it.code}") } } } } + private fun fallbackDownload(response: Response): File { + val downloadDir = + Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) + downloadDir.mkdirs() + val targetFile = File(downloadDir, ASSET_NAME) + targetFile.outputStream().use { output -> + response.body!!.byteStream().copyTo(output) + } + return targetFile + } + /** * Delete previously downloaded APKs */