title: how to get image from gallery
body: <p>I'm trying to get image from the gallery of my device ... 
  I'm having a dialog that has a button that initializes the gallery after the user chooses a photo the path of it should be returned ...</p>
  
  <blockquote>
    <p>but the path is returned as null</p>
  </blockquote>
  
  <p>that's how I do it -  </p>
  
  <pre><code>Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
                  intent.setType("image/*");
                  intent.setAction(Intent.ACTION_GET_CONTENT);
                  startActivityForResult(
                          Intent.createChooser(intent, "Select Picture"),
                          SELECT_PICTURE);
  </code></pre>
  
  <p>In my <code>onActivityResult</code> -  </p>
  
  <pre><code>public void onActivityResult(int requestCode, int resultCode, Intent data) {
          if (resultCode == Activity.RESULT_OK) {
              if (requestCode == SELECT_PICTURE) {
                  Uri selectedImageUri = data.getData();
                  photo_path = getPath(selectedImageUri);
                  // photo_path=selectedImageUri.getPath();
                  Globals.galleryFlag = true;
                  DialogFragment pindiDialogFragment = new PinPhotoDialogFragment();
                  pindiDialogFragment.show(getFragmentManager(), "pin photo");
                  dismiss();
              }
          }
      }
  </code></pre>
  
  <p>And that's my <code>getPath</code> function  - </p>
  
  <pre><code>    public String getPath(Uri uri) {
      String[] projection = { MediaStore.Images.Media.BUCKET_DISPLAY_NAME,
              MediaStore.Images.Media.DATA };
      Cursor cursor = getActivity.getContentResolver().query(uri,
              projection, null, null, null);
      int column_index = cursor
              .getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
      cursor.moveToFirst();
      return cursor.getString(column_index);
  }
  </code></pre>