diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index b665da264..ff15dabe3 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -19,6 +19,7 @@
+
@@ -319,6 +320,13 @@
android:name="android.appwidget.provider"
android:resource="@xml/widget_recent" />
+
+
+
+
+
- val intent = Intent(Intent.ACTION_VIEW, version.apkUrl.toUri())
+ .setNeutralButton(R.string.open_in_browser) { _, _ ->
+ val intent = Intent(Intent.ACTION_VIEW, version.url.toUri())
context.startActivity(Intent.createChooser(intent, context.getString(R.string.open_in_browser)))
- }
- .setNegativeButton(R.string.close, null)
+ }.setPositiveButton(R.string.update) { _, _ ->
+ downloadUpdate(version)
+ }.setNegativeButton(android.R.string.cancel, null)
.setCancelable(false)
.create()
.show()
}
+
+ private fun downloadUpdate(version: AppVersion) {
+ val url = version.apkUrl.toUri()
+ val dm = context.getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager
+ val request = DownloadManager.Request(url)
+ .setTitle("${context.getString(R.string.app_name)} v${version.name}")
+ .setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, url.lastPathSegment)
+ .setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED)
+ .setMimeType("application/vnd.android.package-archive")
+ dm.enqueue(request)
+ Toast.makeText(context, R.string.download_started, Toast.LENGTH_SHORT).show()
+ }
}
diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/settings/about/UpdateDownloadReceiver.kt b/app/src/main/kotlin/org/koitharu/kotatsu/settings/about/UpdateDownloadReceiver.kt
new file mode 100644
index 000000000..bb2b8e9c9
--- /dev/null
+++ b/app/src/main/kotlin/org/koitharu/kotatsu/settings/about/UpdateDownloadReceiver.kt
@@ -0,0 +1,38 @@
+package org.koitharu.kotatsu.settings.about
+
+import android.app.DownloadManager
+import android.content.ActivityNotFoundException
+import android.content.BroadcastReceiver
+import android.content.Context
+import android.content.Intent
+import org.koitharu.kotatsu.core.util.ext.printStackTraceDebug
+
+
+class UpdateDownloadReceiver : BroadcastReceiver() {
+
+ override fun onReceive(context: Context, intent: Intent) {
+ when (intent.action) {
+ DownloadManager.ACTION_DOWNLOAD_COMPLETE -> {
+ val downloadId = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, 0L)
+ if (downloadId == 0L) {
+ return
+ }
+ val dm = context.getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager
+
+ @Suppress("DEPRECATION")
+ val installIntent = Intent(Intent.ACTION_INSTALL_PACKAGE)
+ installIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_GRANT_READ_URI_PERMISSION)
+ installIntent.setDataAndType(
+ dm.getUriForDownloadedFile(downloadId),
+ dm.getMimeTypeForDownloadedFile(downloadId),
+ )
+ installIntent.putExtra(Intent.EXTRA_NOT_UNKNOWN_SOURCE, true)
+ try {
+ context.startActivity(installIntent)
+ } catch (e: ActivityNotFoundException) {
+ e.printStackTraceDebug()
+ }
+ }
+ }
+ }
+}