如何在Android和电脑之间发送/接收文本?

我想发送一个纯文本或丰富的文本从/到Android < – >计算机,可能到剪贴板,但不一定。 我怎样才能做到这一点? 我不想通过电子邮件或创build一个文件来写入文本。

Android API是否允许以某种方式做到这一点? 也许通过NFC或蓝牙

我希望它是无线的。

从你的Android设备,你可以传递字符串到PC这样的。

try { Socket socket = new Socket(DESTINATION_ADDRESS, DESTINATION_PORT); // Exmp : Socket socket = new Socket("192.168.0.101", 80); OutputStream outToserver = socket.getOutputStream(); DataOutputStream out = new DataOutputStream(outToserver); out.writeUTF(SEND_STRING); // Exmp : out.writeUTF("TEST"); socket.close(); } catch (Exception e) { e.printStackTrace(); } 

而从PC你必须收到的消息,并采取行动。

 try { InetAddress IP = InetAddress.getLocalHost(); serverSocket serverSocket = new serverSocket(1000); } catch (UnknownHostException e) { e.printStackTrace(); } // Run an infinite loop to check if the message is received or not. while (true) { try { Socket clientSocket = serverSocket.accept(); DataInputStream in = new DataInputStream(new BufferedInputStream(clientSocket.getInputStream())); String message = in.readUTF(); // Get the message which send from android device. /* do other staff after getting the message . */ }atch (Exception ex) { e.printStackTrace(); } }