title: How to download file from URL in android?
body: <p>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:</p>
  <pre><code>   file?.let {
              val uri = Uri.parse(it)
              val downloadManager = getSystemService&lt;Any&gt;(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, &quot;downloadfileName&quot;)
              request.setMimeType(&quot;*/*&quot;)
              downloadManager?.enqueue(request)
          }
  </code></pre>
  <p>Perhaps today there is a better way to download the file and get it Uri. Please help me</p>