title: Getting Permission Denial Exception
body: <p>I have an activity in my app that allows the user to select several files from the device one by one, I am using an intent like this:</p>
  
  <pre><code>Intent intent = new Intent();
  intent.setType("*/*");
  intent.setAction(Intent.ACTION_GET_CONTENT);
  startActivityForResult(Intent.createChooser(intent, getString(R.string.select_attachments_activity_chooser_label)), SELECT_PICTURE);
  </code></pre>
  
  <p>This is working perfectly fine, I am getting the Uri's of the files selected, they look like this:</p>
  
  <pre><code>content://com.android.providers.media.documents/document/image%3A42555
  </code></pre>
  
  <p>Then, if the file is an image, I am decoding it with:</p>
  
  <pre><code>InputStream streamForDecodeBitmap = MyApp.getContext().getContentResolver().openInputStream(uri);
  Bitmap bitmap = BitmapFactory.decodeStream(streamForDecodeBitmap, null, options);
  </code></pre>
  
  <p>When the user clicks a button, I pass the list of Uris to another activity via intent and in this activity, in an AsyncTask, I am encoding the file in base64 for send it over the network:</p>
  
  <pre><code>InputStream is = MyApp.getContext().getContentResolver().openInputStream(uri);
  byte[] inputData = getBytes(is);
  is.close();
  return Base64.encodeToString(inputData, Base64.DEFAULT);
  </code></pre>
  
  <p>The problem is when I open the inputStream, sometimes it works but most of the times I am getting this exception:</p>
  
  <pre><code>E/AndroidRuntime(22270): Caused by: java.lang.SecurityException: Permission Denial: opening provider com.android.providers.media.MediaDocumentsProvider from ProcessRecord{42858fe0 22270:co.uk.manifesto.freeagentapp/u0a246} (pid=22270, uid=10246) requires android.permission.MANAGE_DOCUMENTS or android.permission.MANAGE_DOCUMENTS
  </code></pre>
  
  <p>These are all the permissions in my manifest:</p>
  
  <pre><code>&lt;uses-permission android:name="android.permission.INTERNET" /&gt;
  &lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /&gt;
  &lt;uses-permission android:name="android.permission.GET_TASKS" /&gt;
  &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/&gt;
  &lt;uses-permission android:name="android.permission.MANAGE_DOCUMENTS"/&gt;
  </code></pre>
  
  <p>I am testing in a device with KITKAT (API 19).</p>