Getting Android app to communicate with Windows app via USB

2,876 views
Skip to first unread message

NYL

unread,
Mar 29, 2012, 10:02:20 PM3/29/12
to android-porting
Dear Android experts,

Not sure if I should ask this question on the porting group or
application group.

I would like to create an Android application that communicates with a
PC Windows app using the USB interface. May I know if this is
possible? Do I need to modify the Android OS, add in drivers or can
this be done at the application level?

Thank you very much.

Chris Stratton

unread,
Apr 3, 2012, 12:39:28 AM4/3/12
to android...@googlegroups.com
On Thursday, March 29, 2012 10:02:20 PM UTC-4, NYL wrote:
I would like to create an Android application that communicates with a
PC Windows app using the USB interface. May I know if this is
possible? Do I need to modify the Android OS, add in drivers or can
this be done at the application level?

This is possible, but poorly supported enough that it may not be suitable for end users.   

Unless you are in a position to install a custom android build adding a new device side USB driver, you don't really get to use the USB as USB.  Instead you have two choices:

1) Install an "ADB" driver on the PC and enable "USB debugging" on the android device.  Set up an ADB port forward.  Run a TCP server on the device, and have a TCP client on the PC connect to the local port which is forwarded to the android device via ADB.  This should work on all ordinary android devices, but several of the steps (identifying and installing the appropriate ADB driver for the phone, activating USB debugging on the phone) may not be a good fit for non-technical end users.

2) Activate some device/build-specific USB (reverse)tethering or internet pass through, and hope that as a side effect this makes TCP connections between the PC and device possible.  This will only work on some devices.

A more practical option may be to ask the user to place the device and PC on the same wireless network, or even communicate by was of a server you place on the Internet so that it is visible from both the PC's network provider and the android device's mobile network.

chenyq

unread,
Apr 3, 2012, 2:48:21 AM4/3/12
to android-porting
very comprehensive

A Curtis

unread,
Apr 3, 2012, 12:17:35 PM4/3/12
to android-porting
There is another option that I believe works on all Android platforms.
At least the drivers exist. Unfortunately I have not found a standard
mechanism to enable it operation.

All Android platforms that I have encountered include g_ether.ko. This
is a gadget ethernet kernel module which may be used for network
communications over USB. The problem is that this conflicts with
g_android.ko, since they both want to own the USB interface.

If you have the ability to modify init.rc then you can:
1. Start adb to listen to a TCP port. This attaches adb to the wifi
interface, freeing up USB
2. Then you can load g_ether.ko and use standard Java networking
methods

If anyone knows how to do this without modifying the Android platform,
please let share....

NYL

unread,
Apr 3, 2012, 10:29:25 PM4/3/12
to android-porting
Thank you very much for the clear reply. It helps a lot.

A Curtis

unread,
Apr 4, 2012, 3:08:38 PM4/4/12
to android-porting
There is another option that is available on all the Android platforms
I have looked at, load g_ether.ko. Unfortunately this isn't as easy as
it should be since g_android.ko, the ADB kernel driver, wants to use
the USB interface by default. If you could modify the default behavior
so ADB connects to a TCP port via Wifi by default, then USB will be
available.

I have been able to accomplish this with a custom init.rc file. If
anyone knows how to do this in a vanilla Android environment it would
be greatly appreciated.

Allen
Reply all
Reply to author
Forward
0 new messages