2

Is there a reliable way of finding out the external SD card folder on Android devices? (KitKat and later)

My understanding is that from KitKat onward you can use getExternalFilesDirs(null) to get the list of usable storage including secondary SD cards.

However on a Lenovo A3500 tablet with an SD card inserted, getExternalFilesDirs() only returns one entry "/storage/emulated/0/Android/data/<app>/files". Going through a file manager one can see both "/storage/sdcard0" (internal flash) and "/storage/sdcard1" (external SD card) but the secondary SD is not available in the list of one entry returned by getExternalFilesDir().

Do some manufacturers decide not to export the SD folder via that standardised API? Are other methods better to reliably find additional storage on a device?

Device is Lenovo A3500 with Android 4.4.2

  • "My understanding is that from KitKat onward you can use getExternalFilesDirs(null) to get the list of usable storage including secondary SD cards" -- only for devices that ship with Android 4.4+. Your device shipped with Android 4.2.2, if [GSMArena](http://www.gsmarena.com/lenovo_a7_50_a3500-6280.php) is correct. Prior to Android 4.4, removable media was not officially accessible by developers at all. Manufacturers offering upgrades to 4.4+ from pre-4.4 can do what they want with respect to integrating with 4.4's limited removable media support. – CommonsWare Sep 03 '15 at 23:57
  • Have a look at System.getenv("SECONDARY_STORAGE"); and others. – greenapps Sep 04 '15 at 07:51

1 Answers1

0

I have solution if you are above 4.4+ & need to get sd-card files directory.

val externalStorageVolumes: Array<out File> =
            ContextCompat.getExternalFilesDirs(this.context, null)
val secondaryExternalStorage = externalStorageVolumes[1] //Sd_card files directory

If Sd card is present that array size will be 2. First one is the emulated storage & next one refers Sd card storage.

venkatesh
  • 319
  • 2
  • 10
  • It's edited, if you are above 4.4+. Someone may find this useful to get sd card path. – venkatesh Sep 29 '20 at 13:56
  • getExternalFilesDirs returns only 1 entry on my Android 8.0 emulator too (while it has an SD card). So this is not an answer at all... – Alexander Dyagilev Sep 29 '20 at 17:56
  • getExternalFilesDirs will return 2 entry if your sd-card is mounted else 1 entry. Make sure it is mounted. Try with a real device. Don't comment blindly without gathering proper info [https://stackoverflow.com/a/33350615/8380444] – venkatesh Sep 30 '20 at 09:53