我正在尝试将我的计算机与 android 手机连接以传输一些数据。对于计算机编程语言,我选择了 c#。
在计算机上,代码如下所示:
var wantedAddress="303926627f06";
var addr = BluetoothAddress.Parse(wantedAddress);
var cli = new BluetoothClient();
cli.Connect(addr, new Guid("{00001101-0000-1000-8000-00805f9b34fb}"));
在 android 手机上,代码看起来像:
private UUID uuid = UUID.fromString("00001101-0000-1000-8000-00805f9b34fb");
private BluetoothAdapter btAdapter= BluetoothAdapter.getDefaultAdapter();
private BluetoothServerSocket server=btAdapter.listenUsingRfcommWithServiceRecord("App name",uuid);
while(isRunning)
{
try {
BluetoothSocket socket=server.accept();
} catch (IOException e) {
isRunning=false;
e.printStackTrace();
}
}
尝试连接到手机后,我收到此错误:
SocketException:
The requested address is not valid in its context 303926627F06:0000110100001000800000805f9b34fb
有谁知道出了什么问题?
谢谢你的帮助!法理