如何读取另一个应用程序的数据库[英] How to read database of another application

本文是小编为大家收集整理的关于如何读取另一个应用程序的数据库的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

我正在使用扎根的设备. 我已经与PC上的ADB Shell连接了,我可以验证其他数据库存在,我可以查询其表.

但是,在我尝试打开数据库时,在我的Java代码中,我会得到错误

android.database.sqlite.sqliteException:无法打开数据库文件

我试图打开这样的数据库:

SQLiteDatabase.openDatabase(PATH, null, SQLiteDatabase.OPEN_READONLY);

路径像/data/data/com.xxx.xxx/databases/xx.db

我应该阅读其他应用程序的数据库或其他方法吗?

更新: 我还尝试按照此线程中的建议制作系统应用程序

我认为它有效,因为该应用程序之后无法卸载该应用程序像普通应用这样的应用程序管理器,因此我认为它是一个系统应用程序.但是,尽管我确定路径和权限还可以.

,我仍然无法访问数据库.

推荐答案

默认情况下,Android OS不允许应用程序访问彼此的私人文件夹.能够读取在其他应用程序文件夹中的文件:

1)您需要使用相同的user id安装两个应用程序.将其添加到两个清单中:

android:sharedUserId="com.xx.xx"

2)如果其他应用程序是第三方应用程序,则您唯一的选择是将应用程序安装为系统应用程序.为此,您需要一部扎根的手机,需要安装system文件夹.然后,您需要将应用程序放入/system/app/文件夹中,然后重新启动手机.它应该在引导过程中自动安装.

其他推荐答案

我假设设置了数据库文件上的权限,以使您的应用程序没有ACESS.即使您的设备扎根,也不意味着您的应用程序是作为root运行的.

其他推荐答案

这是因为应用程序需要root,并且需要更改您尝试访问的数据库的权限,以便实际访问它.您需要做的是,作为root,更改数据库的权限,以便每个人都可以访问它,在数据库上执行您想要的工作,关闭数据库并更改权限.

这确实规避了Android的安全性,因此请自负.您可以在:

上找到一个代码示例

>

本文地址:https://www.itbaoku.cn/post/597689.html

问题描述

I am working on a rooted device. I have connected with the adb shell from my pc and I can verify that the other database exists and I can query its tables.

However in the my java code when I try to open the database I get error

android.database.sqlite.SQLiteException: unable to open database file

I am trying to open the database like this:

SQLiteDatabase.openDatabase(PATH, null, SQLiteDatabase.OPEN_READONLY);

The path is something like /data/data/com.xxx.xxx/databases/xx.db

Am I supposed to read the databases of other applications like this or there is another way?

UPDATE: I also tried making the system app as adviced in this thread Push my apk to /system/app

I think it works because the app cannot be uninstalled after that from the applications manager like the ordinary apps so I think it is a system app. But still I cannot access the database though I am sure the paths and permissions are ok.

推荐答案

Android OS by default does not allow applications to access each others private folders. To be able to read files that are in another applications folder either:

1) you need to have both applications installed using same user id. Add this to both manifests:

android:sharedUserId="com.xx.xx"

2) If other app is a 3rd party app then your only choice is to install your app as system application. To do that you need a rooted phone and you need to mount the system folder. And then you need to put your application into /system/app/ folder and reboot the phone. It should be installed automatically during the boot.

其他推荐答案

I would assume that the permissions on the database files are set such that your application has no acess. Even if your device is rooted it doesn't mean that your application is running as root.

其他推荐答案

This is because the app needs root, and needs to change the permissions of the database you are trying to access so that you can actually access it. What you will need to do is, as root, change the permissions of the database so that everyone can access it, do what you would like on the database, close the database and change the permissions back.

This does circumvent security of android, so proceed at your own risk. You can find a code sample at:

http://rratmansky.wordpress.com/?p=259&preview=true