2

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.

Rich
  • 4,157
  • 5
  • 33
  • 45
  • You mean like a flash drive? Or do you mean within an application that you've created? – slim Dec 01 '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 01 '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 01 '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 01 '10 at 16:26
  • See http://stackoverflow.com/questions/3803871/android-apps-communicating-with-a-device-plugged-in-the-usb-port/6948992#6948992 – James Moore Aug 05 '11 at 15:25

1 Answers1

2

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)

Chris Stratton
  • 39,853
  • 6
  • 84
  • 117
  • 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 01 '10 at 16:04
  • 1
    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 01 '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 01 '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 01 '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 03 '10 at 13:19
  • Source is available, just not in the binary tarball. See android.git.kernel.org ADB itself is in platform/system/core.git but probably had dependencies from other packages – Chris Stratton Dec 03 '10 at 14:05