title: Android - Get absolute file path from uri, picked from Downloads
body: <p>I am trying to get the absolute file path from the uri. But can't get it for the files downloaded with some download manager.</p>
  <p>For example, I have downloaded an audio and stored it in <code>/storage/emulated/0/MIUI/.ringtone/Our Street (30-secs version)_&amp;_7f2f552b-b5b8-41a0-94de-4b3b065b7c00.mp3</code>. If I pick this file from <code>Downloads</code> section of file picker I got the following uri <code>content://com.android.providers.downloads.documents/document/19</code> and I can not calculate the absolute path from this uri.</p>
  <p>But if I pick the file from original directory i.e <code>/storage/emulated/0/MIUI/.ringtone/</code> I got this uri <code>content://com.android.externalstorage.documents/document/primary%3AMIUI%2F.ringtone%2FOur%20Street%20(30-secs%20version)_%26_7f2f552b-b5b8-41a0-94de-4b3b065b7c00.mp3</code> and I can get the absolute file path from this url.</p>
  <p><strong>How could I get the absolute file path while picked from <code>Downloads</code>?</strong></p>
  <p>I am opening file picker using following code:</p>
  <pre><code>Intent chooseFile = new Intent(Intent.ACTION_GET_CONTENT);
  chooseFile.addCategory(Intent.CATEGORY_OPENABLE);
  chooseFile.setType(&quot;*/*&quot;);
  chooseFile.putExtra(Intent.EXTRA_ALLOW_MULTIPLE,false);
  startActivityForResult(Intent.createChooser(chooseFile, &quot;Select Audio&quot;), PICK_AUDIO_RESULT_CODE);
  </code></pre>
  <p>For parsing absolute file path from uri I'm using following code:</p>
  <pre><code>final String id = DocumentsContract.getDocumentId(uri);
  
  final Uri contentUri = ContentUris.withAppendedId(
          Uri.parse(&quot;content://downloads/public_downloads&quot;), Long.valueOf(id)
  );
  
  Cursor cursor = null;
  final String column = &quot;_data&quot;;
  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>