How can I access my Sqlite database after changing package name in Android?
In order to publish my Android app I had to change the package name from the com.example.project I had used during development. Although, after I changed the package name I cannot access the sqlite database any longer. I tried accessing it through the .adb, and it works with the old package-name but not the new one.
How can i access the db in order to put it under the new package? I have a copy of the old un-altered project file.
Many thanks! AK
Is this on the emulator or a phone? If you are developing on a phone and have built up a DB you want:
If the phone is rooted - use a file explorer (or DDMS views file explorer) and get it from /data/data/com.example.prackage/databases and place it in your new package folder.
If the phone isn't rooted - if you have the original package code, create a backup script to copy the sqlite file from the folder /data/data/com.example.prackage/databases - you will need to know the DB file name too. Then in the new package create the reverse of the code to copy the file from the SDCard to the new packages DB folder.
If on the emulator - use the DDMS views file explorer to get the file from the database folder.
This link may help with backup and restore:
One method, using the DDMS File explorer
- Navigate to data/data/com.old.package/databases
- Select the database file
- Click on the floppy disk with an arrow (top right of the file explorer)
- Save the file somewhere you know.
- Navigate to data/data/com.new.package/databases
- Click on the phone with an arrow.
- Find the file you just saved.
That should copy the DB to the new package so you can use it as you did before.
The above is a GUI for using the adb from a command prompt to copy the DB file from the old package to the new package, something like:
adb pull /data/data/com.example.package/databases C:\tempdb
That should make a copy of the old DB, then:
adb push C:\tempdb /data/data/com.example.package/databases