Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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? (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).

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.

like image 313
Daniel Magliola Avatar asked Sep 27 '10 12:09

Daniel Magliola


People also ask

How do I get USB permissions on Android?

When you connect USB the first time (with already installed app), system call permission dialog. Then another time at start app usb will get permission automatically.

How do I change USB mode on Android?

From the Home screen, touch and hold the Recent Apps Key (in the Touch Keys bar) > Settings > Storage > the Menu icon (at the upper-right corner of the screen) > USB PC connection. Tap Media sync (MTP), Internet connection, or Camera (PTP) to connect to the PC.

What is Android USB connection?

Older Android devices support USB mass storage for transferring files back and forth with a computer. Modern Android devices use the MTP or PTP protocols — you can choose which one you prefer. To select a USB connection protocol, open the Settings app, tap Storage, tap the menu button, and tap USB computer connection.

How do I know if my phone is connected to USB mode?

Check the USB Connection Mode on Your Phone (Windows/Mac) Here's how to do that: Connect your phone to your computer using a USB cable. Pull down the notification bar, and you should see an Android system entry that shows the current connection mode. Tap the connection mode item to open the USB Preferences page.


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

like image 181
James Moore Avatar answered Sep 24 '22 03:09

James Moore


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/

like image 34
Noby Avatar answered Sep 24 '22 03:09

Noby