Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

`/storage/emulated/legacy/` vs `/storage/emulated/0/` vs `data/data/myApp'

I want to save in my app an imageFile

I want "Google+ cropper app" to use it.

But the later opens another image.

I guess it's permissions issue.

In my code i save here:

Is this external storage? Environment.getExternalStorageDirectory().getAbsolutePath() which returns: /storage/emulated/0/myApp/file1.tmp

using adb shell is see the file is actually saved in: /storage/emulated/legacy/myApp/file1.tmp

why is the difference?

should i use this place instead? Is this external storage?

getAppContext().getFilesDir().getParent() which returns: `data/data/myApp'

like image 211
Elad Benda Avatar asked May 13 '14 07:05

Elad Benda


People also ask

Where is/storage/emulated/0?

24 /storage/emulated/0/is actually /data/media/0/exposed through an emulated / virtual filesystem, not the actual one. This is with reference to my previous answer here, but with more relevant details. ANDROID STORAGE: On Android 5: /sdcard >S> /storage/emulated/legacy >S> /mnt/shell/emulated/0 /mnt/shell/emulated >E> /data/media

How do I read/storage/emulated/0 on Android?

You don’t have permission to read /storage/emulated/, but since you know it’s in subdirectory 0, just go cd /storage/emulated/0, and you will be able to look around and interact as expected. The easiest way to access /storage/emulated/0/ on an Android device is to download a third-party File Explorer such as ES File Explorer.

What is emulated storage in empower?

Emulated storage indicates the file location of one item against its symlink on the device/ external storage. A symlink or a symbolic link is a file that is used as a reference to another file or directory known as the ‘target’. The symlink is a file that is directly interpreted by the OS as the path to the ‘target’.

What is the difference between ‘internal storage’ and ‘emulated files’?

If you open the homepage of the ES File Explorer and tap on ‘Local’, you’ll see a folder named ’emulated’. However, if you tap on the folder, you will see a message ‘Empty Folder’. On the other hand, if you tap on Internal Storage in ES, you will ultimately be redirected to a directory that contains all the folders in the Internal Storage.


1 Answers

Historically the difference between internal and external storage was as follows...

Internal: The internal flash storage of an Android device used to allocate private storage for each app. The storage allocated is protected to prevent access by any other app (except on rooted devices).

External: In many cases an SD card with no security restrictions, i.e., all apps can access all areas of "external" storage.

As new versions of Android have come along and new devices have increasingly more internal flash storage, the difference between internal and external is becoming blurred. For example my Nexus 7 doesn't have an SD card slot.

In the case of devices without true external storage, it's still necessary for Android to provide an emulated external storage in order to remain compatible with older apps. In other words the RAM is physically internal (non-removable) but a section of it is partitioned and the Android file-system APIs treat that partition as being "external" and world-readable.

As for the paths you see for external storage such as...

/storage/emulated/0/myApp/file1.tmp
/storage/emulated/legacy/myApp/file1.tmp

...one or other of those (possibly both) is a redirection or "virtual" path to the same part of the emulated external directory and file.

This is why it is essential to always use the correct API call to get access to files and directories rather than assuming a hard-coded path as it may well vary from device to device.

If you use Environment.getExternalStorageDirectory(), you can be confident that any other app which does the same will be able to get access to any files you create there.

If you use getFilesDir() then you are accessing the root of the internal storage allocated privately to your app and accessible only to your app (although, as I mentioned a rooted phone can access private / internal storage).

like image 136
Squonk Avatar answered Nov 04 '22 23:11

Squonk