当我尝试从个人计算机连接到蓝牙设备时,出现错误:javax.bluetooth.BluetoothConnectionException: Failed to connect; [10051] A socket operation was attempted to an unreachable network.
它在我的android应用中正常工作。
在我的android应用中,我只需先调用BluetoothAdapter#getRemoteDevice(address)
,然后再调用BluetoothDevice#createRfcommSocketToServiceRecord(UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"))
。
在Java应用程序中,我获得了startInquiry
可以正常工作的设备,因为地址与android的地址匹配。
然后,我用searchServices(null,new UUID[]{new UUID("0000110100001000800000805F9B34FB",false)},device,this);
搜索服务,实际上发现其中的ServiceRecord
像这样toString()
:
0x4:
DATSEQ {
DATSEQ {
UUID 0000010000001000800000805f9b34fb
}
DATSEQ {
UUID 0000000300001000800000805f9b34fb
U_INT_1 0x1
}
}
0x1:
DATSEQ {
UUID 0000110100001000800000805f9b34fb
}
0x0:
U_INT_4 0x10002
}
然后我用返回record.getconnectionURL(ServiceRecord.NOAUTHENTICATE_NOENCRYPT,false)
进行btspp://censored:1;authenticate=true;encrypt=false;master=false
。
然后,我尝试使用Connector.open(url)
与它连接。
不幸的是,一段时间后它引发了异常:
Exception in thread "main" javax.bluetooth.BluetoothConnectionException: Failed to connect; [10051] A socket operation was attempted to an unreachable network.
at com.intel.bluetooth.BluetoothStackmicrosoft.connect(Native Method)
at com.intel.bluetooth.BluetoothStackmicrosoft.access$700(BluetoothStackmicrosoft.java:44).```