title: How can i get PDF Real path from Download Folder in Android?
body: <p>I want to get the real path of PDF from URI of the downloaded pdf from the download folder.</p>
  
  <p>I am already following <a href="https://stackoverflow.com/a/36109871/7846071">this</a> link. But in this, I do not get the real path and getting exception. like below: </p>
  
  <p><strong>URI</strong></p>
  
  <blockquote>
    <p>content://com.android.providers.downloads.documents/document/msf%3A26</p>
  </blockquote>
  
  <p><strong>Lunch Intent:</strong></p>
  
  <pre><code> Intent intent = new Intent();
   intent.setType("application/pdf");
   intent.setAction(Intent.ACTION_GET_CONTENT);
   startActivityForResult(Intent.createChooser(intent, "Select PDF"), PICK_PDF_REQUEST);
  </code></pre>
  
  <p><strong>OnActivityResult:</strong></p>
  
  <pre><code>if (requestCode == PICK_PDF_REQUEST) {
              if (resultCode == Activity.RESULT_OK) {
                  Uri uri = data.getData();
                  String path = null;
                  try {
                      path = getPDFPath(uri);
                      LogUtils.logE(TAG, "Document :  " + path);
                  } catch (URISyntaxException e) {
                      e.printStackTrace();
                  }
            }
   }
  
  
       private String getPDFPath(Uri uri) {
              // DocumentProvider
              if (DocumentsContract.isDocumentUri(context, uri)) {
                  // ExternalStorageProvider
                  if ("com.android.externalstorage.documents".equals(uri.getAuthority())) {
                      String documentId = DocumentsContract.getDocumentId(uri);
                      String[] split = documentId.split(":");
                      String type = split[0];
                      return Environment.getExternalStorageDirectory().toString() + "/" + split[1];
  
                  } else if ("com.android.providers.downloads.documents".equals(uri.getAuthority())) {
                      String decodedURI = Uri.decode(uri.toString());
  
                      if (decodedURI.contains("raw:")) {
                          return decodedURI.substring(decodedURI.indexOf("raw:") + 4);
                      }
  
                      String id = DocumentsContract.getDocumentId(Uri.parse(decodedURI));
  
                      Uri contentUri = ContentUris.withAppendedId(
                              Uri.parse("content://downloads/public_downloads"), java.lang.Long.valueOf(id));
  
                      return getDataColumn(contentUri, null, null);
                  }
              }
              return null;
          }
  
          public String getDataColumn(Uri uri, String selection,
                                      String[] selectionArgs) {
  
              Cursor cursor = null;
              final String column = "_data";
              final String[] projection = {
                      column
              };
  
              try {
                  cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs,
                          null);
                  if (cursor != null &amp;&amp; cursor.moveToFirst()) {
                      final int index = cursor.getColumnIndexOrThrow(column);
                      return cursor.getString(index);
                  }
              } finally {
                  if (cursor != null)
                      cursor.close();
              }
              return null;
          }
  </code></pre>
  
  <p><strong>Exception</strong></p>
  
  <pre><code> 2020-05-04 14:47:09.747 17908-17908/ W/System.err: java.lang.NumberFormatException: For input string: "msf:26"
  2020-05-04 14:47:09.748 17908-17908/W/System.err:     at java.lang.Long.parseLong(Long.java:594)
   2020-05-04 14:47:09.748 17908-17908/ W/System.err:     at java.lang.Long.valueOf(Long.java:808)
  </code></pre>
  
  <p>I want Real path of PDF so I can use it for further use.</p>
  
  <p><strong>Thanks in Advance!!!</strong></p>