JDS
JDS

Reputation: 16978

How can I import a SQLite CSV file to my app?

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?

Upvotes: 0

Views: 1357

Answers (1)

Nikola Despotoski
Nikola Despotoski

Reputation: 50538

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.

Upvotes: 1

Related Questions