I'm using Bluestacks for testing my app, because I don't have Androids lying around. I'm tring to write a file to the SDCard but can't seem to figure out the path for it. I've tried the following: /mnt/sdcard/ext_sd
& /mnt/extSdCard
but neither of those worked.
1 Answers
I've tried the following:
/mnt/sdcard/ext_sd
&/mnt/extSdCard
but neither of those worked.
You should not hardcode paths. Because SD card storage location or path varies from phone to phone. SD card storage location in my phone is /storage/sdcard1
Now coming to your question,
Before API level 19, there was no official API method
to store in SD card. But, many could do it using unofficial libraries or APIs.
Officially, one method (getExternalFilesDirs) was introduced in Context class in API level 19 (Android version 4.4 - Kitkat).
File[] getExternalFilesDirs (String type)
It returns absolute paths to application-specific directories on all shared/external storage devices where the application can place persistent files it owns. These files are internal to the application, and not typically visible to the user as media.
That means, it will return paths to both types Storage - Internal memory and Micro SD card. Generally, second returned path would be storage path of micro SD card(but not always). So you need to check it out by executing the code with this method.
Instead of hardcoding paths, you should use this method in your app source code to get the SD card location. Then, write files to that location.
If you want to know more about storage location or paths in Android, please go through my other answer
-
Before API 19, the official way was `/sdcard`. You can still use it on newer phones (for backward compatibility) where it is a symlink to the real location. – StenSoft Aug 28 '16 at 09:11
-
@StenSoft I meant there was no official API method before API 19. Anyways, thanks for pointing out. I have updated my answer to avoid this confusion :) – AnV Aug 29 '16 at 11:59