How can I let users access the internal storage directory of my app?

I took a closer look at the result of getFilesDir() vs getExternalFilesDir() and found that getFilesDir() returns /data/data/[packagename]/files while getExternalFilesDir() returns /Android/data/[packagename]/files. I thought the app files I was browsing in /Android/data were the internal storage directories, but now I see that those are actually the external storage directories.

If the internal storage directories are indeed never available to regular users, I wish the documentation said that instead of saying they are not available “by default.” To me at least, saying “by default” implies that the default behavior can be changed.

Anyway, I tested and confirmed that if I delete my app, files saved to the getExternalFilesDir() are deleted automatically. So that meets my need for a storage location that is clearly connected with the app (uses an app-specific directory name and is deleted with the app) but is accessible to users for occasional manual file management.

Here’s a comparison that might be helpful to someone else reading this:

  • getFilesDir() – creates an app-specific directory; hidden from users; deleted with the app
  • getExternalFilesDir() – creates an app-specific directory; accessible to users; deleted with the app
  • getExternalStoragePublicDirectory() – uses a shared directory (e.g., Music); accessible to users; remains when the app is deleted

Leave a Comment