TIL: You can reconstruct the SD card root path by stripping the /Android/ suffix from ContextCompat.getExternalFilesDirs()
Was building an offline file browsing kiosk app (MDM) that needed to index & work with files directly from a physical SD card. Android doesn't expose the root path directly, and Environment.getExternalStorageDirectory() (despite the name) returns internal storage.
The trick: ContextCompat.getExternalFilesDirs() returns app-specific paths for every storage volume. Since the /Android/data/<package>/files suffix is standardised, you can strip it to reconstruct the volume root.
val markerIndex = absolutePath.indexOf("/Android/")
val sdCardRoot = absolutePath.substring(0, markerIndex)
Wrote up the full solution with Kotlin code, permissions by API level, OEM gotchas, and a cleaner StorageManager alternative for API 30+:
Curious if anyone's found a cleaner way - especially for devices with non-standard OEM mount points.