mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-11-19 23:49:16 +01:00
use explicit file url instead of download manager's content url (#2859)
This commit is contained in:
parent
92fa8d683a
commit
a1df78517f
@ -6,7 +6,7 @@ import android.content.Context
|
|||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.IntentFilter
|
import android.content.IntentFilter
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.Build
|
import android.os.Environment
|
||||||
import com.jakewharton.rxrelay.PublishRelay
|
import com.jakewharton.rxrelay.PublishRelay
|
||||||
import eu.kanade.tachiyomi.extension.model.Extension
|
import eu.kanade.tachiyomi.extension.model.Extension
|
||||||
import eu.kanade.tachiyomi.extension.model.InstallStep
|
import eu.kanade.tachiyomi.extension.model.InstallStep
|
||||||
@ -63,9 +63,11 @@ internal class ExtensionInstaller(private val context: Context) {
|
|||||||
// Register the receiver after removing (and unregistering) the previous download
|
// Register the receiver after removing (and unregistering) the previous download
|
||||||
downloadReceiver.register()
|
downloadReceiver.register()
|
||||||
|
|
||||||
val request = DownloadManager.Request(Uri.parse(url))
|
val downloadUri = Uri.parse(url)
|
||||||
|
val request = DownloadManager.Request(downloadUri)
|
||||||
.setTitle(extension.name)
|
.setTitle(extension.name)
|
||||||
.setMimeType(APK_MIME)
|
.setMimeType(APK_MIME)
|
||||||
|
.setDestinationInExternalFilesDir(context, Environment.DIRECTORY_DOWNLOADS, downloadUri.lastPathSegment)
|
||||||
.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED)
|
.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED)
|
||||||
|
|
||||||
val id = downloadManager.enqueue(request)
|
val id = downloadManager.enqueue(request)
|
||||||
@ -221,20 +223,15 @@ internal class ExtensionInstaller(private val context: Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Due to a bug in Android versions prior to N, the installer can't open files that do
|
val query = DownloadManager.Query().setFilterById(id)
|
||||||
// not contain the extension in the path, even if you specify the correct MIME.
|
downloadManager.query(query).use { cursor ->
|
||||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
|
if (cursor.moveToFirst()) {
|
||||||
val query = DownloadManager.Query().setFilterById(id)
|
val localUri = cursor.getString(
|
||||||
downloadManager.query(query).use { cursor ->
|
cursor.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI)
|
||||||
if (cursor.moveToFirst()) {
|
).removePrefix(FILE_SCHEME)
|
||||||
@Suppress("DEPRECATION")
|
|
||||||
val uriCompat = File(cursor.getString(cursor.getColumnIndex(
|
installApk(id, File(localUri).getUriCompat(context))
|
||||||
DownloadManager.COLUMN_LOCAL_FILENAME))).getUriCompat(context)
|
|
||||||
installApk(id, uriCompat)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
installApk(id, uri)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -242,5 +239,6 @@ internal class ExtensionInstaller(private val context: Context) {
|
|||||||
companion object {
|
companion object {
|
||||||
const val APK_MIME = "application/vnd.android.package-archive"
|
const val APK_MIME = "application/vnd.android.package-archive"
|
||||||
const val EXTRA_DOWNLOAD_ID = "ExtensionInstaller.extra.DOWNLOAD_ID"
|
const val EXTRA_DOWNLOAD_ID = "ExtensionInstaller.extra.DOWNLOAD_ID"
|
||||||
|
const val FILE_SCHEME = "file://"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user