title: Permission Denial with File Provider through intent
body: <p>I am attempting send a bitmap from the cache directory of my app to the text messaging app. I am using file provider to grant temporary permission to the application that handles the intent. When I try to send the intent and I select the default android text messaging app from the intent chooser my message app crashes and I get this error. I tried selecting other applications from the intent chooser such as email and other messaging apps and it seemed to work fine, only crashes with the default text messaging app.</p>
  
  <pre><code>java.lang.SecurityException: Permission Denial: reading android.support.v4.content.FileProvider uri content://com.example.brandon.emojimms2/shared_images/image.png from pid=9804, uid=10024 requires the provider be exported, or grantUriPermission()
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/Sv47g.png" rel="noreferrer"><img src="https://i.stack.imgur.com/Sv47g.png" alt="Permission Denial"></a>
  Here is the code where I share the intent</p>
  
  <pre><code>private void shareImage()
  {
      File imagePath = new File(mContext.getCacheDir(), "images");
      File newFile = new File(imagePath, "image.png");
      Uri contentUri = FileProvider.getUriForFile(mContext, "com.example.brandon.emojimms2", newFile);
  
      if (contentUri != null) {
          Intent shareIntent = new Intent();
          shareIntent.setAction(Intent.ACTION_SEND);
          shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); // temp permission for receiving app to read this file
          shareIntent.setDataAndType(contentUri, mContext.getContentResolver().getType(contentUri));
          shareIntent.putExtra(Intent.EXTRA_STREAM, contentUri);
          startActivity(Intent.createChooser(shareIntent, "Choose an app"));
      }
  }
  </code></pre>
  
  <p>I am fairly certain I set up the File provider correctly, but here is the manifest in case it is needed. <a href="https://i.stack.imgur.com/iq9yX.png" rel="noreferrer"><img src="https://i.stack.imgur.com/iq9yX.png" alt="enter image description here"></a></p>
  
  <p>Edit: I just did some testing and it seems that the crash with the text messaging app is happening on phones on earlier apis, but is working on new apis such as 7.1. Did either the text messaging app or with the way you were supposed to grant uri read permissions change?</p>