0

I have an app where I've created the exact database schema that a client wants, so that I can import a CSV file - the database contents - into the application, then compile it to an APK and push it to the marketplace.

How is this done?

Jason Plank
  • 2,336
  • 5
  • 31
  • 40
JDS
  • 16,388
  • 47
  • 161
  • 224

1 Answers1

1

Ship the CSV file as asset resource (store it into assets folder) then copy it into database directory in the memory (don't forget to add permissions):

/data/data/packagename/databases/yourfile.csv

You do this for the first run of the app. Bear in mind that you need to test whether that file existed before (i.e. application has been run and the CSV file is copied in database directory). If not, then do the copy, if so, then do nothing, just proceed with operations, so you prevent losing data (if you copy on every start, you lose data). I hope this gives you the general idea.

Jason Plank
  • 2,336
  • 5
  • 31
  • 40
Nikola Despotoski
  • 49,966
  • 15
  • 119
  • 148
  • thanks for the help. Just to clarify: I want the import to work so that all I have to do in the main activity (Java code) is create the tables if they're not already there, and then use the data (list of rows to fit the schema) from the CSV file. Does the CSV file go somewhere in my Eclipse project package? The data/data/packagename/.../file.csv you posted looks like a directory on a single phone... I want the CSV file to be apart of the Eclipse package. Sorry for any misunderstandings on my part, thank you very much for the help so far. – JDS Aug 08 '11 at 22:52
  • There's actually a pretty comprehensive conversation about this topic [here](http://stackoverflow.com/questions/513084/how-to-ship-an-android-application-with-a-database) – Earl Aug 08 '11 at 22:53
  • You copy and paste it in the asset folder in your eclipse project, of course, then you copy it in the /data/data/blabla/databases/file.csv. Follow the link @Earl mentioned for further information. – Nikola Despotoski Aug 08 '11 at 22:57