title: How to download a file when a button inside a RecyclerView is pressed?
body: <p>I'm creating an app where there's a button that when pressed, it will start a download of a file. The button is on a <code>RecyclerView</code> and I'm using the stock Android Download Manager. </p>
  
  <p>I tried to do a <code>setOnClickListener</code> on that button inside the <code>onBindViewHolder</code> on my Recycler View adaptor and include the contents of the function inside it:</p>
  
  <pre><code>holder.button.setOnClickListener {
      val request = DownloadManager.Request(Uri.parse(downloadurl))
      request.setTitle("$downloadname.apk")
      request.setDescription("Download")
      request.setVisibleInDownloadsUi(true)
      request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS)
      request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED)
      val manager = getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager
      manager.enqueue(request)
  }
  </code></pre>
  
  <p>but in the <code>getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager</code> says me that I need a <code>Context</code> and not a <code>String</code>.</p>
  
  <p>Then I tried to create an object that has a download function but it gives me the same error as the function.</p>
  
  <p>How can I make that work in the object or the <code>setOnClickListener</code>?</p>