tags:

views:

847

answers:

1

So far we have developed apps in android that create database on runtime. We like to know how can we access a pre-built or existing database/sqlite file in our android app? Please provide detail

A: 

Take a look at the documentation for android.database.sqlite.SQLiteDatabase.

In particular, there's an openDatabase() command that will access a database given a file path.

SQLiteDatabase db = SQLiteDatabase.openDatabase(path, null, 0);

Just specify the path to your database as the path variable, and it should work.

Trevor Johns
Suppose i have my db file in my assets folder then what path i will provide to the path variable?
Maxood
See this other, related question:http://stackoverflow.com/questions/513084/how-to-ship-an-android-application-with-a-databaseIn short, you can't do it directly. You need to copy the data out of your APK and into a new file in /data, then you can open it directly.This blog post has more information:http://www.reigndesign.com/blog/using-your-own-sqlite-database-in-android-applications/
Trevor Johns