title: How to get the file path from URI?
body: <p>Please find my code below. I need to get the file path of the pdf document, selected by the user from SDcard. The issue is that the URI.getPath() returns:</p>
  
  <pre><code>/file:///mnt/sdcard/my%20Report.pdf/my Report.pdf
  </code></pre>
  
  <p><strong>The correct path is</strong>:</p>
  
  <pre><code>/sdcard/my Report.pdf
  </code></pre>
  
  <p><strong>Please note</strong> that i searched on stackoverflow but found the example of getting the filePath of image or video, <strong>there is no example of how to get the filepath in case of PDF</strong>?</p>
  
  <p><strong>My code , NOT all the code but only the pdf part</strong>:</p>
  
  <pre><code> public void openPDF(View v)
   {
       Intent intent = new Intent();
       //intent.setType("pdf/*");
       intent.setType("application/pdf");
       intent.setAction(Intent.ACTION_GET_CONTENT);
       startActivityForResult(Intent.createChooser(intent, "Select Pdf"), SELECT_PDF_DIALOG);
   }
   public void onActivityResult(int requestCode, int resultCode, Intent result) 
   {
       if (resultCode == RESULT_OK) 
       {
           if (requestCode == SELECT_PDF_DIALOG) 
           {
               Uri data = result.getData();
               if(data.getLastPathSegment().endsWith("pdf"))
               {
                  String pdfPath = data.getPath();
               } 
               else 
               {
                   CommonMethods.ShowMessageBox(CraneTrackActivity.this, "Invalid file type");   
               }               
            }
        }
   }
  </code></pre>
  
  <p>Can some please help me how to get the correct path from URI?</p>