Take the 2-minute tour ×

I've been able to find a few posts on StackOverflow about how to control USB devices using an Android phone -- which I understand is impossible (The Android being a USB device and all.)

However, I would be perfectly happy to set up my application to communicate with the other computer (a Linux host) as a USB device. (Like a really expensive mouse...)

Does anybody have information about how to set up an Android app/phone to use the USB connection and exchange data with a host computer. Obviously, it already works at some level -- it's how Eclipse and Android SDK/debugger do what they do, but I'm still looking for some way to do this in an application.

(My current phone, BTW, is a Droid Incredible.)

Thanks, R.

share|improve this question
You mean like a flash drive? Or do you mean within an application that you've created? –  shady Dec 1 '10 at 14:49
No, just a phone and a host computer (each running a custom app -- and no other USB hardware). I would like to exchange data between the app on the host computer and the app on the Android. Currently, I do this via TCP and UDP, but the parameters of the project have grown and I need to look for another way. –  Rich Dec 1 '10 at 14:57
What is wrong with networking protocols that you hope would be better with something else? What other type of system-to-system communication model would you prefer? Or is the problem not the protocol, but that you want to get away from wifi or 3g as a transport and use something local like USB? In that case, you probably still keep the network protocol as explained below. –  Chris Stratton Dec 1 '10 at 15:16
The only problem with WiFi is the potential for losing the link. In a situation where WiFi isn't working, I need to have an alternate solution. Thanks for the assist. –  Rich Dec 1 '10 at 16:26
add comment

1 Answer

up vote 2 down vote accepted

Basically you'd need to install the USB device driver and the ADB toolsuite from the SDK, either that or reverse engineer their functionality and build it into something else.

Then you enable USB debugging on the phone.

And then you can do something like an adb port forward to allow an application on the pc to connect to a network socket listener on the phone. Note that connections cannot be made in the other direction, but once a connection is made it is bidirectional.

If your version of android supports tethering over USB, you could also leverage that to implicitly create a network between the PC and the phone, at which point you can make connections in either direction. Just make sure nothing starts accidentally pumping lots of data through the phone's mobile network!

(Many android phones actually can experimentally function as USB hosts, but you have to compile new drivers into the kernel, install the new version, and make up a cable to provide USB power to the device as the phone cannot. Also you lose the ADB over USB channel which makes debugging a pain)

share|improve this answer
This is sounding helpful, but I want to clarify because you've posted a very general, full-bodied response... I'm thinking any reverse engineering is a last resort, and I definitely don't want to muck about with my phone's OS, so, 1) Install the Android SDK (with the USB driver and ADB) on my host computer and 2) Learn the ADB tricks that will allow me to network over the USB connection... Seriously, is that it?? Wow. Sadly, my phone's version of "tethering" is just bridging the WiFi to the cellular network, but at least I don't have a mobile network to worry about torking off... –  Rich Dec 1 '10 at 16:04
Yes, just install the sdk, enable adb, and read the docs on adb port forwards. You only need to reverse engineer the adb client if you need the host to be something where you can't use pieces of the actual sdk, say a small embedded system with a non-x86 processor for which you can't compile the current adb code. –  Chris Stratton Dec 1 '10 at 16:16
Sadly, that last sentence may just be what kicks us in the ass... Oh well, we'll see what we can do. –  Rich Dec 1 '10 at 16:24
In actuality, the code may be fairly portable to linux on various processors - some of the adb code is even common between the pc & the phone. Figuring out how to build just adb may be the hard part. –  Chris Stratton Dec 1 '10 at 19:31
I did a bit of searching and found android-sdk_r07-linux_x86.tgz (fairly easily). Unfortunately, I also found out my linux computer isn't working too well and needs attention -- but that's a different issue. What worries me is the 'x86' in the tarball's name -- it's leading me to doubt the ready availability of relevant source code... Ah well, thanks for the support. –  Rich Dec 3 '10 at 13:19
show 1 more comment

Your Answer


