Copy a (db) file from an installed Android apk

I've been looking at doing some performance tuning on a troublesome sql query on a sqlite db on an Android app and wanted tocopy the actual db to do some testing in an IDE.

It took a long time reading various SO articles to find something that worked, but eventually found this (answer from Triplee).

Basically you need to run adb shell, run-as the package to impersonate the permissions, then use cat to pipe the file to another location on the device (sdcard which is available on the emulator), then use adb pull to copy to the host machine, so steps are:

  1. Open adb command prompt (you can do this through Visual Studio)
  2. adb shell
  3. run-as
  4. cat foldername/dbfilename.db > /sdcard/dbfilename.db
  5. exit
  6. exit
  7. adb pull /sdcard/dbfilename.db "c:\users\youruser\desktop\dbfilename.db"

Works nicely!