How does android access a sqlite database included in the assets folder

android, sqlite

Solution

The package name is not the project name, the package name is the namespace. From Anthony's link.

Remember to change the "YOUR_PACKAGE" to your application package namespace (i.e: com.examplename.myapp) in the DB_PATH string.

For example, from the Hello World tutorial, the project name is `HelloAndroid` but the package name is `com.example.helloandroid`

If this application had a database, it would be stored at `data/data/com.example.helloandroid/database`

To see how it is for the other applications you can start your emulator. On the menu bar you have your avd's name (I think it stands for Android Virtual Device). On mine it s "avdessay:5554"

(On Linux) From command line, type:

`adb -s emulator-5554 shell`

You have to replace 5554 by whatever port you are using.

if you have the command prompt '#' you can type:

`cd data/data`

There, you will see that eveything is in a form of a package name.

More info here

Problem

I already have a SQLite database. I put it in the `assets` folder of my project. I read the Android documentation. It said that for all the databases in Android, the path is `data/data/pack_name/database_name`. This confused me. I just placed it in the `assets` folder, so the path is `data/data/assets/database_name`?

Original source