Continue supporting old APIs.
This commit is contained in:
parent
190fbb95ec
commit
667b371653
|
@ -16,8 +16,10 @@
|
|||
|
||||
package im.vector.riotx.core.files
|
||||
|
||||
import android.app.DownloadManager
|
||||
import android.content.ContentValues
|
||||
import android.content.Context
|
||||
import android.os.Build
|
||||
import android.provider.MediaStore
|
||||
import androidx.annotation.WorkerThread
|
||||
import arrow.core.Try
|
||||
|
@ -56,6 +58,7 @@ fun addEntryToDownloadManager(context: Context,
|
|||
title: String = file.name,
|
||||
description: String = file.name) {
|
||||
try {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||
val contentValues = ContentValues().apply {
|
||||
put(MediaStore.Downloads.TITLE, title)
|
||||
put(MediaStore.Downloads.DISPLAY_NAME, description)
|
||||
|
@ -67,6 +70,11 @@ fun addEntryToDownloadManager(context: Context,
|
|||
outputStream.sink().buffer().write(file.inputStream().use { it.readBytes() })
|
||||
}
|
||||
}
|
||||
} else {
|
||||
val downloadManager = context.getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager?
|
||||
@Suppress("DEPRECATION")
|
||||
downloadManager?.addCompletedDownload(title, description, true, mimeType, file.absolutePath, file.length(), true)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Timber.e(e, "## addEntryToDownloadManager(): Exception")
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue