Skip to content Skip to sidebar Skip to footer

How Can I Pull Databases Off My Android Onto My Desktop?

I'm trying this with my Nexus One. I have the android SDK and have used the command adb pull /data/data/com.myapp.android/databases C:\pulls but all I get is pull: building file

Solution 1:

Accessing internal storage is not possible unless your phone is rooted. One simple way is to use the emulator, and then you can get at the files. For getting a database off the device I wrote a little utility and put in some debug UI for it:

privatevoidbackupDb()throws IOException {
    Filesd= Environment.getExternalStorageDirectory();
    Filedata= Environment.getDataDirectory();

    if (sd.canWrite()) {

        StringcurrentDBPath="/data/com.yourcompany.yourapp/databases/yourapp.db";
        StringbackupDBPath="/yourapp_logs/yourapp.db";

        FilecurrentDB=newFile(data, currentDBPath);
        FilebackupDB=newFile(sd, backupDBPath);

        if (backupDB.exists())
            backupDB.delete();

        if (currentDB.exists()) {
            makeLogsFolder();

            copy(currentDB, backupDB);
       }

        dbFilePath = backupDB.getAbsolutePath();
   }
}

 privatevoidmakeLogsFolder() {
    try {
        FilesdFolder=newFile(Environment.getExternalStorageDirectory(), "/yourapp_logs/");
        sdFolder.mkdirs();
    }
    catch (Exception e) {}
  }

privatevoidcopy(File from, File to)throws FileNotFoundException, IOException {
    FileChannelsrc=null;
    FileChanneldst=null;
    try {
        src = newFileInputStream(from).getChannel();
        dst = newFileOutputStream(to).getChannel();
        dst.transferFrom(src, 0, src.size());
    }
    finally {
        if (src != null)
            src.close();
        if (dst != null)
            dst.close();
    }
}

Solution 2:

Create a "pull.bat" file in your windows desktop.

In the file put:

db pull /data/com.APPNAME/databases/DBNAME.sqlite
pause

Solution 3:

If you are using MAC or Linux try this script. This doesn't require root permissions

#!/bin/bash

REQUIRED_ARGS=2
ADB_PATH=/Users/Tadas/Library/sdk/platform-tools/adb
PULL_DIR="~/"if [ $# -ne $REQUIRED_ARGS ]
    thenecho""echo"Usage:"echo"android_db_move.sh [package_name] [db_name]"echo"eg. android_db_move.sh lt.appcamp.impuls impuls.db"echo""exit 1
fi;


echo""

cmd1="$ADB_PATH -d shell 'run-as $1 cat /data/data/$1/databases/$2 > /sdcard/$2' "
cmd2="$ADB_PATH pull /sdcard/$2$PULL_DIR"echo$cmd1eval$cmd1if [ $? -eq 0 ]
    thenecho".........OK"fi;

echo$cmd2eval$cmd2if [ $? -eq 0 ]
    thenecho".........OK"fi;

exit 0

Post a Comment for "How Can I Pull Databases Off My Android Onto My Desktop?"