Reputation: 6336
Ok I am learning to use databases in android and have follow several tutorials that have teach me a lot, now I know how to include a prepopulated database and copy it to the app at the moment of installing and opening the app for the first time, showing its content in a list view. I have made the database using SQLite Database Browser, so my question is how can I instead of including this prepopulated database in my app assets folder have it uploaded to my website and getting it from there so I can do updates to the database there and not having to update the app every time the items in the database change? Can I keep using SQLite Database Browser to create my database? any comment is greatly appreciated, if you can share a tutorial that can help me getting this accomplish is very welcome too. in advance Thank you.
Upvotes: 1
Views: 776
Reputation: 6336
My solution came from YouTube and some tutorials from mimirsoft. 1st I created a database with the mysql wizard, 2nd in phpadmin I created a table with all the information I need in my app 3rd created a php file that querys the data from the database and creates a json string that I can call from my app. 4th in my app I create the call for the php file from ky website, set an adapter and holder for the info to display in my list view. That's it! It works, if want to achieve something similar ask and I can provide some code. Plus you can check the next link where you can find mimirsoft tutorial on this subject. Part 1 http://m.youtube.com/watch?v=P3CwlckiLTU And part 2 http://m.youtube.com/watch?v=HTIYt07NDRo
Upvotes: 1
Reputation: 3153
There are several ways you can do this.
One way would be to have the SQLite database sitting on your web server. You can then make some kind of check to see if it is different from the database that you already have on your device. For example maybe you have a text file on your server as well and inside it has one line, being the version of the database. Inside your database you may have a table with one row that contains your current local version. You can then query your database for the version and compare it to the version in the text file. If the local database version is less than the one listed in the text file then scrap the local version and get the new version.
You can read the remote file by doing something like this:
URL myFileURL = null;
InputStream is = null;
String version = "";
try {
myFileURL = new URL("http://www.mywebsite.com/dbversionfile.txt");
is = myFileURL.openStream();
BufferedReader br = new BufferedReader(new InputStreamReader(is, "UTF-8"));
String line = "";
while((line = br.readLine()) != null) {
version = line;
}
} catch (Exception e) { }
A better solution than this would be to include a skeleton version of your database with your application. Just an empty database with all the appropriate tables. Then you can communicate with a PHP/Java/etc page on your web server and obtain a JSON string of any data not currently existing in your database. You may want to include a timestamp on each row of your data if you choose this method. This way you can do a query on your devices local database for the row with the most recent timestamp. If this timestamp is less than one returned from the database on your server then return all the rows greater than in JSON format.
You may want to research the Android JSONObject class if you want to use this method.
I'm sure there are other methods out there as well.
Upvotes: 0
Reputation: 71
Generate a sqlite dump file and import it in the database, replacing the necessary tables and data.
This is what I did in a web application, not a native aaplication, but it should work.
Upvotes: 0