title: Permission denied : opening provider com.google.android.apps.photos.contentprovider.MediaContentProvider that is not exported from uid
body: <p>My app is crashing only in android >= 6.0 (marshmallow) when I try to access a photo URI stored previously in SharedPreferences. Though the image is retrieved for the first time without any error. I am using <code>targetSdkVersion</code> 22 so that I don't need to handle run-time permissions in API >=23. </p>
  
  <p>Permissions in my Manifest file </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.RECEIVE_SMS" /&gt;
  &lt;uses-permission android:name="android.permission.READ_SMS" /&gt;
  &lt;uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" /&gt;
  &lt;uses-permission android:name="android.permission.RECORD_AUDIO" /&gt;
  &lt;uses-permission android:name="android.permission.CAPTURE_AUDIO_OUTPUT" /&gt;
  &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /&gt;
  &lt;uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /&gt;
  &lt;uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" /&gt;
  &lt;uses-permission android:name="android.permission.WRITE_CONTACTS" /&gt;
  &lt;uses-permission android:name="android.permission.MANAGE_DOCUMENTS" /&gt;
  </code></pre>
  
  <p>I am getting image as follows : </p>
  
  <pre><code> // Determine Uri of camera image to save.
      final File root = new File(Environment.getExternalStorageDirectory() + File.separator + "pics" + File.separator);
      root.mkdirs();
      final String fname = Calendar.getInstance().getTimeInMillis() + ".jpg";
      final File sdImageMainDirectory = new File(root, fname);
      outputFileUri = Uri.fromFile(sdImageMainDirectory);
  
      // Camera.
      final List&lt;Intent&gt; cameraIntents = new ArrayList&lt;Intent&gt;();
      final Intent captureIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
      final PackageManager packageManager = getPackageManager();
      final List&lt;ResolveInfo&gt; listCam = packageManager.queryIntentActivities(captureIntent, 0);
      for (ResolveInfo res : listCam) {
          final String packageName = res.activityInfo.packageName;
          final Intent intent = new Intent(captureIntent);
          intent.setComponent(new ComponentName(res.activityInfo.packageName, res.activityInfo.name));
          intent.setPackage(packageName);
          intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
          cameraIntents.add(intent);
      }
  
      // Filesystem.
      Intent galleryIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
  
      // Chooser of filesystem options.
      final Intent chooserIntent = Intent.createChooser(galleryIntent, "Select Source");
  
      // Add the camera options.
      chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, cameraIntents.toArray(new Parcelable[cameraIntents.size()]));
      startActivityForResult(chooserIntent, Constants.IMAGE_PICKER);
  </code></pre>
  
  <p>This is my OnActivityResult method: </p>
  
  <pre><code>@Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
      if (resultCode == RESULT_OK) {
          if (requestCode == Constants.IMAGE_PICKER) {
              if (data == null) {
                  selectedImageUri = outputFileUri;
              } else {
                  selectedImageUri = data.getData();
              }
              if (selectedImageUri != null) {
                  try {
                      String path = AppUtils.getPath(this, selectedImageUri);
                      if (path != null) {
                          Bitmap bitmap = AppUtils.decodeFile(new File(path));
                          File f = new File(System.currentTimeMillis() + ".jpg");
                          OutputStream os = new BufferedOutputStream(new FileOutputStream(f));
                          bitmap.compress(Bitmap.CompressFormat.JPEG, 100, os);
                          os.close();
                          uploadImageToServer(f, bitmap);
                      }
                  } catch (Exception e) {
                      e.printStackTrace();
                  }
              }
          }
      }
  }
  </code></pre>
  
  <p>where getPath() is function from <a href="https://stackoverflow.com/a/20559418/3758972">https://stackoverflow.com/a/20559418/3758972</a>.</p>
  
  <p>stacktrace : </p>
  
  <pre><code>java.lang.RuntimeException: Unable to start activity ComponentInfo{com.badiyajobs.app/com.badiyajobs.app.screens.ProfileActivity}: java.lang.SecurityException: Permission Denial: opening provider com.google.android.apps.photos.contentprovider.MediaContentProvider from ProcessRecord{25e87b7 20432:com.badiyajobs.app/u0a389} (pid=20432, uid=10389) that is not exported from uid 10107
                                                                      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2426)
                                                                      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2490)
                                                                      at android.app.ActivityThread.access$900(ActivityThread.java:154)
                                                                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1354)
                                                                      at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                      at android.os.Looper.loop(Looper.java:148)
                                                                      at android.app.ActivityThread.main(ActivityThread.java:5443)
                                                                      at java.lang.reflect.Method.invoke(Native Method)
                                                                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
                                                                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
                                                                   Caused by: java.lang.SecurityException: Permission Denial: opening provider com.google.android.apps.photos.contentprovider.MediaContentProvider from ProcessRecord{25e87b7 20432:com.badiyajobs.app/u0a389} (pid=20432, uid=10389) that is not exported from uid 10107
                                                                      at android.os.Parcel.readException(Parcel.java:1620)
                                                                      at android.os.Parcel.readException(Parcel.java:1573)
                                                                      at android.app.ActivityManagerProxy.getContentProvider(ActivityManagerNative.java:3605)
                                                                      at android.app.ActivityThread.acquireProvider(ActivityThread.java:4799)
                                                                      at android.app.ContextImpl$ApplicationContentResolver.acquireUnstableProvider(ContextImpl.java:2018)
                                                                      at android.content.ContentResolver.acquireUnstableProvider(ContentResolver.java:1466)
                                                                      at android.content.ContentResolver.query(ContentResolver.java:475)
                                                                      at android.content.ContentResolver.query(ContentResolver.java:434)
                                                                      at com.badiyajobs.app.utils.AppUtils.getDataColumn(AppUtils.java:790)
                                                                      at com.badiyajobs.app.utils.AppUtils.getPath(AppUtils.java:776)
                                                                      at com.badiyajobs.app.screens.ProfileActivity.setDefaultValue(ProfileActivity.java:192)
                                                                      at com.badiyajobs.app.screens.ProfileActivity.onCreate(ProfileActivity.java:162)
                                                                      at android.app.Activity.performCreate(Activity.java:6259)
                                                                      at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1130)
                                                                      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2379)
                                                                      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2490) 
                                                                      at android.app.ActivityThread.access$900(ActivityThread.java:154) 
                                                                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1354) 
                                                                      at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                      at android.os.Looper.loop(Looper.java:148) 
                                                                      at android.app.ActivityThread.main(ActivityThread.java:5443) 
                                                                      at java.lang.reflect.Method.invoke(Native Method) 
                                                                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728) 
                                                                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618) 
  </code></pre>
  
  <p>I don't know what am I missing. Please help.</p>