我正在尝试将我的Android应用与蓝牙(经典)外设相连接。
通过扫描找到设备后,我创建了一个没有问题的BluetoothSocket。但是,mySocket.connect()永远阻止。
public void run(BluetoothAdapter mBluetoothAdapter) {
// Cancel discovery because it otherwise slows down the connection.
mBluetoothAdapter.cancelDiscovery();
try {
// Connect to the remote device through the socket. This call blocks
// until it succeeds or throws an exception.
mySocket.connect();
} catch (IOException connectException) {
// Unable to connect; close the socket and return.
try {
mySocket.close();
} catch (IOException closeException) {
Log.e(TAG, "Could not close the client socket", closeException);
}
return;
}
}
为什么不抛出连接超时错误?
PS:我的应用和外设都使用默认的UUID(“00001101-0000-1000-8000-00805F9B34FB”),所以这不应该是我的问题。