You are on page 1of 3

8/11/13

Android apps, communicating with a device plugged in the USB port - Stack Overflow

Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Tell me more

Android apps, communicating with a device plugged in the USB port

I'm thinking about an Android app (with possibly an accompanying physical device), and i'm trying to figure out whether this is something that's feasible. 1) Let's say I plug my Android to my PC. Would it be possible for an app installed on the PC to communicate with an app running in the cell phone? I just need a very simplistic data exchange, it can even be one-way (just data pushed from the cell phone to the listening app on the PC, whenever the cell phone wants, I don't need any data sent from PC to phone). When I plug it in, the phone gives me 4 options (charge, disk drive, HTC sync, tethering), which makes me think this is not doable, but still worth the shot. 2) Would it be possible for an app on the PC to talk to an app on the phone through any other way? (Wifi, bluetooth, etc). I'm guessing no on wi-fi since neither party has the other's IP (and I want this to kinda just work, not having to input IPs manually all the time). 3) If I make a device that's plugged to the little USB port at the bottom of the phone (and let's say this is a magical device that can do anything, I don't quite care about those details as long as it's doable). Can I have an Android app talk to that device? 4) Any other ideas to make the phone talk to a "device" that I make, or to an app in the PC are more than welcome. Going "through the web" could be an option (although there'd have to be a central server that I own as a middle man, I believe). But i'd prefer if the communication was direct between the two devices. Thank you very much for any ideas! Daniel
android usb communication wifi

asked Sep 27 '10 at 12:45 Daniel Magliola 7,265 19 79 153 add comment

5 Answers
The world has changed since this question was asked, and the answer is now the Android Open Accessory Development Kit. It won't solve the problem for existing usb devices, but it makes it possible to create new devices that can use an Android device's USB connection.
answered Aug 4 '11 at 21:50 James Moore 2,585 2 22 38 But not from a Windows PC as I read...? Zonata May 6 at 22:33 @Zonata I haven't used it, but developer.android.com/tools/adk/adk2.html claims Windows support. James Moore May 6 at 22:55 Thank, but I think I will go old school... I found a tutorial on socket forwarding which might interest others: qtcstation.com/2011/03/connecting-android-to-the-pc-over-usb Zonata May 6 at 22:59 add comment

stackoverflow.com/questions/3803871/android-apps-communicating-with-a-device-plugged-in-the-usb-port

1/3

8/11/13

Android apps, communicating with a device plugged in the USB port - Stack Overflow

For communication via usb/wlan take a look at this project: http://code.google.com/p/android-notifier/


answered Sep 27 '10 at 12:56 WarrenFaith 21k 8 45 77

android-notifier is not working in USB mode. Wifi and Bluetooth mode is supported. Mihir Feb 13 at 10:44

add comment

Let's say I plug my Android to my PC. Would it be possible for an app installed on the PC to communicate with an app running in the cell phone? Not really. There is no general-purpose channel of communication over USB. Would it be possible for an app on the PC to talk to an app on the phone through any other way? (Wifi, bluetooth, etc). Yes. I'm guessing no on wi-fi since neither party has the other's IP (and I want this to kinda just work, not having to input IPs manually all the time). I'm no expert on zeroconf, but that's at least conceivable for allowing your handshake sans any user input. If I make a device that's plugged to the little USB port at the bottom of the phone...Can I have an Android app talk to that device? Not without modifying firmware in Android, because there would be no driver. Not to mention the fact that few Android devices allow that USB port to operate in host mode.
answered Sep 27 '10 at 13:01 CommonsWare 308k 18 521 587

I spent like 6 months 3 years ago, trying to figure out how to connect an iPhone/other smart phone to a USB document scanner before determining that it couldn't be done. I was very annoyed... Brian Postow Sep 27 '10 at 13:15

add comment

If you turn on usb debugging on the phone and have something derived from the sdk's (open source) adb tool on the pc, they can communicate. The pc will have to initiate communications but within the sessions it can be mostly bidirectional or even mostly from device to pc. See developer.android.com about the adb shell and port forwarding. Root not required. People are using bluetooth to talk to arduino embedded controllers. With root I have made my phone act as a usb host, but it was a pain as I had to use wifi to get a debug shell since the usb was occupied. Some phones have a low voltage serial port on an extusb connector or audio lines, but root and a level shifter would be required to use this. Another idea I had been thinking of, doing a software modem on the headset jack, apparently has been done for both android and iphone by someone in Japan. This should not require root.
answered Sep 27 '10 at 13:37 Chris Stratton 17.8k 1 14 40

stackoverflow.com/questions/3803871/android-apps-communicating-with-a-device-plugged-in-the-usb-port

2/3

8/11/13

Android apps, communicating with a device plugged in the USB port - Stack Overflow
Thank you for your answer. My idea is to make this available to regular people. An app that'll be installed through the android market (at least the android side of the app). That implies no rooting, no usb debugging (i think), and nothing that my mom wouldn't be able to do. What you mention about bluetooth.... Does that imply rooting, or is it something my mom could do? Daniel Magliola Sep 27 '10 at 14:52

1 2

The headphone jack idea is interesting, for sure Daniel Magliola Sep 27 '10 at 14:53 Bluetooth serial (vs. earphone) may not work before a certain android version, and the hardware on the outside is expensive (like $20-30 in parts, up to $150 to get what is otherwise a $30 controller board with it integrated), but it shouldn't require root. Turning on USB debugging does not require root either, but yes, it's not for everyone. Basically you have a choice of hardware cost or user complexity. Chris Stratton Sep 27 '10 at 15:00

add comment

Communication between Android Device and PC is possible in one more way. Through ADB connection via USB. 1. Port Forwarding. 2. Server Socket JAVA Program. 3. Client Socket Android App. Through this app can communicate with the our JAVA Program running on PC. http://www.anothem.net/archives/2010/10/15/android-usb-connection-to-pc/
edited Jul 25 '12 at 13:28 answered Jul 25 '12 at 13:18 Noby 1,102 2 7 33

add comment

Not the answer you're looking for? Browse other questions tagged
communication wifi or ask your own question.

android usb

stackoverflow.com/questions/3803871/android-apps-communicating-with-a-device-plugged-in-the-usb-port

3/3

You might also like