蓝牙套接字,写入和读取字符串

Bluetooth socket, write and read strings

如何通过蓝牙插座输出和读取字符串。现在它打印正在发送的字节的值,即字符数 0-255。所以 'hi' 是 2,'bye' 是 3。这是我的读写函数:

public void read() {
            byte buffer[] = new byte[1024];
            final int bytes;

            try {
                bytes = iStream.read(buffer);

                activity.runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        updateTView(bytes);
                    }
                });
                Log.i("WTF",String.valueOf(bytes));
            } catch(IOException e) {
                //TODO: something
            }
}

public void writeText(byte bytes[]) {
    try {
        oStream.write(bytes);
    } catch(IOException e) {
        //TODO: something
    }
}
                  private InputStream input;

在后台线程中执行此操作。

                  byte[] buffer = new byte[1024];
                  bytes = input.read(buffer);
                  String readMessage = new String(buffer, 0, bytes);
                  // Send the obtained bytes to the UI Activity
                  System.out.println(readMessage);