0

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?

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

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.

stealthjong
  • 10,858
  • 13
  • 45
  • 84
  • I am able to save a String with about 4.000 characters via `Log.i()`. From Eclipse you can export selected Log statements to a file. – Simulant Jan 23 '14 at 11:39
  • Yeah, couple'eh hundred, 4.000, it doesn't make much of a difference when receiving 2.000.000 character SOAP responses. and exporting selected Log statements is limited to the 4.000 characters. – stealthjong Jan 23 '14 at 11:57
  • You obviously do not understand how `adb` works. You can't initiate any transfers from the device side. I mean you could but there will be no software on PC side expecting it. – Alex P. Jan 23 '14 at 21:30
  • @AlexP. You obviously did not read my post. If you read it, you'd see that I do not expect it to be possible, but "it's worth a shot". So why my curiosity is worth a downvote, I do not understand. – stealthjong Jan 23 '14 at 21:58

3 Answers3

1

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.

To answer your question: No, this is not possible. It's not how adb works. Even if you could "push" from Android to PC, you need a piece of software to handle the data. Android does not contain any API which makes that possible, and neither does any part of the 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).

Hope this clarifies a bit.

MC Emperor
  • 22,334
  • 15
  • 80
  • 130
0

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.

Harish Talanki
  • 866
  • 13
  • 27
  • As you could've read, I do know about pulling and pushing, but I want to specifically push from the Android device to the pc (the Android device should initiate). – stealthjong Jan 23 '14 at 12:03
  • I didn't do it, neither do I understand it. However, as you could've already read, I am quite aware of adb pulling, and I do it quite frequently as well. My specific question was whether or not adb can work in the other direction, that is android -> pc instead of the other way around. – stealthjong Jan 24 '14 at 07:44
0

You can push files from ADB to PC (eclipse).

In Eclipse Window-Open Perspective-DDMS

and then in DDMS view select your device from the left side list.

and in the Right side view, you will find a folder called mnt, inside it you will find sd card. There are your files. your devices files. Now to get them out to your 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.

Sandeep R
  • 2,284
  • 3
  • 25
  • 51