After reading the Android documentation on storing files, I see that External Storage can include both a removable sd card AND storage that is internal to the device, i.e. not removable. Is there a way to distinguish between removable storage and non-removable storage when choosing to save a file to External Storage?
Additional Notes. Motorola recommends setting up the SD card as Internal Storage if the device has 8GB or less of storage.
The SD Card is called "External Storage" to be compatible with other way of having a storage independent from the system. So the SD Card is the External Storage (both are the same).
Use SD card as default storage for installing apps It will allow you to install your apps directly to the SD card. If you do this, the SD card will also be acting as internal storage. The solution is an easy one and is compatible with many android devices.
Most Android phones have an SD card slot - or, more likely, a microSD card slot- which allows you to significantly expand the storage space in your phone.
I think you can't reliably distinguish between internal and external (SD) storage.
At first glance it might seem like you can use something like Environment.isExternalStorageRemovable()
but this isn't reliable, because your "primary external" storage device might very well be the device's internal memory, not the SD card.
The doc for Environment.getExternalStorageDirectory()
states:
Note: don't be confused by the word "external" here. This directory can better be thought as media/shared storage. It is a filesystem that can hold a relatively large amount of data and that is shared across all applications (does not enforce permissions). Traditionally this is an SD card, but it may also be implemented as built-in storage in a device that is distinct from the protected internal storage and can be mounted as a filesystem on a computer.
As an example, my LG G4 has an external SD card installed, and I can see it with adb (external_SD
):
$ adb shell ls -la /storage/
drwx------ root root 2015-02-28 01:10 USBstorage1
drwx------ root root 2015-02-28 01:10 USBstorage2
drwx------ root root 2015-02-28 01:10 USBstorage3
drwx------ root root 2015-02-28 01:10 USBstorage4
drwx------ root root 2015-02-28 01:10 USBstorage5
drwx------ root root 2015-02-28 01:10 USBstorage6
dr-xr-xr-x root root 2015-02-28 01:10 emulated
drwxrwx--x root sdcard_r 2015-07-31 08:19 external_SD
lrwxrwxrwx root root 2015-02-28 01:10 sdcard0 -> /storage/emulated/legacy
However, the various APIs for external storage return values that prove that the device is using internal memory as its "primary external" storage:
Running the code on an emulator without external SD card returns exactly the same results.
So you can't assume that /mnt/sdcard
means a physical SD card.
You may have reconsider what you're actually trying accomplish rather than trying to detect the storage type. :-)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With