http://www.reigndesign.com/blog/using-your-own-sqlite-database-in-android-
applications/
Most all of the Android examples and tutorials out there assume you want to create
and populate your database at runtime and not to use and access an independent,
preloaded database with your Android application.
The method I'm going to show you takes your own SQLite database file from the
"assets" folder and copies into the system database path of your application so the
SQLiteDatabase API can open and access it normally.
)
1. Preparing the SQLite database file.
Assuming you already have your sqlite database created, we need to do some
modifications to it.
If you don't have a sqlite manager I recommend you to download the
opensource)SQLite Database Browser)available for Win/Linux/Mac.
Open your database and add a new table called "android_metadata", you can
execute the following SQL statement to do it:
CREATETABLEDEFAULT
Now insert a single row with the text 'en_US' in the "android_metadata" table:
INSERTINTOVALUES
Then, it is necessary to rename the primary id field of your tables to "_id" so Android
will know where to bind the id field of your tables.
You can easily do this with)SQLite Database Browser)by pressing the edit table
button) , then selecting the table you want to edit and finally selecting the field
you want to rename.
After renaming the id field of all your data tables to "_id" and adding the
"android_metadata" table, your database it's ready to be used in your Android
application.
评论16