title: Android Studio get File from Gallery Intent
body: <p>Short answer is it possible to get original file from Gallery request,and if it possible how can i do it? This code doesn't work for me.</p>
  
  <pre><code>Uri uri = data.getData();
  File file = new File(uri.getPath());
  </code></pre>
  
  <p>And the long Answer)):
  I use this code to make gallery intent</p>
  
  <pre><code>addGallery.setOnClickListener(new View.OnClickListener()
      {
          @Override
          public void onClick(View v)
          {
               Intent intent = new Intent(Intent.ACTION_PICK);
               intent.setType("image/*");
               startActivityForResult(intent, GALLERY_IMAGE_REQUEST);
          }
      });
  </code></pre>
  
  <p>In mu onActivityResult i use this code</p>
  
  <pre><code>@Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data)
  {
      super.onActivityResult(requestCode, resultCode, data);
      if (resultCode == Activity.RESULT_OK)
      {
          switch (requestCode)
          {
              case GALLERY_IMAGE_REQUEST:
                  if (data != null)
                  {
                      try
                      {
                          Uri uri = data.getData();
                          File file = new File(uri.getPath());
                          FileInputStream inputStream = new FileInputStream(file);
                          bitmap = BitmapFactory.decodeStream(inputStream);
                          imageView.setImageBitmap(bitmap);
                          inputStream.close();
                      } catch (Exception e)
                      {
                          e.printStackTrace();
                      }
                  }
          }
      }
  }
  </code></pre>
  
  <p>And i cant get file.</p>
  
  <p>The same code with getting bitmap from data works well but i need to get exactly file from gallery but not only Uri or Bitmap.</p>
  
  <pre><code>                 try
                      {
                          Uri uri = data.getData();
                          InputStream imageStream = getContentResolver().openInputStream(uri);
                          final Bitmap selectedImage = BitmapFactory.decodeStream(imageStream);
                          imageView.setImageBitmap(selectedImage);
                          imageStream.close();
                      } catch (Exception e)
                      {
                          e.printStackTrace();
                      }
  </code></pre>