Android ADB access to application databases without root

Solution 1:

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

Solution 2:

A quick workaround is to use the run-as command to copy the database in a folder where you can have access, such as /sdcard and then, do a normal adb pull

adb shell
$ run-as package.name cp /data/data/package.name/dbname.db /sdcard/
$ exit
adb pull /sdcard/dbname.db

More information on the run-as command here

Note that the run-as command is available since API level 8 (Android 2.2) and can only be used if the application is debbugable.