Feb 25, 2013

Android Database

Seems the process to import an Android database isn't as simple as just dropping a SQLite database into your project. If the database doesn't reside in the "/data/data/<project name>/" directory, Android may have issues reading the database correctly. In addition, the primary key column names need to be "_id". Finally, there needs to be a table in the database that has some additional metadata:


CREATE TABLE "android_metadata" ("locale" TEXT DEFAULT 'en_US')
INSERT INTO "android_metadata" VALUES ('en_US')


What needs to be determined is how this will work in locales outside en_US.

Final thought is in regards to file size. It seems if you don't give the database a specific file extension, Android prior to 2.3 will not decompress assets in your APK if it is larger than 1MB. The 300k word dictionary looks to be about 6MB, so this would fall under that restriction. I'd have to rename it to something like "mp3", so that the android packaging tool will not try to compress it.

Note, copying the database over to the "/data/data" may only be necessary if the database is intended to be written - if the database is read-only, this may not be necessary. I'll need to investigate this further.

Helpful resources:



No comments:

Post a Comment