我正在尝试将我的电脑与安卓手机连接以传输一些数据。对于计算机编程语言,我选择了 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
谁知道哪里出了问题?
谢谢你的帮助! 法律
最佳答案
请参阅 https://32feet.codeplex.com/wikipage?title=Errors 处的错误代码因此,这表明客户端没有找到在目标设备上运行的具有预期 UUID 的服务器。现在为什么...
如果您使用 32feet.NET SdpBrowser 示例并列出“(通过 L2CAP)”的所有 SDP 服务,您会看到什么?
您是否连接到正确的设备地址?
关于c# - 用蓝牙连接PC和安卓手机(c#),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16195974/