title: FileProvider is unable to attach file to email client on Android 11
body: <p>I used to attach a logs file, that I was storing in externalCacheDir, to a mail client.
  Using this : <code>intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(logFile))</code></p>
  <p>However, starting from Android 11 it just stopped working. So I tried using FileProvider. But once the mail client opens it says &quot;Couldn't attach file&quot;.</p>
  <p>I have tried doing everything I could find here on SO and on the internet in general. But I can't seem to find the solution that will actually work.</p>
  <p>Activity :</p>
  <pre><code>val logFile: File = File(globalContext.externalCacheDir, &quot;MyLogFile.log&quot;)
  
  fun Activity.openMail(
      type: String = &quot;text/plain&quot;
  ): Boolean {
      val intent = Intent(Intent.ACTION_SENDTO)
      intent.putExtra(Intent.EXTRA_EMAIL, arrayOf(&quot;&lt;some address...&gt;&quot;))
      intent.putExtra(Intent.EXTRA_SUBJECT, &quot;Android Logs&quot;)
      intent.putExtra(Intent.EXTRA_TEXT, &quot;some text&quot;)
  
  
      val uri = FileProvider.getUriForFile(this, &quot;${BuildConfig.APPLICATION_ID}.fileprovider&quot;, logFile)
      intent.putExtra(Intent.EXTRA_STREAM, uri)
  
      intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
      intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION)
      intent.type = type
      intent.data = Uri.parse(&quot;mailto:&quot;)
  
      if (intent.resolveActivity(packageManager) != null) {
          startActivity(Intent.createChooser(intent, &quot;Send email via::&quot;))
          return true
      } else {
          return false
      }
  }
  </code></pre>
  <p>Manifest :</p>
  <pre><code>&lt;uses-permission android:name=&quot;android.permission.WRITE_EXTERNAL_STORAGE&quot; /&gt;
  &lt;uses-permission android:name=&quot;android.permission.READ_EXTERNAL_STORAGE&quot; /&gt;
  
  &lt;provider
      android:name=&quot;androidx.core.content.FileProvider&quot;
      android:authorities=&quot;${applicationId}.fileprovider&quot;
      android:exported=&quot;false&quot;
      android:grantUriPermissions=&quot;true&quot;&gt;
          &lt;meta-data
              android:name=&quot;android.support.FILE_PROVIDER_PATHS&quot;
              android:resource=&quot;@xml/provider_paths&quot; /&gt;
  &lt;/provider&gt;
  </code></pre>
  <p>provider_paths :</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;paths&gt;
      &lt;external-cache-path name=&quot;external_cache&quot; path=&quot;.&quot;/&gt;
  &lt;/paths&gt;
  </code></pre>