What is the best way to download file from url. I try to use DownloadManager. But I cannot understand how to get Uri of downloaded file . Here is my code:
file?.let {
val uri = Uri.parse(it)
val downloadManager = getSystemService<Any>(Context.DOWNLOAD_SERVICE) as DownloadManager?
val request = DownloadManager.Request(uri)
request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI or
DownloadManager.Request.NETWORK_MOBILE)
request.allowScanningByMediaScanner()
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED)
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "downloadfileName")
request.setMimeType("*/*")
downloadManager?.enqueue(request)
}
Perhaps today there is a better way to download the file and get it Uri. Please help me