简体   繁体   English

如何使用adb将文件复制到可从PC访问的android目录

[英]How to copy file using adb to android directory accessible from PC

If you attach android device to PC you can browse files and dirs. 如果您将Android设备连接到PC,您可以浏览文件和目录。 It is possible to get this directory using Environment.getExternalStorage() . 可以使用Environment.getExternalStorage()获取此目录。 You can use it from your application and create accessible files and dirs. 您可以在应用程序中使用它并创建可访问的文件和目录。 It works fine. 它工作正常。

On my devices this path looks like /storage/emulated/0 and if i try adb push to this directory i will get access denied error. 在我的设备上,此路径看起来像/storage/emulated/0 ,如果我尝试adb push到此目录,我将获得访问被拒绝错误。 Is it possible to copy files using adb to the same folder as Windows Explorer does? 是否可以将使用adb的文件复制到与Windows资源管理器相同的文件夹中?

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)

I'm implementing automated import/export and i want files to be accessible without adb shell in case anything will go wrong. 我正在实现自动导入/导出,我希望在没有adb shell的情况下访问文件以防万一出错。

Currently using variable $EXTERNAL_STORAGE as workaround, it works for both adb and application. 目前使用变量$EXTERNAL_STORAGE作为解决方法,它适用于adb和应用程序。

Device: Asus Fonepad 7, Android 5.0, tried Genymotion Custom Tablet 6.0 - works. 设备:华硕Fonepad 7,Android 5.0,尝试了Genymotion Custom Tablet 6.0 - 工作。

Try to use /sdcard/ . 尝试使用/sdcard/ Although it is strongly discouraged to do this in code . 虽然强烈建议不要在代码中执行此操作 It seems to be the only way with adb : 这似乎是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

By the way, on my device they don't have the same value : Environment.getExternalStorage() points to /storage/emulated/0/ while /sdcard points to /storage/emulated/legacy . 顺便说一句,在我的设备上,它们没有相同的值: Environment.getExternalStorage()指向/storage/emulated/0//sdcard指向/storage/emulated/legacy

It's pretty easy, internal storage is unavailable on non-rooted devices. 这非常简单,内部存储在非root设备上不可用。 So as was mentioned in bwt answer you just need to push your data to sdcard : 正如bwt回答中提到的,你只需要将数据推送到SD卡:

adb push somefile /sdcard/somefile

With retrieving files from your filesystem you'll also have few problems. 通过从文件系统中检索文件,您也会遇到一些问题。 But with the case of pulling a database from a debug application - you'll just need to change file permission via chmod . 但是从调试应用程序中提取数据库的情况 - 您只需要通过chmod更改文件权限。 Here you have a useful link - XDA guys about adb 在这里你有一个有用的链接 - XDA的人关于adb

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM