6

I'm working on a project to automate some tasks (such as play a song, play a video, receive bluetooth data, etc) on an Android phone from a PC.

Basically the PC will send a notifier to the phone and an app or something on the phone would then process the notifier and do 'something'. The opposite of this really: http://code.google.com/p/android-notifier/

I've seen some examples showing how to send commands to an Android listener app or service via a network connection, but in this case, I would much rather the transmission be over a physical connection.

USB Ideally, I'd like the connection to be via the USB port. But I've seen some posts online that suggest that the SDK does not natively support this. (Android apps, communicating with a device plugged in the USB port).

Serial over USB I've also seen some sites that show how to use a breakoutbox to perform bi-directional serial communication, but only with the G1. Is this possible with newer phones?

The Phone I'm open to really any newish phone. I'm currently looking at the Galaxy S, because it has the video out through the headphone jack. I'm open to rooting if need be.

Community
  • 1
  • 1
J J
  • 1,480
  • 4
  • 17
  • 26
  • I figured out how to call an intent action from the command line using adb and the shell... http://learnandroid.blogspot.com/2008/01/run-android-application-from-command.html Now I need to figure out how to get data back... – J J Jun 08 '11 at 23:09
  • You can write data to a file and then get it to a PC by 'adb pull' – werewindle Nov 24 '11 at 17:26
  • Do I have to poll, or is it a blocking/synchronous call? – J J Dec 09 '11 at 21:06
  • Sorry for the very late answer , but I am assuming the issue is still unsolved. If not , please ignore. I have used ADB to communicate : refer [this](http://stackoverflow.com/a/21749521/1833437) for additonal details. – Ab5 Mar 30 '15 at 07:47

2 Answers2

4

Implement a HTTP server in your app, then put your phone in USB Tether mode. This will create a local network between your phone and your PC. You should then be able to send HTTP request or create websockets using the phone's ip.

EDIT : I tested it, and it works, see here

Community
  • 1
  • 1
Rémy DAVID
  • 4,045
  • 6
  • 22
  • 26
0

What you can do is the phone acting as a server and then use adb to forward ports [1].

In this scenario the pc app would connect to localhost which would be redirected to the app on the phone via the usb cable.

But if you go this way, you might just as well simply connect directly to the phone's ip (without the adb port forwarding)...

[1] http://developer.android.com/guide/developing/tools/adb.html#forwardports

BoD
  • 10,222
  • 6
  • 60
  • 57
  • ADB does not establish a network, so no, you can't connect directly - if ADB is the transport you have to use port forwards. You might be confusing the emulator-only host network aliases. – Chris Stratton Jul 29 '14 at 14:55
  • @ChrisStratton By "simply connect directly to the phone's ip" I meant to not use ADB at all. So I'm not sure what you mean :) – BoD Jul 29 '14 at 15:27
  • How were you proposing to connect it then? Wifi? You almost certainly can't make inbound connections via a mobile provider. – Chris Stratton Jul 29 '14 at 15:32