Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Get Application's 'Home' Data Directory

A simple question, relating to the default 'home' directory when an app writes to the internal memory. By default, any files created are placed by the OS (2.2) in:

/data/data/your.package/files 

When reading in files, the same default is used, when keeping in proper context via openFileInput(), openFileOutput(). But if I need to check file existence, for instance, using the File class, I need to specify the whole path in the constructor.

I see there are Environment.getDataDirectory() (returns /data), Environment.getRootDirectory() (returns /system), etc, but nothing related to getting the app's 'home' directory.

It's not a huge deal, but I'd rather not hard-code the full path into my App for File to use (say the package name changes, say the path changes in a future OS release) if there is some way to reference the app's 'home' directory programmatically.

like image 409
Unpossible Avatar asked Jan 19 '11 18:01

Unpossible


People also ask

How do I find my data folder on Android?

Please go to Android system settings, find storage section, click it. From the storage page, find "Files" item, and click it. If there are multiple file managers to open it, please make sure to choose "Open with Files" to open it, which is the system file manager app.

Where is the home directory on Android?

Each app has its own directory in /data/data (for a multi-user system, it's /data/users/n ).

How do I access private data app on Android?

Access private files GUI — In Android Studio, launch Android Device Monitor from the menu: Tools/Android/Android Device Monitor. Navigate to the File Explorer tab, then data/data/<your app package name>/. Find the file you are looking for, and you can push and pull a file from there.

How do I access root data on Android?

Launch “Solid Explorer,” then tap the “hamburger icon” (Menu) in the top-left section. Select “Root” to activate root file access. Navigate to “System -> bin, xbin, or sbin,” depending on what you need. You can also browse other folders in root.


2 Answers

Of course, never fails. Found the solution about a minute after posting the above question... solution for those that may have had the same issue:

ContextWrapper.getFilesDir() 

Found here.

like image 159
Unpossible Avatar answered Oct 05 '22 10:10

Unpossible


You can try Context.getApplicationInfo().dataDir if you want the package's persistent data folder.

getFilesDir() returns a subroot of this.

like image 23
Learn OpenGL ES Avatar answered Oct 05 '22 11:10

Learn OpenGL ES