0

I'm using Eclipse 3.7.0 to build my Android app. I saw the post that tells me that to access a file in external storage, I should create a path of the form Environment.getExternalStorageDirectory() + "/Android/data/" + getPackageName() + "/subfolder/myfile.xml". I also saw the post that tells me to check for the availability of the SD Card before continuing. All of that seems to make sense to me.

When the app is first installed, I'd like to set up the directory subfolder and place the file myfile.xml into that directory. How do I tell Eclipse to do that? I've created the file, but where do I place them on the Package Explorer? I tried in the root and in the assets directories, but neither of those seem to work.

Where are files that are placed into assets stored?

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
Chuck
  • 203
  • 6
  • 16

1 Answers1

0

For working with the assets, the AssetManager is the thing to use:

http://developer.android.com/reference/android/content/res/AssetManager.html

But this is totally different from working with the SD card. Files in the assets folder can be provided by yourself on compile time. The SD card is something you can't access during compile time but during runtime.

fkerber
  • 1,032
  • 9
  • 24
  • OK, I want to set up initial directories and files on the SD card. Can I make that happen when the app is installed? And how? – Chuck Aug 13 '12 at 16:19
  • The question is what you want to achieve with this files and where they come from. Of course you can create directories on SD card on first start of your app (or better said, test on every start and create if missing). – fkerber Aug 13 '12 at 16:21
  • The file is read by the app. By putting an initial file into place, I'm looking to set up a couple of default values. The default values may be deleted later by the user. I know how to check for them each time I start up the app, how would I do so on it's first start? – Chuck Aug 13 '12 at 16:25
  • Perhaps this can help you: http://stackoverflow.com/questions/2130932/how-to-create-directory-automatically-on-sd-card – fkerber Aug 13 '12 at 16:26
  • OK, that really spells out the mechanics of adding directories at rntime. I can put code into the `onCreate` of my splash screen that'll check that my drectories and files are there. If they aren't, it'll create them. You've implicitly answered my original question-I can't populate external storage folders and files in Eclipse simply by placing them into the Package Explorer's tree structure. Thanks! – Chuck Aug 13 '12 at 16:37