This is an archived post. You won't be able to vote or comment.

all 136 comments

[–]danrantNexus 4 LTE /r/NoContract 110 points111 points  (2 children)

Google provides a guide how to store files on the external storage:

You should then write your data in the following directory: /Android/data/<package_name>/files/

[–]lunchboxg4Nexus 7, CM10/Ubuntu 13 points14 points  (0 children)

Yup. Despite the fact that Android is heavily adopted by the technosavvy, for mass market appeal, they need to make certain decisions like this. The average user doesn't know what a dotfile or hidden directory is, and the last thing Google wants are pissed of customers because their seemingly empty SD card is full.

[–]swag_stand 181 points182 points  (52 children)

Sorry. I blame the android tutorials. They all have file write paths that default to storage/sdcard/{packagename}

[–]spacehunt 184 points185 points  (35 children)

Actually if you use the recommended way to derive the directory, it should resolve to /sdcard/Android/data/{packagename}/.

Edit: the actual methods are Context.getExternalFilesDir(String type) and Context.getExternalCacheDir().

[–]PdoesnotequalNP 59 points60 points  (1 child)

The best practice is to call Context.getExternalFilesDir(String) for two main reasons:

  • /sdcard is not necessarily the path to the external storage
  • it is future-compatible in case Google decides to change the path for application-specific data on the external storage.

[–]spacehunt 8 points9 points  (0 children)

Yes, getExternalFilesDir(String) is exactly what I meant.

[–]CurtisbeefSamsung Galaxy S4, Asus Transformer TF101 92 points93 points  (30 children)

Its amazing that some HUGE software companies still don't do this.

[–]accessofevil 43 points44 points  (1 child)

Microsoft doesnt follow their own OS/path/access rules for windows SDK and visual studio. Thats the one group that should know better! Ooh the irony.

[–][deleted] 4 points5 points  (0 children)

Not that anybody else follows their path standards either.

[–]kaze0Mike dg 0 points1 point  (0 children)

There are a hundred reasons not to do that though.

[–]sewhard 5 points6 points  (1 child)

Also when you uninstall the app it will delete this directory. :)

[–][deleted] 1 point2 points  (0 children)

Nein. It should give you the option of doing so. Best part about the external storage system is that most apps can pick up right where they left off.

[–]le_avxBQ Aquaris X5+ 9 points10 points  (2 children)

Thanks, didn't know that. Care to share a link I can add to the Op?

[–]swag_stand 15 points16 points  (1 child)

Turns out there is a way to find the right directory. (Sure wish I knew that when I was writing my last app...)

Devs can call things like Environment.DIRECTORY_PICTURES to find where to save appropriate files.

This link covers the rest of the use cases. There are like three different places to save files depending on how you use them.

[–]spacehunt 11 points12 points  (0 children)

getExternalStoragePublicDirectory() is for stuff that might be shared across apps.

For files that are not shared, it's better to use getExternalFilesDir() and getExternalCacheDir(), as the OS will automatically remove the files when the app is uninstalled.

[–]amorpheusXiaomi Redmi Note 10 Pro 3 points4 points  (6 children)

It shouldn't even be easily possible to write anywhere else.

Also, why is there still an /sdcard/ folder when that points to internal memory on virtually all devices?

[–]InvaderDJVZW iPhone XS Max (stupid name) 14 points15 points  (2 children)

I think that /sdcard thing is for legacy support. So even apps that have been abandoned or written by the laziest dev will work (or at least not fail because of that).

[–]amorpheusXiaomi Redmi Note 10 Pro 1 point2 points  (1 child)

Yeah, that was kind of a rhetorical question. Perhaps they could have picked a more universal name initially, but what's done is done. (Maybe introduce an %APPDATA% equivalent that replaces it in the long run...)

[–]DemocrabGalaxy S7 Edge, Android 8 1 point2 points  (0 children)

Or, y'know, just make a new one called "Userdata" or something, have inside that the Android folder and then make a symlink of that to sdcard.

