5

I am trying to get the Internal and External Storage path of an Android device.

This is how I am getting the Internal Storage path in most of the devices

Environment.getExternalStorageDirectory().getPath()

The above method is working in most of the device but some device this method is giving issue that is it is returning the SD Card path.

Someone who could tell me how to exactly get the Internal storage path in those device whose Environment.getExternalStorageDirectory().getPath() return External Storage path (SD Card path).

I am also aware of Environment.getDataDirectory().getPath() but this method return value like /data whereas the Environment.getExternalStorageDirectory().getPath() for the same device returns /storage/sdcard0 which points to Internal Storage when SD Card is not present but when an SD Card is present it gives the path which points to SD Card and not Internal Storage.

Can anyone help me understand the difference between the above two and also help me to get the Internal Storage path of an Android device? Also, help me with a solution which works sam across all the devices.

EDIT : Anyone who feels this post is inappropriate please comment and let me know the reason so that I could keep that in mind for future.

5
  • 2
    It is unclear what you mean by "the Internal storage path". It does not seem to line up with what the Android SDK refers to as internal storage, external storage, or removable storage. Jan 21, 2018 at 16:27
  • 2
    Hi Interesting question, possible answer stackoverflow.com/a/19982338/2298357 Jan 21, 2018 at 16:29
  • @PankajKantPatel Thanks for the answer. Will this answer return Internal Storage path as well as External Storage path (SD Card). And also will this work same for all the devices? Jan 21, 2018 at 16:55
  • @CommonsWare Thanks. But I am referring to the Storage where generally files are saved such as WhatsApp Folder, DCIM, Download etc.. Jan 21, 2018 at 16:57
  • @Rahulrr2602 I have to say this is an important Question. Even after knowing this from Android I have stumbled many a times with this same question while developing in Flutter. I think the nomenclature creates the conflict. Because as technology grew, the same idea of internal/external/removable/partitioned never adhered to the original function names! Nov 29, 2021 at 9:30

1 Answer 1

4

I am referring to the Storage where generally files are saved such as WhatsApp Folder, DCIM, Download etc.

That is what the Android SDK refers to as external storage.

The above method is working in most of the device but some device this method is giving issue that is it is returning the SD Card path.

It should return the location of external storage on 100% of Android devices. Whether external storage is removable or not is up to the device manufacturer. The vast majority of Android devices have permanent non-removable external storage, typically on the same partition as internal storage in the on-board flash memory of the device.

Someone who could tell me how to exactly get the Internal storage path in those device whose Environment.getExternalStorageDirectory().getPath() return External Storage path (SD Card path).

Most likely, there is no such path.

the Environment.getExternalStorageDirectory().getPath() for the same device returns /storage/sdcard0 which points to Internal Storage when SD Card is not present but when an SD Card is present it gives the path which points to SD Card and not Internal Storage.

The value of getExternalStorageDirectory() should not vary based on the presence or absence of some piece of removable media. If your description is accurate, then that is a buggy device, and there is little that you can do about it. Certainly, there is no standard means of getting the "other" getExternalStorageDirectory() value, since that value should not be changing.

(BTW, what device do you have that behaves this way?)

Can anyone help me understand the difference between the above two

getDataDirectory() more or less returns the root of internal storage. I say "more or less" as apps never really work with this directory, but instead with app-specific subdirectories (e.g., getFilesDir() on Context).

3
  • Excellent Answer. Thank You very much. The device which is giving this issue is Micromax Canvas Tablet P290. Can you also please guide me on how to find the SD Card path?. Jan 21, 2018 at 18:06
  • @Rahulrr2602: Hmmm... I will keep an eye out for that and will see if I can get one for testing. "Can you also please guide me on how to find the SD Card path?" -- generally, you do not access removable storage via the filesystem. There is no guaranteed way to get a filesystem path for removable storage, and that path would be useless (since you do not have read or write access to most of it). Jan 21, 2018 at 18:13
  • Thank You very much. Just one more thought can this be because the Tablet treats the SD Card as Internal Storage(Storage in which DCIM, Download folders are placed)? And hence the actual Internal storage is treated as External Storage. Jan 21, 2018 at 19:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.