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

Answers


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


Need Your Help

Styling select not displaying the same on Chrome or Firefox

html css css3

I'm having a problem styling a select box with Chrome and Safari, on Firefox works fine.

Items collection must be empty before using ItemsSource Error

c# wpf

How to add a delete column in datagrid in WPF, when i add this column, got Items collection must be empty before using ItemsSource Error

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.