Reputation: 1679
I have an app that uses a database (SQLite) in the assets folder which is copied into the data/data...folder on the android device. The problem is that the data inside the database is a train schedule that is updated every two months. To further complicate the matter, the data is online in five csv files that are zipped. I have written a java script that downloads, unzips, parses the data I need, builds the database, and populates it.
Is there a way to update (replace) the database in the assets folder? At that point a simple delete of the android app database will fire off a copy of the new data.
The real questions:
Ideas?
Upvotes: 1
Views: 455
Reputation: 2937
Okay, I'm just going to write out my thoughts in an answer instead of the comments.
Like CommonsWare said, you cannot update files in the assets/ dir. They are part of the APK, i.e., they are compiled into your app so you can replace the entire app or nothing at all.
You have a javascript to convert zipped csv files with the train schedule information files to a database that your app can use. I'm assuming that it is this database file that you put in assets/ and then build your app.
Since your app needs to refresh its data every so often it seems the most obvious to me to let your app download it. The thing that is downloaded should be the ready-to-use database, not the set of zipped csv files.
You can convert the zipped csv files into a database on your developement pc and then put that database file in the location where your app can download it.
A service for your app can be very simple. It just has to be a static file server, it does not need to be an API backend. If you rent a server then Nginx, Apache or IIS can do that out of the box for you. You can even do it without renting a server if you put the database file on Github or Dropbox.
When your app starts up, it checks if there's a newer version of the database file than what it currently has, and if so it downloads it. When completely downloaded it can run the same code that you have now for copying from assets/ to data/data but it does the copying from wherever it was downloaded to.
Upvotes: 2