Sorry if this question have been asked before . But i didnt understand . Can any one give me good explanation of it with an example . what is difference between both of them isExternalStorageRemovable and isExternalStorageEmulated
In old android devices external storage was directed to SD card that you could physically remove. In new android devices external storage is directed to a directory on the data partition (with FUSE on top of it) - an emulated SD card.
So, isExternalStorageEmulated will tell you if your storage is on data partition and isExternalStorageRemovable will tell you if your storage is SD card. Most of the time they will return opposite output but I guess you can find a rare device that its external storage is a separated partition so both of them will return false.
Related
I make a search on google and other.
I can not find answer about external storage/memory card path.
so please help.
There is no reliable way to determine the path to a micro SD card. To removable storage.
getExternalStorageDirectory() will give a path to external storage and hence is unusable.
You better let the user pick the right path.
On modern systems you can try getExternalFilesDirs().
How to get the status whether a SD card is mounted/inserted in Android device or not.
The following is always returning TRUE:
android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED)
There are several post related to this, but I couldn't find a manufacturer-independent solution.
Android API: Iterate through all external storages obtainable with getExternalStoragePublicDirectory, calling isExternalStorageRemovable on each of them. When you find one, ask if it is mounted with getExternalStorageState. However, it may happen that the SD card is not used for any external storage directory and so you would not find it.
fstab: Parse /etc/vold.fstab, find mount points, ask if they are removeable with isExternalStorageRemovable and check their state with getExternalStorageState. Because it does not use public API, it may not work correctly in some versions of Android, including future ones. It may not work when the SD card is not used for any external storage either.
mounts: Parse /proc/mounts and do the same as for fstab but that may not work if the SD card is not used for any external storage. Or search for any partition using vfat but that may return false positives. /proc/mounts is a public Linux API so it is present in the same format everywhere. If no SD card can be found there, it is impossible to distinguish whether the SD card is unmounted or not supported at all.
However, there's really no reason to need that (and that's why there is no simple API for it). When you want to put some content in an external storage, you should use the appropriate directory provided by getExternalStoragePublicDirectory, disregarding whether it is an SD card or not.
I have an Android application which needs some data from the SD and I check on entry that the files are there with File.exists() method and checking the SD card isnt either UNMOUNTED or SHARED. This works fine on my device, but have gotten feedback that on other device its showing the Toast that indicates that no data is present.
My questions are:
1 - Is there a way this checks can indicate that the SD is not mounted or shared even after it has been unplugged from the PC?.
2 - Is it possible that getExternalStorageDirectory() resolves to internal storage? I know how this sounds, but people have told me that the app works on some devices when copying the data to internal storage instead of external one, even though i keep telling them that shouldn't happen.
On many devices getExternalStorageDirectory() does not give you the SdCard but resolves to internal storage often called /sdcard or /storage/sdcard0. It does not matter if you
put a microSD in the device. Those paths stay the same and are valid.
If you put in a microSD than that can be mounted under many names e.g:
, "/mnt/sd-ext
, "/mnt/sdcard-ext
, "/mnt/external_sd
, "/mnt/extsd
, "/mnt/extSdCard
, "/mnt/sdcard2
There is no function to determine the sdcard.
You have to give your users the opportunity to select the storage directory.
I found that using Environment object isn't reliable;e to determinate SD card. Actually it works, however sometimes tells like as no SD card, so I use just direct mount as /sdcard and it works. Now I realized that a device may have several SD cards. My device report it as external-sdcard, so I can access this card as /external-sdcard or /sdcard/external-sdcard. Now question, how to figure out type of a particular mount? I can traverse directory, but File object doesn't have any attribute telling me I am SD card. I remember regular Java provides FileSystem objects which I can use to inspect particular files and this object can tell me if a File object is simple file, or it is drive, or it is external drive. Is something like that available for Android?
AFAIK, the currently documented API only supports one SD card (actually external storage).
You can use Environment.getExternalStorageDirectory() to get the directory, and Enviroment.getExternalStorageState() to check if it is mounted.
Anything besides that seems to be (currently) unsupported.
Bearing that in mind, you could parse /proc/mounts to find out what file systems are mounted where.
I would like to get in my file browser File reference to external disk not SD Card. I mean I know that there is method
Environment.getExternalStorageDirectory();
But to my knowledge this will get reference to SD Card. But how to get external disk (say kind of USB storage attached to Android device)? You know that device can have both SD card and external USB stick attached to them.
But how to get external disk (say kind of USB storage attached to Android device)?
Android does not support this. If particular devices do, you would have to ask their manufacturers what they recommend.
In the end I have selected following solution:
1) Enlisting all existing roots using:
File[] roots=File.listRoots();
2) check presense among those roots standard ones, i.e.
File phoneRoot=new File("//");
File sdRoot=Environment.getExternalStorageDirectory();
3) If there are some extra ones - treat them as those additional external disks/sticks
I think it's best solution, since no hacks, everything is standard and this covers possible future extensions.