Win a copy of Terraform in Action this week in the Cloud forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

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

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic