Reputation: 2200
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.
Upvotes: 3
Views: 7466
Reputation: 841
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
Upvotes: 1
Reputation: 59168
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.
Upvotes: 9
Reputation: 95578
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.
Upvotes: 1