Skip to main content

How to use Android Debug Bridge to copy data out of your Android device

I recently built an Android application that had the capability to export data in XML format to the devices external storage directory.

External storage directory path in Android OS can be accessed using the android.os.Environment package. Following code return the path for the external storage directory: 

Environment.getExternalStorageDirectory().getPath()

To copy data from this storage into your local device, you can use the Android Debug Bridge command line tool which comes installed with the Android SDK platform. 

The following command will pull a single file named filename.ext out of the device and copy it to your local computer:

adb pull /sdcard/filename.ext ./filename.ext

If you want to copy multiple files with certain extension to your local computer you can use Adb's shell command capability. 

The following command will pull all files with .xml extension to your local file for example:

adb shell ls /sdcard/*.xml | tr '\r' ' ' | xargs -n1 adb pull

You can also use adb and shell commands to get Sqlite3 data directory out of your device. Following command can be used to copy the entire Sqlite3 data directory into the devices external sdcard storage. 

adb -d shell 'run-as com.app cat /data/data/com.app/databases/dbname > /sdcard/dbname'

You can use the adb pull command to pull the export to your local computer. 

adb pull /sdcard/dbname ./dbname



Comments