I repeat from another answer :
Starting from API level 8 (Android 2.2), if you are creating the application as a debugging application, you can use the shell run-as command to run the command or executable file as a specific user / application or simply switch to the UID your application so that you can access to his data directory.
So, if you want to pull your application database from the device, you must start the debug build of the application, connect to the adb shell and run the following command:
run-as com.yourpackage sh -c "cat ~/databases/db-file" > /sdcard/db-file.sqlite
This will copy your db-file to the root of your SD card / external storage. Now you can easily get it from there using the adb pull file manager or whatever you like. Please note that with this approach, it is not necessary for your application to have WRITE_EXTERNAL_STORAGE permission, since copying is performed by the shell user, who can always write to external memory.
On Linux / Mac systems, it is possible to copy the database directly to your computer using the following command, which can be used without entering the adb shell:
adb shell 'run-as com.yourpackage sh -c "cat ~/databases/db-file"' > db-file.sqlite
This, however, will not work correctly on Windows due to CR / LF character conversion. Use the old method there.
Idolon Dec 08 '11 at 16:45 2011-12-08 16:45
source share