title: How to use support FileProvider for sharing content to other apps?
body: <p>I'm looking for a way to correctly share (not OPEN) an internal file with external application using Android Support library's <a href="http://developer.android.com/reference/android/support/v4/content/FileProvider.html" rel="noreferrer">FileProvider</a>. </p>
  
  <p>Following the example on the docs,</p>
  
  <pre><code>&lt;provider
      android:name="android.support.v4.content.FileProvider"
      android:authorities="com.example.android.supportv4.my_files"
      android:grantUriPermissions="true"
      android:exported="false"&gt;
      &lt;meta-data
          android:name="android.support.FILE_PROVIDER_PATHS"
          android:resource="@xml/my_paths" /&gt;
  &lt;/provider&gt;
  </code></pre>
  
  <p>and using ShareCompat to share a file to other apps as follows:</p>
  
  <pre><code>ShareCompat.IntentBuilder.from(activity)
  .setStream(uri) // uri from FileProvider
  .setType("text/html")
  .getIntent()
  .addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
  </code></pre>
  
  <p>does not work, since the FLAG_GRANT_READ_URI_PERMISSION only grants permission for the Uri specified on the <code>data</code> of the intent, not the value of the <code>EXTRA_STREAM</code> extra (as was set by <code>setStream</code>).</p>
  
  <p>I tried to compromise security by setting <code>android:exported</code> to <code>true</code> for the provider, but <code>FileProvider</code> internally checks if itself is exported, when so, it throws an exception.</p>