如何使用 adb 将文件复制到可从 PC 访问的 android 目录
How to copy file using adb to android directory accessible from PC
如果您将 android 设备连接到 PC,您可以浏览文件和目录。可以使用 Environment.getExternalStorage()
获取此目录。您可以在您的应用程序中使用它并创建可访问的文件和目录。它工作正常。
在我的设备上,此路径看起来像 /storage/emulated/0
,如果我尝试 adb push
到此目录,我将收到拒绝访问错误。是否可以使用 adb
将文件复制到与 Windows Explorer 相同的文件夹?
D:\...\tools>adb push ACCOUNTS.DB /storage/emulated/0
failed to copy 'ACCOUNTS.DB' to '/storage/emulated/0': Permission denied
58969 KB/s (606505 bytes in 0.010s)
我正在实施自动化 import/export,我希望无需 adb shell
即可访问文件,以防出现任何问题。
目前使用变量$EXTERNAL_STORAGE
作为解决方法,它适用于 adb
和应用程序。
设备:Asus Fonepad 7,Android 5.0,尝试过 Genymotion Custom Tablet 6.0 - 有效。
尝试使用/sdcard/
。尽管在 code 中强烈建议不要这样做。这似乎是 adb 的唯一方法:
$ adb push somefile /storage/emulated/0/somefile
[100%] /storage/emulated/0/somefile
adb: error: failed to copy 'somefile' to '/storage/emulated/0/somefile': Read-only file system
$ adb push somefile /sdcard/somefile
[100%] /sdcard/somefile
顺便说一句,在我的设备上它们没有相同的值:Environment.getExternalStorage()
指向 /storage/emulated/0/
而 /sdcard
指向 /storage/emulated/legacy
.
这很简单,内部存储在非 root 设备上不可用。因此,正如 中提到的,您只需将数据推送到 sdcard 即可:
adb push somefile /sdcard/somefile
从您的文件系统中检索文件也不会遇到什么问题。但是对于从调试应用程序中提取数据库的情况 - 您只需要通过 chmod
更改文件权限。
这里有一个有用的 link - XDA guys about adb
如果您将 android 设备连接到 PC,您可以浏览文件和目录。可以使用 Environment.getExternalStorage()
获取此目录。您可以在您的应用程序中使用它并创建可访问的文件和目录。它工作正常。
在我的设备上,此路径看起来像 /storage/emulated/0
,如果我尝试 adb push
到此目录,我将收到拒绝访问错误。是否可以使用 adb
将文件复制到与 Windows Explorer 相同的文件夹?
D:\...\tools>adb push ACCOUNTS.DB /storage/emulated/0
failed to copy 'ACCOUNTS.DB' to '/storage/emulated/0': Permission denied
58969 KB/s (606505 bytes in 0.010s)
我正在实施自动化 import/export,我希望无需 adb shell
即可访问文件,以防出现任何问题。
目前使用变量$EXTERNAL_STORAGE
作为解决方法,它适用于 adb
和应用程序。
设备:Asus Fonepad 7,Android 5.0,尝试过 Genymotion Custom Tablet 6.0 - 有效。
尝试使用/sdcard/
。尽管在 code 中强烈建议不要这样做。这似乎是 adb 的唯一方法:
$ adb push somefile /storage/emulated/0/somefile
[100%] /storage/emulated/0/somefile
adb: error: failed to copy 'somefile' to '/storage/emulated/0/somefile': Read-only file system
$ adb push somefile /sdcard/somefile
[100%] /sdcard/somefile
顺便说一句,在我的设备上它们没有相同的值:Environment.getExternalStorage()
指向 /storage/emulated/0/
而 /sdcard
指向 /storage/emulated/legacy
.
这很简单,内部存储在非 root 设备上不可用。因此,正如
adb push somefile /sdcard/somefile
从您的文件系统中检索文件也不会遇到什么问题。但是对于从调试应用程序中提取数据库的情况 - 您只需要通过 chmod
更改文件权限。
这里有一个有用的 link - XDA guys about adb