What are the differences among Internal storage, external storage, sd card and removable storage?
When building an app that uses the internal storage, the Android OS creates a unique folder, which will only be accessible from the app, so no other app, or even the user, can see what's in the folder.
The external storage is more like a public storage, so for now, it's the sdcard, but could become any other type of storage (remote hard drive, or anything else).
The internal storage should only be used for application data, (preferences files and settings, sound or image media for the app to work).
If you intent to download many mp3s, i'd reccomend saving them to external storage, as the external storage is often bigger. Besides, storing data on the internal storage may prevent the user to install other applications.
Android External Storage vs. SD Card
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:
- Environment.getExternalStorageState: mounted
- Environment.isExternalStorageEmulated: true
- Environment.isExternalStorageRemovable: false
- Context.getExternalCacheDir: /storage/emulated/0/Android/data/com.codeblast.storagetype/cache
- Context.getExternalFilesDir: /storage/emulated/0/Android/data/com.codeblast.storagetype/files
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. :-)
External vs Internal memory storage . What shall i use?
AFAIK there are no limits on internal memory per application. But, it's true, that this memory usually runs low if users have lots of apps on device so you should not use it for big (or lots of) files.
I'd go with external memory (sd-card) and IF raw access to images is a problem, then I'd:
- Encrypt the file. That's heavy and it'll slow things down.
- Scramble the file. This involves shifting around the bytes, e.g. moving first 1000 bytes to the end of the file, etc.. You can create your own version of
InputStream
that does byte-shuffling, and pass it toBitmapFactory.decodeStream(..)
.
About the Android's Internal Storage and the external SD Card
Just to answer part of your question.From the official documention:
All Android devices have two file storage areas: "internal" and "external" storage. These names come from the early days of Android, when most devices offered built-in non-volatile memory (internal storage), plus a removable storage medium such as a micro SD card (external storage). Some devices divide the permanent storage space into "internal" and "external" partitions, so even without a removable storage medium, there are always two storage spaces and the API behavior is the same whether the external storage is removable or not.
You do not have a removeable SDCard, but your device has a location on its internal storage that behaves like one.
Android - Internal Storage vs External Storage when App installed on SD Card
The app can be installed onto the SD card, but the content will be saved on the built in storage, not the external SD card.
No. If the device has external storage, the app will be installed to external storage. It does not matter whether the device also has an SD card.
If the app is install on an SD card, will calling getFilesDir() give a path on the SD card, or the internal storage?
getFilesDir()
is always internal storage, regardless of where the app is installed.
Choose internal storage and external storage
Use Internal Storage for your purpose (as a file or as a shared pref[key-value pair] )
SD Card is not an option for you usage .
Use the android developer link which explains various storage options:
http://developer.android.com/guide/topics/data/data-storage.html
Cheers,
Preeya
Questions about Android storage capacity
Here you go:
If so, I wonder where the external storage and the internal storage
occupy each of the 64 GB, and where can I see them?
You can see it in Settings > Storage > Internal Shared Storage.
Below is screenshot from Sony Xperia Z5 device Android 7.1:
Are both stores sharing 64GB?
Yes both are sharing the storage. Check below screeshot from Settings > Storage:
To understand more about stoarge capacities in Anroid you can check my famous answer here : https://stackoverflow.com/a/29427958/631803
Related Topics
Changing Text Color of Menu Item in Navigation Drawer
Android: How to Refresh Listview Contents
How to Change the Color of the Tabs Indicator Text in Android
How to Set Spinner Default Value to Null
Android Studio 2.0 - Pause/White Screen on App First Run
How to Add Shadow to the Fab Provided with the Android Support Design Library
Debug Native Code in Android Library
Eclipse Installation Error: Install_Failed_Uid_Changed
Android Studio: Application Installation Failed
Android Sd Card Write Permission Using Saf (Storage Access Framework)
Convert Xml to JSON Object in Android
How to Finish an Android Application