Search code examples
androidandroid-external-storageinternal-storage

Android External SD Card Access


Long time iOS developer, advanced Android programmer (but not as advanced as I thought.. LOL)..

Trying to understand Android device storage options. On my android device I have an 14Gig SD Card.

When I write code

String strDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS)+ File.separator + "MyFolder";

it gets placed in a "Documents folder" on the internal device (when viewed with File Manager).

The path appears to be

storage/emulated/0

and my sd card (acording to the File Manager) is

storage/extSdCard

Why does Environment.getExternalStoragePublicDirectory give me a path to my intneral card?

What am I missing that gets me to a path to store files to the external card. I think I understand part of this is do to OS changes in SD Card access in 4.1 but not sure what I'm missing.

I've read through Environment.getExternalStorageDirectory does not return the path to the removable storage and still not clear. My app currently stores files using getExternalStoragePublicDirectory, however my users are requesting they have the option of storing it on the SDCard instead?


Solution

  • Why does Environment.getExternalStoragePublicDirectory give me a path to my intneral card?

    Because external storage is not removable storage. Neither of those are internal storage.

    however my users are requesting they have the option of storing it on the SDCard instead?

    On Android 4.4+, either use the Storage Access Framework (to allow the user to choose a storage location, including removable storage, Drive/Dropbox/other cloud providers, etc.), or use getExternalFilesDirs() on Context. The latter method returns a File[] — if there are 2+ elements in the array, all but the first are locations on removable storage that you can read from and write to. You cannot write to arbitrary locations on removable storage on devices that ship with Android 4.4+.