Home » Android » java – Send string from Android phone to PC

java – Send string from Android phone to PC

Posted by: admin June 15, 2020 Leave a comment

Questions:

How can I can send a string (ex: "hi") to my PC from my Android phone?

How to&Answers:

Before doing this in Android, I recommend you read the basics of Java networking:

Try to get access to a good book. Once you know how to do it in Java, implement a test client in Android & a test server in your PC.

Answer:

I’m actually implementing a socket solution between Android and PC right now! Once you understand the basics behind sockets (by reading the links that Sebastian suggested), you can use the following links as code guides to make your instruments talk:

I’m using the client code from the Android socket example link above, and the server example from the Unix socket example on Beej’s website (I’ve been informed that I’m a new user to stackoverflow, so I’m going to link that as a comment to this answer). The Unix socket server is set up to receive a connection and a packet from the client, then send an answer back and close the socket. I modified this so that the server is just a loop that continuously asks for input from the user at the console. It’s not a pretty solution (i.e. no user interface on the PC side), but it will at least give you the basics. You can make it pretty later.