title: Gallery Image File Exists but Bitmap decode file is null
body: <p>I'm trying to show an image picked from the gallery using the uri path returned by <code>OnActivityResult</code>.The file exists and it is either a <code>.png</code> or <code>.jpg</code> format but <code>Bitmap.decodeFile()</code> is always null or for some pictures(facebook messenger saved) it's showin an <code>Access denied error</code>. What am I doing wrong? </p>
  
  <p>I did read all of the related topics. </p>
  
  <p>I don't want to use the <code>openStream</code> method which was working, or the <code>imageView.setImageURI</code> option which was also working. </p>
  
  <p>Manifest: </p>
  
  <pre><code> &lt;uses-permission android:name="ANDROID.PERMISSION.WRITE_EXTERNAL_STORAGE"/&gt;
      &lt;uses-permission android:name="ANDROID.PERMISSION.READ_EXTERNAL_STORAGE"/&gt;
  </code></pre>
  
  <p>MainActivity onCreate:</p>
  
  <pre><code>// required by Android 6.0 +
          checkPermissions(getApplicationContext());
          FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
          fab.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {
  
                  Intent gallery =
                          new Intent(Intent.ACTION_PICK,
                                  android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI);
                  startActivityForResult(gallery, PICK_IMAGES);
              }
          });
  </code></pre>
  
  <p>MainActivity onActivitiyResult:</p>
  
  <pre><code>@Override
          public void onActivityResult(int requestCode, int resultCode, Intent data)
          {
              if (requestCode == PICK_IMAGES &amp;&amp; resultCode == RESULT_OK &amp;&amp; data != null) {
  
                  String imagePath = "";
                  Uri targetUri = data.getData();
                  if (data.toString().contains("content:")) {
                      imagePath = getRealPathFromURI(targetUri);
                  } else if (data.toString().contains("file:")) {
                      imagePath = targetUri.getPath();
                  } else {
                      imagePath = null;
                  }
  
                  ImageView imageView = (ImageView) findViewById(R.id.imageView);
  
                  Log.d("Image",imagePath);
  
                  File thePath = new File(imagePath);
  
                  if(thePath.exists()){
                      Log.d("Image", "exists");
                  }
  
                  Bitmap myBitmap = BitmapFactory.decodeFile(thePath.getAbsolutePath());
                  if(myBitmap == null)
                  Log.d("Image","bummer");
                  imageView.setImageBitmap(myBitmap);
  
              } else {
                  Log.d(TAG, "Something went wrong");
              }
          }
  
          public String getRealPathFromURI(Uri contentUri) {
              Cursor cursor = null;
              try {
                  String[] proj = {MediaStore.Images.Media.DATA};
                  cursor = getContentResolver().query(contentUri, proj, null, null,
                          null);
                  int column_index = cursor
                          .getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
                  cursor.moveToFirst();
                  return cursor.getString(column_index);
              } finally {
                  if (cursor != null) {
                      cursor.close();
                  }
              }
          }
  </code></pre>