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
?
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
When you create a database by utilizing the SQLiteDatabase
or SQLiteOpenHelper
classes, it creates the database in your data/data/package_name/database
.
You can access that resource by using
InputStream myInput = myContext.getAssets().open(your_database_here);
Any other information, look at Using your own SQLite database in Android Applications
The package_name
portion of the path, would be the name of your package. You can find the name of the package at the first line in your .java
files.
As an example, my class starts with this at the top
package com.forloney.tracker;
So my database is in data/data/com.forloney.tracker/database
folder.
Hope this makes sense.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With