如何读取另一个应用程序的数据库 [英] How to read database of another application
问题描述
我正在使用有根的设备。
我从我的pc连接到adb shell,我可以验证其他数据库存在,我可以查询其表。
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.
但是在我的java代码当我尝试打开数据库时我收到错误
However in the my java code when I try to open the database I get error
android.database.sqlite.SQLiteException:无法打开数据库文件
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);
路径类似于/data/data/com.xxx.xxx/databases/xx.db
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?
我也试着让系统应用程序在这个线程中提供建议将我的apk推送到/ system / app
我认为这是可行的,因为应用程序无法从应用程序管理器像普通应用程序那样卸载,所以我认为它是一个系统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操作系统默认不允许应用程序访问彼此的私人文件夹。要能够读取另一个应用程序文件夹中的文件:
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)您需要使用相同的 code>。将它添加到以下两个清单中:
1) you need to have both applications installed using same user id
. Add this to both manifests:
android:sharedUserId="com.xx.xx"
2)如果其他应用程序是第三方应用程序,那么您唯一的选择是将应用程序安装为系统应用程序。要做到这一点,你需要一个有根的手机,你需要挂载 system
文件夹。然后,您需要将您的应用程序放入 / system / app /
文件夹,然后重新启动手机。它应该在启动期间自动安装。
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.
这篇关于如何读取另一个应用程序的数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!