0

I know that when i run in an emulator, the db file can be viewed, pushed and pulled at data/data/com.appname/databases/db.sql

but that is using emulator, what if i run using an android phone? how do i push the db file? please help me by providing clear tutorial! thanks in advance!

I have been reading answers from existing similar question like this:

Access the phone internal storage to push in SQLite database file

but I dont understand how to do it. where to put the code and etc and also when I launch my app, it will be able to access the database file and retrieve the data to display them in my apps

Community
  • 1
  • 1
Chrisantics
  • 165
  • 2
  • 16
  • You should place in assets and access it on the first time you open the app, ../databases/.. via code... possible duplicate of [How to ship an Android application with a database?](http://stackoverflow.com/questions/513084/how-to-ship-an-android-application-with-a-database) – VenomVendor Apr 15 '14 at 02:59
  • @VenomVendor I did try the code provided in the https://github.com/jgilfelt/android-sqlite-asset-helper but when creating the class public class MyDatabase extends SQLiteAssetHelper{...} it says that cannot resolve symbol 'SQLiteAssetHelper' and it is red in color. and fyi, I am using Android studio – Chrisantics Apr 15 '14 at 03:56
  • 1
    https://github.com/jgilfelt/android-sqlite-asset-helper/tree/master/library/src/main/java/com/readystatesoftware/sqliteasset have you imported this library, if not import it. – VenomVendor Apr 15 '14 at 05:20

2 Answers2

0

If you have an .sqlite (not .sql), you should take out the extension of the file and then paste it in the assets folder of your project.

Try this question. It goes with all the specifics of how to read an already built database in your app.

But in summary, you have to create your own class (DataBaseHelper) that extends SQLiteOpenHelper to read or create the database.

Community
  • 1
  • 1
Luis Lavieri
  • 4,064
  • 6
  • 39
  • 69
0

I have stumbled upon a way of importing the database file say if we already have an existing db file (don't have to recreate it). And this tutorial helped me a lot!!!

http://www.reigndesign.com/blog/using-your-own-sqlite-database-in-android-applications/

Chrisantics
  • 165
  • 2
  • 16