1

我有 Windows 控制台应用程序(用 C# 编写),它需要通过蓝牙从 Android 手机(运行 Java 应用程序)接收字符串。Windows 控制台应用程序使用 32feet.Net 库来处理蓝牙。

这是从 Android 手机发送字符串的 Java 代码(为简洁起见,省略了不重要的细节):

 BluetoothDevice targetDevice = getDeveice();
 BluetoothSocket socket = targetDevice.createRfcommSocketToServiceRecord(getUuid()); 
 socket.connect();
 OutputStream outputStream = socket.getOutputStream();
 outputStream.write("MyString".getBytes());

这是接收数据的 C# 代码:

string lgphone = "00:00:00:00:00:00"; // The MAC address of my phone, lets assume we know it
BluetoothAddress addr = BluetoothAddress.Parse(lgphone);
var btEndpoint = new BluetoothEndPoint(addr, new Guid("0000111f-0000-1000-8000-00805f9b34fb"));
var btClient = new BluetoothClient();
btClient.Connect(btEndpoint);
Stream peerStream = btClient.GetStream();
byte[] buf = new byte[1000];
int readLen = peerStream.Read(buf, 0, buf.Length);

BluetoothClient连接成功。但是peerStream没有任何数据 :( 如果需要,我可以提供更多详细信息。

一般方法是否正确?你能建议什么可能是错的吗?

4

0 回答 0