2

I already read that /sdcard/ is a symlink to the actual path of /storage/emulated/0/.

I'm an Android app developer using Apache Cordova, wherein cordova.file.externalRootDirectory is indeed file:///storage/emulated/0/.

Is it always fully reliable to save some app internal files at /storage/emulated/0/path/to/app, considering that the user might not have an external physical memory card on their phone?

4
  • 1
    As for the question title, the answer is "No": emulated is not physical but what's sometimes called the "internal SD card". The physical one usually shows up in /storage by its label, e.g. /storage/DF8C-A1B1. Besides, emulated/0/ is what shows up at /sdcard if the device owner is "logged in". If there are other accounts, their "internal SD card" shows up as emulated/1/ and so on. – Izzy Dec 20 '20 at 3:35
  • 1
    @Izzy external SD cards are also emulated using FUSE/sdcardfs the way /data/media is. Additionally /sdcard (/storage/emulated/0) may point to a physically external SD card at least in two situations: 1) User formatted the SD card as Adoptable storage and migrated complete data to it. 2) On a device with physical primary only storage configuration (which isn't very common). – Irfan Latif Dec 20 '20 at 4:39
  • 1
    @IrfanLatif never heard of those, thanks for the pointer! But if you read the page behind the link, it doesn't say a word on "emulated" for this rare case – but it says for all others: "Primary shared storage (/sdcard) is emulated on top of internal storage." And that's not the "physical card" – especially not with the Nexus 6 being named an example (except for the Nexus 1, no Nexus has a slot for SD cards). You may have a point with adoptable storage, though, which I never used (why should I; that's just an emergency last resort anyhow). – Izzy Dec 20 '20 at 12:07
  • 1
    @Izzy SD cards are always emulated whether using as Portable Storage or Adoptable Storage or with the Physical Primary Only configuration. Apps are never accessing the undelying filesystem directly in shared storage. And I haven't used any device with the Physical Primary Only configuration either, nor I've ever used Adoptable storage except for making experiments. But from a developer's perspective all possible situations have to be considered. – Irfan Latif Dec 20 '20 at 12:28
4

Is it always fully reliable to save some app internal files at /storage/emulated/0/path/to/app?

No. External shared storage isn't reliable, as documented under getExternalFilesDir() and other related documentation, because of multiple possible reasons:

  • User or any other app with full storage access can read, modify or delete the files.
  • App's private directories in external storage get deleted when the app is uninstalled.
  • User might be using physically external SD card as the only primary shared external storage. So the data is lost when the card is removed.

Better use internal storage (getFilesDir() and sisters) for data security and reliability. For more details:

2
  • thanks a lot, but when the user never had a physically external card in the first place, does /storage/emulated/0/path/to/app still exist? – João Pimentel Ferreira Dec 20 '20 at 21:50
  • 1
    @JoãoPimentelFerreira yes. /storage/emulated/0 always exists. It's an emulated filesystem, the actual underlying directory is /data/media/0. You can please go through my answers to the linked questions for detailed explanation on this. – Irfan Latif Dec 20 '20 at 22:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.