开发者

Android SQLiteOpenHelper existing database

开发者 https://www.devze.com 2023-01-03 01:18 出处:网络
Newbie Q coming from iPhone/MonoTouch C# background I have an existing SQLite database file from another project.

Newbie Q coming from iPhone/MonoTouch C# background

I have an existing SQLite database file from another project.

Where do I include the database file into my Eclipse project to have it deploy with the app.

Do I need to indicate that the database file is writable? (In the iPhone world you ne开发者_StackOverflow中文版ed to copy the database file from the app's bundle to a writable folder on the iPhone proper before first use.)

Once I have the database file on the phone, how do I tell SQLiteOpenHelper to use it? (I extend SQLiteOpenHelper in a custom class.


Where do I include the database file into my Eclipse project to have it deploy with the app.

You can place the db file in either res/raw or assets/.

Do I need to indicate that the database file is writable? (In the iPhone world you need to copy the database file from the app's bundle to a writable folder on the iPhone proper before first use.)

With Android, you'll have to copy the file from your bundle into the app's database directory. Then, your app should be able to open the database using SQLiteOpenHelper as you would any other database created by your app.

To open the file (assuming you placed it in res/raw), call Resource.openRawResource(id) and to get the destination directory, call Context.getDatabasePath(filename). The database path might not exist, so you might need to create the parent directories first.

0

精彩评论

暂无评论...
验证码 换一张
取 消