title: How do I check the permission of an URI that has been send with an intent?
body: <p>I have tried the following but this always returns PackageManager.PERMISSION_DENIED although I
  know that I have the right to read the file. Any ideas?</p>
  
  <pre><code>Uri uri = (Uri) intent.getExtras().get(Intent.EXTRA_STREAM);
  
  // check uri permissions but does not work
  int perm = checkUriPermission(uri , "r", null,
          Binder.getCallingPid(), Binder.getCallingUid(),
          Intent.FLAG_GRANT_READ_URI_PERMISSION);
  if (perm == PackageManager.PERMISSION_DENIED) {
      Toast.makeText(getApplicationContext(),
      "No permissions to read the file", Toast.LENGTH_LONG).show();
      finish();
  }
  </code></pre>