title: SecurityException with grantUriPermission when sharing a file with FileProvider
body: <p>I have two applications.  I'm trying to share a file from application A to application B using a FileProvider.  Application A calls the insert method on a ContentProvider in Application B to insert a record. The data inserted includes the Uri to the file I want to share from App A.  The ContentProvider in App B would then try to read the shared file from App A.
  Since I'm not using an Intent to share the file, I'm calling <code>Context.grantUriPermission</code> in App A to allow the read (and at times write):</p>
  
  <pre><code>mContext.grantUriPermission(MyPackageName, contentUri, Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
  </code></pre>
  
  <p>However, executing this line gives me (Names changed to protect the innocent):</p>
  
  <pre><code>java.lang.SecurityException: Uid 10066 does not have permission to uri content://au.com.example.AppA.fileprovider/MyFolder/MyFileName
  at android.os.Parcel.readException(Parcel.java:1322)
  at android.os.Parcel.readException(Parcel.java:1276)
  at android.app.ActivityManagerProxy.grantUriPermission(ActivityManagerNative.java:2374)
  at android.app.ContextImpl.grantUriPermission(ContextImpl.java:1371)
  at android.content.ContextWrapper.grantUriPermission(ContextWrapper.java:400)
  at etc...
  </code></pre>
  
  <p>App A has the following in the Manifest file:</p>
  
  <pre><code>&lt;provider
      android:name="android.support.v4.content.FileProvider"
      android:authorities="au.com.example.AppA.fileprovider"
      android:exported="false"
      android:grantUriPermissions="true"
      android:readPermission="au.com.example.READ_CONTENT"
      android:writePermission="au.com.example.WRITE_CONTENT" &gt;
      &lt;meta-data
          android:name="android.support.FILE_PROVIDER_PATHS"
          android:resource="@xml/filepaths" /&gt;
  &lt;/provider&gt;
  </code></pre>
  
  <p>filepaths.xml has:</p>
  
  <pre><code>&lt;paths&gt;
      &lt;files-path
          name="MyFolder"
          path="MyFolder/" /&gt;
  &lt;/paths&gt;
  </code></pre>
  
  <p>Both App A and App B have the following:</p>
  
  <pre><code>&lt;uses-permission android:name="au.com.example.READ_CONTENT" /&gt;
  &lt;uses-permission android:name="au.com.example.WRITE_CONTENT" /&gt;
  </code></pre>
  
  <p>I've tried defining the permissions in both apps. They are both signed with the same debug signature:</p>
  
  <pre><code>&lt;permission
      android:name="au.com.example.READ_CONTENT"
      android:permissionGroup="MyGroup"
      android:protectionLevel="signature" &gt;
  &lt;/permission&gt;
  &lt;permission
      android:name="au.com.example.WRITE_CONTENT"
      android:permissionGroup="MyGroup"
      android:protectionLevel="signature" &gt;
  &lt;/permission&gt;
  </code></pre>
  
  <p>The actual path the file ends up in is:</p>
  
  <pre><code>/data/data/au.com.example.AppA/files/MyFolder
  </code></pre>
  
  <p>At this point I'm stumped. I don't know why I can't grant permission for a file I just created within the same application.  So my questions are: Why am I getting this exception and how can I successfully grant permission to App B?</p>