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

AndroidUsbCommunicationWifi

Android Problem Overview


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.

  1. Would it be possible for an app on the PC to talk to an app on the phone through any other way? (Wi-fi, 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).

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

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

Android Solutions


Solution 1 - Android

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.

Solution 2 - Android

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/

Solution 3 - Android

Edit: Please note this answer predates the availability of the Android USB host and accessory APIs and support found in many devices released after it was written.

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.

Solution 4 - Android

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionDaniel MagliolaView Question on Stackoverflow
Solution 1 - AndroidJames MooreView Answer on Stackoverflow
Solution 2 - AndroidNobyView Answer on Stackoverflow
Solution 3 - AndroidChris StrattonView Answer on Stackoverflow
Solution 4 - AndroidWarrenFaithView Answer on Stackoverflow