title: Best way to get primary shared directory path in Android 29+
body: <p>I'm working on updating an Android app to remove references to deprecated functions. One feature of the app uses <code>Environment.getExternalStorageDirectory()</code> to access the primary shared directory of the device. That feature, in context, yields the path <code>/storage/emulated/0</code> (and this path is displayed to the user).</p>
  <p>As of API level 29, <code>Environment.getExternalStorageDirectory()</code> has been deprecated and replaced with Context's <code>getExternalFilesDir()</code> method, but swapping <code>Environment.getExternalStorageDirectory()</code> for <code>getContext().getExternalFilesDir(null)</code> results in the feature yielding the path <code>/storage/emulated/0/Android/data/&lt;app package name&gt;/files</code>, which is where app-specific data is stored. If I instead use <code>getContext().getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS)</code>, for example, that yields <code>/storage/emulated/0/Android/data/&lt;app package name&gt;/files/Downloads</code>. Not the desired result</p>
  <p>I've tried appending <code>/../../../..</code>, which effectively displays the same directory, but the user ends up seeing <code>/storage/emulated/0/Android/data/&lt;app package name&gt;/files/../../../..</code>, and that's unwieldy and annoying. I've also considered simply lopping off everything after and including &quot;Android/&quot;, but I don't know if that will cause problems on other devices.</p>
  <p>What is the best way to use <code>getExternalFilesDir()</code> to get the <em>primary</em> shared directory?</p>