Android ADB access to application databases without root

Scoobler picture Scoobler · Jan 16, 2010 · Viewed 46.3k times · Source

Can anyone tell me, is it possible to use the ADB to pull and push a database from an app, without root privileges on the phone?

For example, I know the location on my rooted magic and dream is:

/data/data/com.xxxx.xxxx/databases/xxxx

I know that you can use ADB without root, but when trying to use the shell - you can't view that location without root privaliges. But I have been told you can use push and pull if you know the file you want?

Basically I want to pull a database from MY app on a non rooted phone modify it and push it back on.

Only trouble I have is, the two phones I have are both root and I don't have access to a non root one to try it out.

Answer

Pilot_51 picture Pilot_51 · Jun 18, 2013

While Nilhcem's answer didn't work for me, it lead me in the right direction (for that I upvoted) and I now have a working solution.

Old answer that may not work with newer versions of Android:

#Transfer file from app databases directory to PC
adb shell
$ run-as package.name
$ cd ./databases/
$ ls -l #Find the current permissions - r=4, w=2, x=1
$ chmod 666 ./dbname.db
$ exit
$ exit
adb pull /data/data/package.name/databases/dbname.db ~/Desktop/

#Transfer file from PC to app databases directory (requires the above permission change)
adb push ~/Desktop/dbname.db /data/data/package.name/databases/dbname.db
adb shell
$ run-as package.name
$ chmod 660 ./databases/dbname.db #Restore original permissions
$ exit
$ exit

Alternate method using external storage (confirmed to work with 6.0.1):

#Transfer file from app databases directory to external storage
adb shell
$ run-as package.name
$ cp ./databases/dbname.db /sdcard/
$ exit
$ exit

#Transfer file from external storage to app databases directory
adb shell
$ run-as package.name
$ cp /sdcard/dbname.db ./databases/
$ exit
$ exit