I am a complete noob at Android, only at the level of basic (1 or 2 line) Activities activated by buttons, but I would like to create a really simple app that, when I tap the app icon, it fires and forgets a message to a listening server on my Windows 8 PC. The phone is connected as a simple media device, without Kies, via a USB cable.
I can get as far as a message box lying and saying the message was sent. I need to know what kind of comms channel to use, e.g. a COM port or what, and how to send data over that from Android. On the Windows side, once I've established how to communicate, I can help myself.
starting with the desktop side of this application: You can use the ADB (Android debug bridge) to establish a tcp/ip socket connection via port between the device and desktop. The command is :
to run this command in your java program, you will have to create a process builder wherein this command ets executed on a child shell.
For windows you may need to use:
The function required to execute adb commands :
Above method will take the above command as a string and execute it on a child shell
CommandExecutor is a class which has the execute method in it. The code of the execute method is the same as posted above. This will check if any device is connected and if it connected, it will return it unique id number.
It is preferable to use id number while executing adb commands like :
OR
Note that '-s' is necesarry after adb.
Then using adb forward commnd you need to establish a tcp/ip socket. Here the desktop will be the client and mobile/device will be the server.
Then you need read from the server i.e. the device :
The 'buffer' will contain what device will send from its end of the app.
Now in your mobile application,you will need to open the same connection and siple write data to it out buffer
Using Managed.adb in c#
Then create a server socket on android to that port.
and client socket on C#