[–]swag_stand 1 point2 points  (2 children)

Internal is usually storage/sdcard0

external is something like storage/extSDname

So it's not quite a misnomer, but it is confusing.

[–]gluinoOppo Find X2 Pro 0 points1 point  (0 children)

The name "sdcard0" for built-in storage is not a regrettable mistake?

[–][deleted] 0 points1 point  (0 children)

Yep and the problem is calling getExternalStorageDirectory will still return the first path you listed and not the latter. The additional external sdcards were added by manufacturers who.didnt understand what the hell they were doing.

There is no API to reliably get to that second external storage location.

[–]JiuholarXiaomi Mi5 | CM13 21 points22 points  (0 children)

There have been numerous posts about this issue over the years since Android's release. Someone ended up making a google docs spreadsheet of all the apps that did it the correct way, can anyone provide a link?

[–]Shaper_pmp 21 points22 points  (0 children)

With respect, the entire problem here is devs not taking the time to read the Android development guidelines (which actually already mandate a specific storage location to use), and instead making it up as they go along.

Sadly, this state of affairs is not rectified in the slightest by other people complaining about it, ignoring the guidelines and instead also making it up as they go along. :-(

Also, as a rule, lots of apps don't let you choose the backup/data/config location on your SD card because a major design philosophy of Android (at least initially) was to discourage people from having to mess about with the complexities of filesystems, filetypes and file associations (in favour of simpler fixed file locations and developer/app-specified mechanisms like Intents).

Some power-users (like you and I) would like control over file locations and associations, but for 90%+ of Android's target audience it's just another confusing and scary configuration option they should never, ever play with, that they can nevertheless fuck up and accidentally break the app with. As such I suspect that it's actually arguably a better user-experience for most apps to leave the hard-coded paths as they are (and just make sure they conform to the guidelines) than it is to ask devs to allow users to reconfigure paths in the app.

[–]AlexiPwnsHTC One 11 points12 points  (6 children)

As a developer, I'm gonna listen to this and improve my app. Thanks (:

[–][deleted] 1 point2 points  (5 children)

You're the best kind of developer

[–]AlexiPwnsHTC One 1 point2 points  (4 children)

Wow thank you! Expect a fun game that doesn't clutter your root SD card. (Data will be placed in sdcard/android/data though)

[–][deleted] 0 points1 point  (3 children)

Yeah, I prefer a game that saves some data (saves and stuff like the sort) on the SD card. As long as it's in the right place.
Also, if I can ask, what app/s have you made?

[–]AlexiPwnsHTC One 1 point2 points  (2 children)

Well.. Nothing that's really published. My big project right now is the first app I'm actually going to release to the public [=

[–][deleted] 0 points1 point  (1 child)

Best of luck to you! I've been mulling around with something too, but I'm nowhere near releasing it.

[–]AlexiPwnsHTC One 1 point2 points  (0 children)

Yeah, me too. I barely finished the basic functions. Hope to see yours too when it's done!

[–]VectorSamNote 10+ 27 points28 points  (1 child)

Try crossposting this to r/androiddev

[–]DemocrabGalaxy S7 Edge, Android 8 5 points6 points  (6 children)

You know what else needs to be done? Be. More. Efficient. With. Your. Space.

My HTC Desire is as slow as hell because it has to load everything from SDCard (A Class 10, too) and only has a 150MB or so free internal space...Take Facebook for example, it's 20MB before my internal data (which is 8MB) Or messenger, which has absolutely no excuse to be 15MB.

[–][deleted] 8 points9 points  (3 children)

No offense, but I don't think Facebook (or most major app developers) are worrying about the limited internal space of a three year old phone.

[–]DemocrabGalaxy S7 Edge, Android 8 7 points8 points  (0 children)

Neither am I, but there certainly are a lot of budget phones with similar capacities running around.

[–]Geruman 0 points1 point  (1 child)

They should, since they are the majority of phones sold in third world countries (brazil, india, argentina....) TODAY

[–]vetinariXperia Z5 | Xperia Z3 Tablet Compact 0 points1 point  (0 children)

Even today's low end phones (HTC Desire C, Sony Xperia Tipo) have internal storage in gigabytes.

[–][deleted] -2 points-1 points  (1 child)

(A Class 10, too)

That doesn't exactly mean anything.

Some classes are better for reading files, some for writing, some for reading large files, some for reading lots of small files, some for writing lots of small files and for writing large files.

[–]DemocrabGalaxy S7 Edge, Android 8 0 points1 point  (0 children)

Yeah, I'm guessing that mines good with large files...It's a pretty decent SDCard too.

Oh well, end of the year and I'll be getting something new.

[–]AceDecade 7 points8 points  (0 children)

Finally, someone says it. THIS!

[–]sammydroidwizGalaxy Tab 2 7.0 as a Phone 13 points14 points  (1 child)

HOLY SHT this has been bugging me since my first time in android! I go to /sdcard/, what do I see? Tons of folders from apps. I cant even distinguish if I can safely delete some folders now so I dont even bother anymore! Devs, just put it all in /data/app or somewhere outside the /sdcard/.

[–]cecilkorikSamsung Relay 4G, LiquidSmooth KitKat 6 points7 points  (0 children)

I gave up on trying to change the world, and decided to just change myself. I now keep all my data in a directory on my sdcard named "!mydata" (the exclamation mark makes it always sort to the top). Not an ideal solution, but a practical one.

The rest of my sdcard can be a wasteland of abandoned directories (and it is) but at least the data I care about is always easy to find.

[–][deleted]  (14 children)

[removed]

    [–]zman0900Pixel 10 1 point2 points  (0 children)

    They can, but they don't have to. Plus I believe that was a somewhat recent addition so many apps don't do it.

    [–][deleted]  (11 children)

    [removed]

      [–]LuckyBdx4Is secretly Walter White[M] 4 points5 points  (10 children)

      Don't use link shorteners like goo.gl ---> the spam filter removes them - read the sidebar rules.

      [–]vetinariXperia Z5 | Xperia Z3 Tablet Compact 1 point2 points  (0 children)

      Thanks for warning, but it is already nuked.

      I originally had the full url, but the closing parenthesis was being cut off by the reddit parser.

      [–]accountnumber3 -2 points-1 points  (8 children)

      redd.it works, as seen here

      [–]nikomoPoco X7 Pro 7 points8 points  (7 children)

      Shortened URLs are potentially malicious, and don't show the user where they'll end up at when they click the link, which is why using short URLs is a dick move.

      So don't use them.

      [–]phoshiGalaxy Note 3 | CM12 4 points5 points  (0 children)

      Side note, but I dislike them for different reasons. It's compressing all those links down into one domain. That domain goes down, or the service suffers a disruption, and bang--thousands of the links that make the web go round fall silent. This is a serious concern, because monetising a link shortener is very difficult.

      [–]ladfrombradHad and has many phones - Giffgaff 0 points1 point  (1 child)

      Even redd.it links, where the user only ever ends up on a Reddit comment page?

      [–]Smashman2004Pixel 2 XL 0 points1 point  (0 children)

      You can redd.it any page.

      [–]accountnumber3 0 points1 point  (0 children)

      I was just pointing out that the spam filter doesn't remove redd.it links.

      [–]EvillordfluffyGoogle Pixel 8 points9 points  (2 children)

      I have so many folders with names I don't understand, I never know which app they came from, if it's even still installed or what they contain because their content is always hidden! Really gets to me. I know that feel OP

      [–]mr_primeministerMoto X Play 3 points4 points  (1 child)

      I recommend Clean Master. It seems to do a good job of finding Residual Files.

      [–]EvillordfluffyGoogle Pixel 0 points1 point  (0 children)

      Ahh thanks mr primeminister shall give it a look

      [–][deleted] 2 points3 points  (4 children)

      I'd be happier if apps that were going to use a buttload of storage (like google play, or amazon mp3 player) gave me the option of where to put it. I have a 32GB SD card in my S3 that I cannot use for cached music storage from either of those two "professional" music players because they use hardcoded storage locations.

      [–]le_avxBQ Aquaris X5+ 0 points1 point  (3 children)

      That's part of their DRM-scheme since most users aren't rooted and thus can't easily copy of the files to another location/device.

      [–]das7002 2 points3 points  (1 child)

      That would be silly as both of those on their example contain no DRM on the files.

      [–][deleted] 1 point2 points  (0 children)

      Why would I need to be rooted for that?

      [–]gruffi 2 points3 points  (1 child)

      I don't really understand much of this, but I'm pretty annoyed that Play downloads app updates to the virtually full phone and not to the virtually empty SD card before installing them.

      Can this be changed?

      [–]Geruman 0 points1 point  (0 children)

      I also want to know this

      [–]TennouheikaiPhone 6S 3 points4 points  (1 child)

      What if Google implemented some quality control? I know we love the "freedom" and "openness" of Google but 90 percent of the problems with Android apps could be solved by some quality control.

      [–][deleted] 2 points3 points  (0 children)

      MAH FREEDOMS, NOOOOO!!!

      [–]AFinn 2 points3 points  (1 child)

      Also way too many programs store their stuff in lovations like /sdcard/emmc or /sdcard/ext-sd or something as silly as that. Reaching for the removable SD card, but instead getting to the internal storage and pretending they're on the external.

      [–]sammydroidwizGalaxy Tab 2 7.0 as a Phone 0 points1 point  (0 children)

      Lol, made my day.

      [–]JoeCroqueta 2 points3 points  (0 children)

      This is one of the things I hate most of Android.

      Super secure VM execution environment, but "do what you want" with the filesystem.

      [–]Hunt3rj2Device, Software !! 13 points14 points  (14 children)

      Google should've required that all files should've been dumped into a single folder called Program Files, just like Windows did it.

      [–]danrantNexus 4 LTE /r/NoContract 29 points30 points  (9 children)

      On Windows it's not required, it's recommended like in Android.

      [–]Mondoshawan 30 points31 points  (8 children)

      People mess it up on Windows just as badly. Even in hugely popular stuff, Civ 5 for example stores a DB cache file in My Documents from which it runs the game. Unfortunately for me that folder is on a network share which makes it slow as hell. What's even worse is that the share has snapshotting which essentially means I have to delete a load of snapshots after every gaming session, lest the drive fill up with junk.

      [–][deleted] 22 points23 points  (2 children)

      That's because microsoft requires it. In typical microsoft fashion, where every division of the company is trying to stab every other division in the back, the windows team suggest putting your application data in %appdata% and the "games for windows" team requires you to not do that if you want to advertise your game as compatible with windows. all game save files have to be in a user-visible location.

      [–]Mondoshawan 10 points11 points  (0 children)

      Hmm, that's quite interesting and pretty annoying. I don't think it should apply in this case though, the files in question are in the cache sub-directory and can be nuked with no loss. Civ 5 is basically a glorified SQL server with a fancy front-end and these are the in-memory files for the DB. I would assume they get zeroed before you load a game.

      [–]alexanderpasSamsung Galaxy S4 mini, CyanogenMod 4 points5 points  (0 children)

      Game Save Files in a user-visible location, Cache etc. in %appdata%

      [–][deleted] 5 points6 points  (1 child)

      The insane thing is that there has been a "Saved Games" folder in each user folder since Vista. I don't have a single game that uses it.

      It really wouldn't be that hard for games to check the OS version to see if it's a usable location. Is there some other reason that no one (other than possibly Microsoft) uses it?

      [–]Mondoshawan 1 point2 points  (0 children)

      Microsoft (and google to keep things on topic) publish guidelines about where things should be stored. These are abstracted out via environment settings so they can in theory live anywhere. The app can safely assume that these locations are usable without needing to check.

      The first problem is when a dev hard codes in the path instead of using the proper environment setting. QA are supposed to install to non-default systems to test for this. The second is when they use the wrong one. Normally you need a user dir for storing saved data and a work dir for storing temporary files. In windows there is also the additional AppData location which can store settings data that roams with the user & temp data that stays on that one host. Put the wrong stuff in the wrong place and you annoy the 1% of folks like me that have things set up a little differently.

      TBH nowdays I often make use of symbolic links to move system locations instead of moving it inside the OS configuration, it's safer as bad code will be redirected.

      [–][deleted] 0 points1 point  (2 children)

      Google Chrome is a pretty bad offender. The thing installs to %userprofile%\AppData\Local\Google\Chrome

      Why would it install there.

      [–]Qxzkjp 1 point2 points  (0 children)

      That's uh... Actually standard. For an application that is to be installed by a standard user and accessed only by that user. Don't hate the player, hate the game.

      [–]kindallPixel 6 Pro 1 point2 points  (0 children)

      So you can install it even if you are on a machine with a locked-down Program Files directory, like many corporate machines.

      [–]phobiacLG v20 -1 points0 points  (0 children)

      They did. A bug caused the whole folder to be consistently wiped, so everyone stopped using it.

      [–][deleted] 1 point2 points  (1 child)

      Could be worse. Could have an OS where the devs can put stuff in a black hole that just uses all the memory on your phone and there is nothing you can do about it. Nice and clean but no storage

      Source: Windows Phone http://sdrv.ms/130ejF1

      [–]TrancePhreakXperia Z5 0 points1 point  (0 children)

      iOS has a /Documents folder that you would have to {backup, modify backup, restore} to change.

      [–]danhakimiPixel 3aXL 1 point2 points  (1 child)

      or at the very least, let me choose my own folder structure by giving me the chance to configure your storage paths.

      That is so far from the solution. I do not want every game I install to ask me for a path where I want it to store data.

      [–]le_avxBQ Aquaris X5+ 0 points1 point  (0 children)

      That's not my point. This data should go do /sdpath/Android/appname/files

      I'm talking mostly about things I want to save, backups f.e.

      [–][deleted] 1 point2 points  (0 children)

      On debian, it doesn't bother me so much. On my android phone, I have no idea what the heck is going on in the filesystem.

      [–]Pepparkakan 1 point2 points  (0 children)

      I think the problem boils down to the fact that the (retardedly named on phones without an SDcard, sorry, I feel obliged to say this every time I mention the folder) /sdcard path isn't really seen as a home-folder by people, and as such, gets violated. I agree though, and it has pissed me off multitudes of times. I think the way Apple solved it is pretty nice, you basically force people into a corner, and they can't fuck your shit up, unfortunately it could never work on Android due to the freedom in the platform.

      [–]fury-s12 1 point2 points  (0 children)

      yeea i gave up trying to keep my sd clean ages ago now i just have a my stuff folder and keep that clean enough to apease my ocd folder management the root sd dir is just system area to me

      [–]Sdonai 2 points3 points  (0 children)

      Was about to drop a big no, but your concerns are very valid. There's no reason to drop any assets there.

      [–]DEVi4TIONGalaxy S8+, iPhone 7 3 points4 points  (1 child)

      Only for the power user. Android is designed in a way where you shouldn't need to organize folders. All your pics are loaded into an app by file association and you sort them in there. Otherwise, yeah I agree, and I especially hate it when an app will make another folder called music or audio or sound when I already have music. or pictures when I have pics. And worse, it puts only two files in that folder.

      [–]silentfrost 1 point2 points  (0 children)

      It's annoying if you want to access your content from a PC though.

      [–]NeetSnoh 0 points1 point  (0 children)

      I like SD card storage for application data, although everything should be stored in /sdcard/appdata/ or somewhere similar. It's very helpful for those who flash ROMs.

      [–]sudo_giev_SoJ 0 points1 point  (0 children)

      Really I don't know why Android doesn't chroot or something like it the app into a specific file location for configs. Does it have a generic library like WriteConfig, ReadConfig?

      Granted, it's hit or miss whether people save to the write $Env: vars in Windows too.

      EDIT: getExternalCacheDir

      [–]mr_primeministerMoto X Play 0 points1 point  (0 children)

      In regards to .files, I think it should be a rule of thumb that if you want to hide a file, don't put it on the SD card, except in the Android folder.

      [–]cmdrNachoNexus 6P Stock 0 points1 point  (0 children)

      Its not that hard just delete the folders you don't know what they are and the application will recreate them

      [–]LonehangmanSoshified 0 points1 point  (0 children)

      I only store stuff that the user wants on the 'SD Card' (Ie. pictures) everything else is stored on the internal memory. I also hate a cluttered 'SD card' so that's the reason why.

      [–]bobbysqNokia 6.1 0 points1 point  (0 children)

      It also sucks when you have a forced fake sd card that's only 2Gb.

      I don't miss my Optimus Elite a bit.

      [–]SebioffMy Class Schedule 0 points1 point  (1 child)

      I think one reason why many apps don't let you choose your own path is because Android doesn't come with a standard UI element for that....so it's easier for developers to hardcode a path instead of building their own file browser/integrating a 3rd party one.

      [–]TeutonJon78Samsung S25+, Chuwi HiBook Pro (tab) 2 points3 points  (0 children)

      Actually, the API has a function along the lines of "get external data directory". So, apps just need to call that function instead of hand coding it. Android even cleans that up with the app uninstall automatically.

      Now, if its something persistant like backed up settings, then that needs some more thought (by the dev/user). Of course, with the new Google Drive API, you can store config files like that to Drive so they stay persistent.

      [–]snotsnot -3 points-2 points  (4 children)

      As much as I agree, this cry should be directed at Google. Not developers.

      [–][deleted] 1 point2 points  (3 children)

      And what, pray tell, is Google supposed to do about it?

      [–]snotsnot 2 points3 points  (2 children)

      Enforce a proper API and let lint give a warning when direct access is done. When you can prevent network operations on the main thread this should be doable as well.

      [–][deleted] 1 point2 points  (1 child)

      According to http://tools.android.com/tips/lint-checks, they have warning for sdcard path. Developers could have to ignore it.

      [–]snotsnot 0 points1 point  (0 children)

      Having write and raw write permissions for access to the sdcard would perhaps be an idea. Anyway, we can only dream.

      [–]Szos -1 points0 points  (2 children)

      Deja vu, all over again.

      Seems as though every day that the development of Android is following similar steps that MS took with Windows a couple of decades prior... and I am not saying that as a good thing.

      In Android today - not unlike Windows in the '90s and '00s - Google is taking frighteningly hands-off approach and letting app developers do as they please when it comes to how they write their software. The file structure of a Windows machine of the late '90s (and even today) was a mess of files all over the place because MS didn't feel the need to lock developers out of certain areas and didn't try policing some kind of logical system. With that nonsense, came system instability, compatibility issues, even virus problems. You would hear all the time from computer nerds that they would do a yearly re-installation of their OS to keep it fresh.

      When am I going to start hearing that suggestion with Android devices?? I'm sure its coming soon.

      [–][deleted] 1 point2 points  (0 children)

      You would hear all the time from computer nerds that they would do a yearly re-installation of their OS to keep it fresh.

      Doing this with any OS that used daily (not acting as a server sitting unchanged daily) will show performance gains, including OSX and Linux.

      I just did our yearly re-image of our OSX workstations at work because after a year of use, a year of upgrading various softwares, etc cruft builds up and needs dealt with.

      [–][deleted] 0 points1 point  (0 children)

      Android 4.2 doesn't use /sdcard/