Copy folder from Android app to local Windows directory

16,052

Solution 1

You're trying to gain read access to /data partition on actual android device. Such thing is not possible without root access, even if the app folder is yours. For the reason that permissions to read /data partition are not granted and cannot be granted, unless you're using an emulator. On emulator, which by default is with admin privileges for developer, you can access the data partition to read and write. On actual device you cannot. Not with adb, not with DDMS.

So basically speaking, anything that requires access to those files under /data is not going to work. Whether you sue cp command or pull command. The moment your kernel reads the beginning of your path which starts with /data/... it says: Oops, no can do.

Solution 2

You have almost solved the problem. As the storage of this kind is secured, you need to do one additional step. You need to copy the file from secured location to sdcard of the device. And then you can copy it anywhere via usb or android pull. Here are the command sequence I executed successfully.

adb shell
run-as DroidSample.DroidSample
cd shared_prefs
cp  DroidSample.DroidSample_preferences.xml /sdcard/DroidSample.DroidSample_preferences.xml
exit
exit
adb pull /sdcard/DroidSample.DroidSample_preferences.xml C:/test/

That's it.

And I really appreciate the way you posted your question. Best of luck.

Share:
16,052
testing
Author by

testing

Updated on June 04, 2022

Comments

  • testing
    testing almost 2 years

    I'm trying to use the Android Adb Command Prompt to copy a folder inside the app container to a local Windows folder. The device is running Android 5.1.1 and is not rooted.

    adb pull or cp aren't working. How can I copy a folder?

    The following approaches aren't working:

    Approach 1

    adb shell
    adb pull /data/data/DroidSample.DroidSample/files/MetroLog/MetroLogs C:/temp/test
    

    error: device not found

    Inside the shell you can't see to do adb pull. See here.

    Approach 2

    DDMS can't access the data folder.

    Approach 3

    adb shell
    run-as DroidSample.DroidSample
    cp /files/MetroLog/MetroLogs/ C:/temp/test
    

    cp: /files/MetroLog/MetroLogs/: No such file or directory

    Approach 4

    adb shell
    run-as DroidSample.DroidSample
    cp /data/data/DroidSample.DroidSample/files/MetroLog/MetroLogs/ C:/temp/test
    

    cp: /data/data/DroidSample.DroidSample/files/MetroLog/MetroLogs is a directory (not copied).

    This is also not working.

    Approach 5

    adb shell
    run-as DroidSample.DroidSample
    chmod 777 /files/MetroLog/MetroLogs
    exit
    exit
    adb pull /data/data/DroidSample.DroidSample/files/MetroLog/MetroLogs C:/temp/test
    adb shell run-as DroidSample.DroidSample
    chmod 700 /files/MetroLog/Metrologs
    

    remote object '/data/data/DroidSample.DroidSample/files/MetroLog/MetroLogs' does not exist

    So also this isn't working.

    Approach 6

    adb shell
    mkdir /sdcard/tmp
    cp /data/data/DroidSample.DroidSample/files/MetroLog/MetroLogs /sdcard/tmp
    

    cp: /data/data/DroidSample.DroidSample/files/MetroLog/MetroLogs: Permission denied

    This is also not working.

    Approach 7

    The only thing which half work is this

    adb exec-out run-as DroidSample.DroidSample cat "files/MetroLog/MetroLogs/Log - 20160509.log" > C:/temp/test/test.log
    

    But here I don't get the original file and I also have to know the exact file name. Additionally, that I loose line breaks and I have to do this for each file. Not that what I want.

    So I'm running out of ideas. How can I access the internal stored files and copy them over?

  • testing
    testing almost 8 years
    Here the question was explicitely of accessing files from data folder for unrooted devices. I was able to access a file from data folder with adb exec-out run-as com.packagename cat source > destination. Why does this work then?
  • daxgirl
    daxgirl almost 8 years
    It works on emulator. Not on actual device. It could never ever work on actual device. Neither you nor adb has read permissions for /data partition. View my answer.
  • testing
    testing almost 8 years
    Tried it on device again and it works. Perhaps it is because of Debug build?
  • daxgirl
    daxgirl almost 8 years
    May very well be but I doubt it. As of your original question, none of the methods you listed will work. No access to data partition can be granted to you.
  • Pavlus
    Pavlus over 6 years
    @testing yes, it's because of debug build
  • Amod Gokhale
    Amod Gokhale over 3 years
    This should be marked as answer.. works on non-rooted phone as well ( worked with debug version of app though ). not with live app