How To Send/receive Text Between Android And Computer?
I want to send a plain or rich text from/to Android <-> Computer, probably to clipboard but not necessarily. How can I do that? I don't want to email or create a file in orde
Solution 1:
From your android device you can pass String to PC like this .
try {
Socketsocket=newSocket(DESTINATION_ADDRESS, DESTINATION_PORT);
// Exmp : Socket socket = new Socket("192.168.0.101", 80);OutputStreamoutToServer= socket.getOutputStream();
DataOutputStreamout=newDataOutputStream(outToServer);
out.writeUTF(SEND_STRING);
// Exmp : out.writeUTF("TEST");
socket.close();
} catch (Exception e) {
e.printStackTrace();
}
And from PC you have to receive the message and do action .
try {
InetAddressIP= InetAddress.getLocalHost();
ServerSocketserverSocket=newServerSocket(1000);
} catch (UnknownHostException e) {
e.printStackTrace();
}
// Run an infinite loop to check if the message is received or not.while (true) {
try {
SocketclientSocket= serverSocket.accept();
DataInputStreamin=newDataInputStream(newBufferedInputStream(clientSocket.getInputStream()));
Stringmessage= in.readUTF(); // Get the message which send from android device. /* do other staff after getting the message . */
}atch (Exception ex) {
e.printStackTrace();
}
}
Post a Comment for "How To Send/receive Text Between Android And Computer?"