title: Android - Choose Image from Gallery and store it in a File type variable
body: <p>I am a new to Android Development. I wish to select an image or a video from the Gallery of an Android Device. Store it in a variable of type<code>File</code>. I am doing this, since I need to upload the image/video on <strong>dropbox</strong> using the Android API from my application. The constructor takes in the fourth parameter of the type <strong>File</strong>. I am not sure, what to pass as a file since all the examples I searched display the image chosen in an ImageView by using the <strong>url</strong> and making a bitmap.</p>
  
  <pre><code>imageView.setImageBitmap(BitmapFactory.decodeFile(picturePath));
  </code></pre>
  
  <p>Here is the code, I have.</p>
  
  <pre><code>final Intent galleryIntent = new Intent(Intent.ACTION_GET_CONTENT);
  //to get image and videos, I used a */"
  galleryIntent.setType("*/*"); 
  startActivityForResult(galleryIntent, 1);
  
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
      if (requestCode == 1 &amp;&amp; resultCode == RESULT_OK) {               
      Uri selectedImageUri = data.getData();
      imagepath = getPath(selectedImageUri);                
      }
  }
  
  public String getPath(Uri uri) {
      String[] projection = { MediaStore.Images.Media.DATA };
      Cursor cursor = getContentResolver().query(uri, projection, null, null, null);
      int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
      cursor.moveToFirst();                
      int columnIndex = cursor.getColumnIndex(projection[0]);
      String filePath = cursor.getString(columnIndex);
      cursor.close();        
      yourSelectedImage = BitmapFactory.decodeFile(filePath);
      return cursor.getString(column_index);
  }
  </code></pre>