Sending commands from a PC to an Android phone - via physical connection (USB, Serial, etc)

12,060

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

Share:
12,060
J J
Author by

J J

Updated on June 12, 2022

Comments

  • J J
    J J almost 2 years

    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.

  • Chris Stratton
    Chris Stratton over 9 years
    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.
  • BoD
    BoD over 9 years
    @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 :)
  • Chris Stratton
    Chris Stratton over 9 years
    How were you proposing to connect it then? Wifi? You almost certainly can't make inbound connections via a mobile provider.