Home > Software design >  How to push a file from computer to /data/.../databases/ using adb command?
How to push a file from computer to /data/.../databases/ using adb command?

Time:05-29

Below command is to pull a file:

adb -d shell "run-as com.myapp cat /data/data/com.myapp/databases/file.db" > file.db

But how to push it back like Android Studio does via Device File Explorer?

CodePudding user response:

There is no simple command for uploading the file. What Android Studio does when uploading a file using Device File Explorer is this:

  1. Upload the file via adb push to /data/local/tmp/<random file name>
  2. Execute adb shell run-as com.myapp sh -c 'cp /data/local/tmp/<random file name> /data/data/com.myapp/<path>/<final file-name>'
  3. Delete the temp file via adb shell rm /data/local/tmp/<random file name>
  4. Get the updated view for Device File Explorer using adb shell run-as com.myapp sh -c 'ls -al /data/data/com.myapp/<path>/'

I discovered this by capturing the adb traffic on TCP port 5027 using Wireshark. An interesting detail is that each command executed using adb shell command uses the form <command-to-be executed in adb shell> || echo ERR-ERR-ERR-ERR

CodePudding user response:

Use this command

adb push <file_path> <android_device_path>

adb pull <android_device_path>

  • Related