title: Android - file provider - permission denial
body: <p>I have two apps : app1 and app2.</p>
  
  <p>App2 has :</p>
  
  <pre><code>&lt;provider
          android:name="android.support.v4.content.FileProvider"
          android:authorities="com.android.provider.ImageSharing"
          android:exported="false"
          android:grantUriPermissions="true" &gt;
          &lt;meta-data
              android:name="android.support.FILE_PROVIDER_PATHS"
              android:resource="@xml/paths" /&gt;
  &lt;/provider&gt;
  </code></pre>
  
  <p>paths.xml :</p>
  
  <pre><code>&lt;paths&gt;
  
       &lt;files-path name="my_images" path="images/"/&gt;
  
  &lt;/paths&gt;
  </code></pre>
  
  <p>App2 receives request in its Activity from App1 to get URI for an image. The App2 Activity does the following once URI is decided :</p>
  
  <pre><code>Intent intent = new Intent();
  
  intent.setDataAndType(contentUri, getContentResolver().getType(contentUri));
  
  int uid = Binder.getCallingUid();
  String callingPackage = getPackageManager().getNameForUid(uid);
  
  getApplicationContext().grantUriPermission(callingPackage, contentUri,
                      Intent.FLAG_GRANT_READ_URI_PERMISSION);
  
  setResult(Activity.RESULT_OK, intent);
  finish();
  </code></pre>
  
  <p>On receiving the result back from App2, App1 does the following :</p>
  
  <pre><code>Uri imageUri = data.getData();
  if(imageUri != null) {
      ImageView iv = (ImageView) layoutView.findViewById(R.id.imageReceived);
      iv.setImageURI(imageUri);
  }
  </code></pre>
  
  <p>In App1, on returning from App2, I get the following exception :</p>
  
  <blockquote>
    <p>java.lang.SecurityException: Permission Denial: opening 
    provider android.support.v4.content.FileProvider from 
    ProcessRecord{52a99eb0 3493:com.android.App1.app/u0a57} 
    (pid=3493, uid=10057) that is not exported from uid 10058</p>
  </blockquote>
  
  <p>What am I doing wrong ?</p>