• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What's the real purpose of the /data/data/{application_package} directory?

 
Siju Odeyemi
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I'm using /data/data/{application_package}/files to store and load "user supplied" files needed in my application.

This works fine in my emulators but I just looked on my HTC phone and though it has the /data directory there is nothing inside it. I would have guessed that each application would have a private space in there automatically on installation as per "/data/data/{application_package}" but this is not the case.

PROBLEM: My application will obviously fail if I installed it on a real device (i.e. FileNotFoundException thrown due to directory literally not existing on the phone) EXCEPT I explicitly create the directory structure myself (in code) during the first run of the application. This seems like a bit of a hack to me. Has anyone else had to work with these directories? Any insights?

Thanks in advance.
 
Siju Odeyemi
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Finally solved this problem. The method getFilesDir() in the ContextWrapper class in the Android API returns the app data directory without you having to hardcode it:



The code above effectively returns the right dir preventing any errors from surfacing as a result of different phones using different locations. Joy.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic