Developing Android Apps: Connect to an Existing SQLite Database

This post was drafted some time ago, so some of the details are lost in the mists of time. But I’ll provide links to the source so anyone interested in doing something similar can start from there.

The android app I’m developing needs to be able to connect to an existing SQLite database, there are not many examples of how to achieve this in the Android tutorials, however I was able to find some guidance in a post from another Android developer on the reigndesign blog

The key is that the database needs to be copied internally to the system directory on the device running the application before it can be accessed. This doesn’t seem particularly efficient but I’m sure Android had their reasons! My modified version of the code to do this is available from my github repository here:

FootyLinksSQLLiteHelper.java

I’ve also encountered a couple of other snags since then while working with the SQLite database.

No password support

Passwords do not appear to be supported at all for the Android applications. I’d automatically added password protection to the database when creating it and it took me a while to figure out why eclipse was refusing to read it!

Manually delete after schema changes

I’ve added some additional fields to the database over time. However initially they were not being copied into the version of the database in my device emulator. I found it was necessary to browse the emulator files themselves, using the DDMS perspective in Eclipse, and delete the old database file directly in the emulator file system.

Comments

Copyright © 2016 - Hook Technologies Ltd - Powered by Octopress