Files
svxhomyak/app/src/main/java/ru/ua1zbe/svxremote/UpdateFileProvider.kt
ua1zbe 1a9dd9a5a4 Add in-app update checker via Gitea API (v1.0.2)
- Check latest release on startup, show 'update available' dialog with
  Update/ Later buttons
- Download APK with progress and install via ACTION_VIEW + custom
  UpdateFileProvider (no androidx)
- Request unknown-app-sources permission if needed, resume download on
  return to the app
2026-08-14 08:54:17 +03:00

34 lines
1.4 KiB
Kotlin

package ru.ua1zbe.svxremote
import android.content.ContentProvider
import android.content.ContentValues
import android.database.Cursor
import android.net.Uri
import android.os.ParcelFileDescriptor
import java.io.File
/** Минимальный FileProvider для установки APK (без androidx). */
class UpdateFileProvider : ContentProvider() {
override fun onCreate(): Boolean = true
override fun openFile(uri: Uri, mode: String): ParcelFileDescriptor {
val name = uri.lastPathSegment
?: throw IllegalArgumentException("bad uri")
if (name != name.substringAfterLast('/')) {
throw IllegalArgumentException("bad uri")
}
val path = File(context?.cacheDir, "updates/$name")
return ParcelFileDescriptor.open(path, ParcelFileDescriptor.MODE_READ_ONLY)
}
override fun getType(uri: Uri): String = "application/vnd.android.package-archive"
override fun insert(uri: Uri, values: ContentValues?): Uri? = null
override fun delete(uri: Uri, selection: String?, selectionArgs: Array<out String>?): Int = 0
override fun query(
uri: Uri, projection: Array<out String>?, selection: String?,
selectionArgs: Array<out String>?, sortOrder: String?
): Cursor? = null
override fun update(uri: Uri, values: ContentValues?, selection: String?, selectionArgs: Array<out String>?): Int = 0
}