如何使用ADB命令将文件从计算机推送到/Data/.../databases/?

发布于 2025-02-02 02:28:07 字数 176 浏览 2 评论 0原文

下面的命令是提取文件:

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

但是如何像Android Studio通过设备文件资源管理器一样将其推回?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

旧夏天 2025-02-09 02:28:07

没有简单的命令可以上传文件。 Android Studio使用设备文件资源管理器上传文件时会做什么:

  1. 通过adb push/data/local/tmp/<随机文件名>
  2. eccodute adb shell run-as 上传文件。 com.myapp sh -c'cp/data/local/tmp/<随机文件名> /data/data/com.myapp//path ;/> final file-name>'
  3. 通过adb shell shell rm/data/local/tmp/tmp/tmp/tmp< andy files>
  4. 使用adb shell run -as com.myapp sh -c'ls -al/data/data/com.myapp/com.myapp/<;

我通过使用Wireshark在TCP端口5027上捕获ADB流量来发现这一点。一个有趣的细节是,使用adb shell命令执行的每个命令使用form &lt;命令 - 命令在adb shell&gt;中执行。 || Echo Err-err-err-err

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 /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

离旧人 2025-02-09 02:28:07

使用此命令

adb push&lt; file_path&gt; &lt; android_device_path&gt; gt;

adb pull&lt; android_device_path&gt; gt;

Use this command

adb push <file_path> <android_device_path>

adb pull <android_device_path>

素罗衫 2025-02-09 02:28:07

从罗伯特的答案中,我可以这样做:

function dbpull() {
    adb shell run-as "com.$1.debug" cat "/data/data/com.$1.debug/databases/$2.db" > "/Users/username/Desktop/$2.db"
}
function dbpush() {
    adb push "/Users/username/Desktop/$1.db" "/sdcard/db/tmp/"
}
function dbpush2() {
    adb shell run-as "com.$1.debug" cp "/sdcard/db/tmp/$2.db" "/data/data/com.$1.debug/databases/$2.db"
}
function dbcheck() {
    adb shell run-as "com.$1.debug" ls -al "/data/data/com.$1.debug/databases/"
}

只需在您的 .bash_profile 中写上述代码行,然后在终端中调用它。

dbpull myapp mydata

目前,我更喜欢使用Visual Studio代码,而不是Android Studio来开发我的Android应用程序。因此,我需要更多地了解终端中的命令,例如ADB,Gradle等。

我希望这对每个人都有用。

From Robert's answer now I can do like this:

function dbpull() {
    adb shell run-as "com.$1.debug" cat "/data/data/com.$1.debug/databases/$2.db" > "/Users/username/Desktop/$2.db"
}
function dbpush() {
    adb push "/Users/username/Desktop/$1.db" "/sdcard/db/tmp/"
}
function dbpush2() {
    adb shell run-as "com.$1.debug" cp "/sdcard/db/tmp/$2.db" "/data/data/com.$1.debug/databases/$2.db"
}
function dbcheck() {
    adb shell run-as "com.$1.debug" ls -al "/data/data/com.$1.debug/databases/"
}

Just write above code lines in your .bash_profile and then call it in terminal.

dbpull myapp mydata

At this moment I prefer to use Visual Studio Code than Android Studio to develop my Android apps. So, I need to know more about commands in terminal, e.g. adb, gradle, etc.

I hope this would be useful for everyone.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文