title: Permission Denial: opening provider com.android.providers.media.MediaDocumentsProvider
body: <p>I am trying to allow the user to access his photo library to get a profile picture, and that save that profile picture to SharedPreferences. I also have a navbar that gets this picture from SharedPreferences</p>
  
  <p>I am getting the following error:</p>
  
  <pre><code>java.lang.SecurityException: 
  Permission Denial: opening provider com.android.providers.media.MediaDocumentsProvider from ProcessRecord
  {a601c1c 3379:com.example.foo.finalapp/u0a60} (pid=3379, uid=10060) requires android.permission.MANAGE_DOCUMENTS or android.permission.MANAGE_DOCUMENTS
  </code></pre>
  
  <p>Here is the code for getting the picture:</p>
  
  <p>MainActivity</p>
  
  <pre><code>       ImageView prof_pic = (ImageView) header.findViewById(R.id.profPic);
          pref = getSharedPreferences(Profile.pref_filename, 0);
          String uri = pref.getString("target_uri", "");
          TextView tv_name = (TextView) header.findViewById(R.id.tv_name);
          String name = pref.getString("name", "");
          if(!uri.equals("")) {
              Uri urii = Uri.parse(uri);
              try {
                  Bitmap bitmap = BitmapFactory.decodeStream(getContentResolver().openInputStream(urii));
                  tv_name.setText(name);
                  prof_pic.setImageBitmap(bitmap);
              } catch (FileNotFoundException e) {
  
              }
          }
          else {
              prof_pic.setImageResource(R.drawable.ic_android_black_24dp);
          }
      }
  
  profile_pic.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  /*
                  Intent intent = new Intent(Intent.ACTION_PICK,
                          android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
                  startActivityForResult(intent, 0);
                  */
                  Intent intent;
  
                  if (Build.VERSION.SDK_INT &lt; 19) {
                      intent = new Intent();
                      intent.setAction(Intent.ACTION_GET_CONTENT);
                      intent.setType("*/*");
                      startActivityForResult(intent, KITKAT_VALUE);
                  } else {
                      intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
                      intent.addCategory(Intent.CATEGORY_OPENABLE);
                      intent.setType("*/*");
                      startActivityForResult(intent, KITKAT_VALUE);
                  }
              }
          });
  
  @Override
      public void onActivityResult(int requestCode, int resultCode, Intent data) {
          super.onActivityResult(requestCode, resultCode, data);
          if (requestCode == KITKAT_VALUE) {
              if (resultCode == RESULT_OK) {
                  targetUri = data.getData();
                  //Bitmap bitmap;
                  try {
                      bitmap = BitmapFactory.decodeStream(getActivity().getContentResolver().openInputStream(targetUri));
                  /*
                  SharedPreferences.Editor edit = pref.edit();
                  edit.putString("target_uri", targetUri.toString());
                  edit.apply();
                  */
                      sTargetUri = targetUri.toString();
                      profile_pic.setImageBitmap(bitmap);
                  } catch (FileNotFoundException e) {
                      // TODO Auto-generated catch block
                      e.printStackTrace();
                  }
              }
          }
      }
  </code></pre>
  
  <p>Here is my manifest</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.finalapp"&gt;
  
      &lt;uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /&gt;
      &lt;uses-permission android:name="android.permission.MANAGE_DOCUMENTS" /&gt;
  
      &lt;application
          android:allowBackup="true"
          android:icon="@mipmap/ic_launcher"
          android:label="@string/app_name"
          android:supportsRtl="true"
          android:theme="@style/AppTheme"&gt;
          &lt;activity
              android:name=".MainActivity"
              android:label="@string/app_name"
              android:theme="@style/AppTheme.NoActionBar"&gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.MAIN" /&gt;
  
                  &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
          &lt;activity android:name=".JobViewActivity"&gt;&lt;/activity&gt;
      &lt;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>