How can one pull the (private) data of one's own Android app?

前端 未结 14 1732
长发绾君心
长发绾君心 2020-11-30 16:44

Attempting to pull a single file using

adb pull /data/data/com.corp.appName/files/myFile.txt myFile.txt

fails with

failed          


        
相关标签:
14条回答
  • 2020-11-30 17:15

    Does that mean that one could chmod the directory from world:--x to world:r-x long enough to be able to fetch the files?

    Yes, exactly. Weirdly enough, you also need the file to have the x bit set. (at least on Android 2.3)

    chmod 755 all the way down worked to copy a file (but you should revert permissions afterwards, if you plan to continue using the device).

    0 讨论(0)
  • 2020-11-30 17:16

    After setting the right permissions by adding the following code:

    File myFile = ...;
    myFile.setReadable(true, false); // readable, not only for the owner
    

    adb pull works as desired.

    see File.setReadable()

    0 讨论(0)
  • 2020-11-30 17:18

    you can do:

    adb pull /storage/emulated/0/Android/data//

    0 讨论(0)
  • 2020-11-30 17:23

    Similar to Tamas's answer, here is a one-liner for Mac OS X to fetch all of the files for app with your.app.id from your device and save them to (in this case) ~/Desktop/your.app.id:

    (
        id=your.app.id &&
        dest=~/Desktop &&
        adb shell "run-as $id cp -r /data/data/$id /sdcard" &&
        adb -d pull "/sdcard/$id" "$dest" &&
        if [ -n "$id" ]; then adb shell "rm -rf /sdcard/$id"; fi
    )
    
    • Exclude the -d to pull from emulator
    • Doesn't stomp your session variables
    • You can paste the whole block into Terminal.app (or remove newlines if desired)
    0 讨论(0)
  • 2020-11-30 17:25

    Backed up Game data with apk. Nougat Oneplus 2.

    **adb backup "-apk com.nekki.shadowfight" -f "c:\myapk\samsung2.ab"**
    
    0 讨论(0)
  • 2020-11-30 17:28

    On MacOSX, by combining the answers from Calaf and Ollie Ford, the following worked for me.

    On the command line (be sure adb is in your path, mine was at ~/Library/Android/sdk/platform-tools/adb) and with your android device plugged in and in USB debugging mode, run:

     adb backup -f backup com.mypackage.myapp
    

    Your android device will ask you for permission to backup your data. Select "BACKUP MY DATA"

    Wait a few moments.

    The file backup will appear in the directory where you ran adb.

    Now run:

    dd if=backup bs=1 skip=24 | python -c "import zlib,sys;sys.stdout.write(zlib.decompress(sys.stdin.read()))" > backup.tar
    

    Now you'll you have a backup.tar file you can untar like this:

     tar xvf backup.tar
    

    And see all the files stored by your application.

    0 讨论(0)
提交回复
热议问题