Reputation: 721
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.
Upvotes: 5
Views: 6947
Reputation: 1006614
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
).
Upvotes: 4