在 Android 中更改包名称后如何访问我的 Sqlite 数据库?

发布于 2024-10-05 09:58:27 字数 198 浏览 0 评论 0原文

为了发布我的 Android 应用程序,我必须更改我在开发过程中使用的 com.example.project 中的包名称。 虽然,在我更改包名称后,我无法再访问 sqlite 数据库。我尝试通过 .adb 访问它,它适用于旧的包名称,但不适用于新的包名称。

我如何访问数据库以便将其放在新包下?我有一份未更改的旧项目文件的副本。

非常感谢! AK

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

—━☆沉默づ 2024-10-12 09:58:27

这是模拟器上的还是手机上的?如果您正在手机上进行开发并已构建了所需的数据库:

  • 如果手机已 root - 使用文件浏览器(或 DDMS 视图文件浏览器)并从 /data/data/com 获取它。 example.prackage/databases 并将其放入新的包文件夹中。

  • 如果手机未 root - 如果您有原始包代码,请创建一个备份脚本以从文件夹 /data/data/com.example.prackage/databases 复制 sqlite 文件 - 您还需要知道数据库文件名。然后在新包中创建相反的代码,将文件从 SDCard 复制到新包 DB 文件夹。

  • 如果在模拟器上 - 使用 DDMS 视图文件资源管理器从数据库文件夹中获取文件。

此链接可能有助于备份和恢复:

备份/恢复 Sqlite 到 SDCard

更新

一种方法,使用 DDMS 文件资源管理器

  1. 导航到 data/data/com.old.package/databases
  2. 选择数据库文件
  3. 单击带有箭头的软盘(文件资源管理器的右上角)
  4. 将文件保存在您知道的地方。
  5. 导航至 data/data/com.new.package/databases
  6. 单击带有箭头的手机。
  7. 找到您刚刚保存的文件。

这应该将数据库复制到新包中,以便您可以像以前一样使用它。

上面是一个 GUI,用于在命令提示符下使用 adb 将数据库文件从旧包复制到新包,例如:

adb pull /data/data/com.example.package/databases C:\ tempdb

应该复制旧数据库,然后:

adb push C:\tempdb /data/data/com.example.package/databases

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文