简体   繁体   English

通过ADB将文件从Android推送到PC

[英]Push files from Android to PC over ADB

It's probably not possible due to safety issues and many other reasons, but it's worth a shot, so here goes: 由于安全问题和许多其他原因,这可能是不可能的,但是值得一试,所以这里是:

Is it possible to push files from an Android device directly to a computer using ADB? 是否可以使用ADB将文件从Android设备直接推送到计算机?

Why would you want that, you might ask. 您可能会问,为什么要这样。 Good question. 好问题。 I find it useful to view larger Strings on a computer instead of on an Android device, especially since Log.d() won't show Strings of a length more of a couple hundred characters. 我觉得有用查看大Strings的计算机上,而不是在Android设备上,特别是因为Log.d()将不会显示Strings的长度更几百个字符。 Things like SOAP requests and responses, other xml files are not easily viewable on my Nexus 7. I've tried some things with the UsbManager class and the UsbDevice class, but I can't seem to find the USB-connection to my computer. 在Nexus 7上不容易查看诸如SOAP请求和响应之类的内容以及其他xml文件。我曾尝试使用UsbManager类和UsbDevice类进行某些操作,但似乎找不到与计算机的USB连接。

PS. PS。 I can think of other methods, like using a logging webservice, for all I care, or writing a script which pulls a certain (log) directory periodically, but I'm just curious whether or not it is possible, it makes my life ever so slightly easier. 我可以想到其他方法,例如使用记录式Web服务,就我所关心的事情,或编写脚本来定期拉取某个(日志)目录,但是我很好奇是否可能,它使我的生活永远所以稍微容易一些。

As I can read in your question, you are quite aware of the fact that you can pull files from your Android device to your PC, so I won't suggest that. 正如我在您的问题中所看到的那样,您非常清楚可以将文件从Android设备拉到PC的事实,因此我不建议这样做。

To answer your question: No , this is not possible. 要回答您的问题: ,这是不可能的。 It's not how adb works. 这不是adb工作方式。 Even if you could "push" from Android to PC, you need a piece of software to handle the data. 即使您可以从Android“推”到PC,也需要一个软件来处理数据。 Android does not contain any API which makes that possible, and neither does any part of the Android SDK. Android不包含任何可能的API,Android SDK的任何部分也不包含。

Still you could use any of the methods you already know of ( adb pull , Eclipse DDMS View, and yes, even a logging webservice, as you yourself suggested). 仍然可以使用任何已知的方法( adb pull ,Eclipse DDMS View,是的,甚至可以按照您自己的建议使用日志记录Web服务)。

Hope this clarifies a bit. 希望这可以澄清一点。

To copy a file or directory (and its sub-directories) from the emulator or device, use 要从仿真器或设备复制文件或目录(及其子目录),请使用

adb pull <remote> <local>

For more details on the usage, refer this link 有关用法的更多详细信息,请参阅链接

EDIT: What I understand is that you want your app to pull a particular file right? 编辑:据我了解,您希望您的应用正确提取特定文件吗? If yes, you need to use 如果是,则需要使用

public class YourAppCode {
    public static void main(String[] args) throws Exception {
        Runtime runtime = Runtime.getRuntime();
        Process process = runtime.exec(new String[] {"/usr/bin/adb", "devices");
    }
}

Instead of devices, you need to send pull command along with the source and destination. 您需要发送拉命令以及源和目标,而不是设备。

You can push files from ADB to PC (eclipse). 您可以将文件从ADB推送到PC(Eclipse)。

In Eclipse Window-Open Perspective-DDMS 在Eclipse 窗口中-Open Perspective-DDMS

and then in DDMS view select your device from the left side list. 然后在DDMS视图中,从左侧列表中选择您的设备。

and in the Right side view, you will find a folder called mnt , inside it you will find sd card. 在右侧视图中,您将找到一个名为mnt的文件夹,在其中将找到sd卡。 There are your files. 有您的文件。 your devices files. 您的设备文件。 Now to get them out to your pc 现在将它们发送到您的PC

There are two buttons on the right side top. 右侧顶部有两个按钮。 one button says pull a file from device another button says push a file to device 一个按钮表示从设备中提取文件,另一个按钮表示将文件推送至设备

You need pull the file from device. 您需要从设备中提取文件。 Select your respective file and click the pull a file from device button. 选择您各自的文件,然后单击从设备中提取文件按钮。

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

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