2

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

Facundo Casco
  • 10,065
  • 8
  • 42
  • 63
kakka47
  • 3,479
  • 8
  • 44
  • 52
  • Are you creating the database from code? or you already had the sqlite file? – Cristian Dec 01 '10 at 17:39
  • I had it in the project, the only thing I did was to change the package name. When i access it from command prompt it is under its old package name. Is there a way to move it, or copy it? – kakka47 Dec 01 '10 at 18:00

1 Answers1

3

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:

Backup / Restore Sqlite to SDCard

UPDATE

One method, using the DDMS File explorer

  1. Navigate to data/data/com.old.package/databases
  2. Select the database file
  3. Click on the floppy disk with an arrow (top right of the file explorer)
  4. Save the file somewhere you know.
  5. Navigate to data/data/com.new.package/databases
  6. Click on the phone with an arrow.
  7. 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

Community
  • 1
  • 1
Scoobler
  • 9,696
  • 4
  • 36
  • 51
  • It is on the emulator. I have used the file explorer in Eclipse and I can see the database file under the path /data/data/com.example.package/databases. I read in the link you posted that "You can use getPath() on a SQLiteDatabase object to find out where it resides, AFAIK (haven't tried this)". The getPath should I use in the old project file then? I am very confused, there is no easy "copy"-funktion from the file-viewer? – kakka47 Dec 01 '10 at 18:21
  • Since I still have the original project, maybe it is easier to just change the package name there in order to be able to publish it? I tried to rename the package in a copy of the project and it didn't work. Anyone know what to think about when changing package names? – kakka47 Dec 01 '10 at 18:45
  • When you can see the DB file in the file explorer, there is a picture of a phone with a little red arrow, and a floppy disk with an arrow - one will save the file to the computer the other will allow you to push a file onto the emulator. If you copy the DB file from the old package path to your HDD, then copy the DB file from you HDD to the new package. – Scoobler Dec 01 '10 at 23:30