title: Gmail error "Unable to attach file"
body: <p>I am trying to email PDF file using Gmail. However, Gmail app is showing toast:</p>
  
  <blockquote>
    <p>Unable to attach file</p>
  </blockquote>
  
  <p>PDF file is not-corrupt and is generated successfully in application's cache directory.</p>
  
  <p>Code: (<strong>Please comment below if you need code in Java.)</strong>:</p>
  
  <pre><code>    val photoURI: Uri = FileProvider.getUriForFile(this, "com.packagename.provider",
              File(this.cacheDir.path + "/Report.pdf"))
  
      val emailIntent = Intent(Intent.ACTION_SENDTO)
      emailIntent.data = Uri.parse("mailto:")
      emailIntent.putExtra(Intent.EXTRA_STREAM, photoURI)
      emailIntent.putExtra(Intent.EXTRA_EMAIL, arrayOf("some@domain.com"))
      emailIntent.putExtra(Intent.EXTRA_SUBJECT, "subject")
      emailIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
      emailIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION)
      startActivity(emailIntent)
  </code></pre>
  
  <p>Please help</p>