title: Get real path of a file from URI?
body: <p>I'm developing a feature which takes .pdf, .doc and .docx file by using ACTION_GET_CONTENT Intent.</p>
  
  <p>You probably guessed that i need to get Real file path from the uri returned by Intent.
  I have searched for atleast 3 days to find out code which gives file or real path by using URI. But in those code, only files selected from either Downloads or Recent or internal or some other is working. But couldn't find code which can work for all options viz, Recent, Downloads, Internal storage, SD Card, Drive and Drop box.</p>
  
  <p>These are the solutions i tried..
  <a href="https://www.dev2qa.com/how-to-get-real-file-path-from-android-uri/" rel="nofollow noreferrer">https://www.dev2qa.com/how-to-get-real-file-path-from-android-uri/</a> </p>
  
  <p><a href="https://stackoverflow.com/questions/13209494/how-to-get-the-full-file-path-from-uri">How to get the Full file path from URI</a> </p>
  
  <p>and even this too, </p>
  
  <p><a href="https://github.com/iPaulPro/aFileChooser/blob/master/aFileChooser/src/com/ipaulpro/afilechooser/utils/FileUtils.java" rel="nofollow noreferrer">https://github.com/iPaulPro/aFileChooser/blob/master/aFileChooser/src/com/ipaulpro/afilechooser/utils/FileUtils.java</a></p>
  
  <p>I want code which works in android versions between Android Lollipop and Android Pie.</p>
  
  <p>This is my Intent</p>
  
  <pre><code>Intent intent1 = new Intent(Intent.ACTION_GET_CONTENT);
  intent1.addCategory(Intent.CATEGORY_OPENABLE);
  intent1.setType(mimeTypes.length == 1 ? mimeTypes[0] : "*/*");
  if (mimeTypes.length &gt; 0) {
      intent1.putExtra(Intent.EXTRA_MIME_TYPES, mimeTypes);
  }
  startActivityForResult(Intent.createChooser(intent1, "ChooseFile"), REQUEST_CODE_PICK_FILE);
  </code></pre>
  
  <p>And everytime i test these codes, </p>
  
  <pre><code>Caused by: java.lang.IllegalStateException: Couldn't read row 0, col -1 from CursorWindow.  Make sure the Cursor is initialized correctly before accessing data from it.
  
  java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1024, result=-1, data=Intent { dat=content://com.android.externalstorage.documents/document/primary:Download/62-2.pdf flg=0x1 }} to activity {com.xxx.xxx.xxx}: java.lang.IllegalStateException: Couldn't read row 0, col -1 from CursorWindow.  Make sure the Cursor is initialized correctly before accessing data from it.
  </code></pre>