Java 了解connect()是否成功进行蓝牙连接的方法

Java 了解connect()是否成功进行蓝牙连接的方法,java,exception,bluetooth,ioexception,Java,Exception,Bluetooth,Ioexception,有没有办法知道连接方法是否成功 我有ConnectThread类中的代码: public void run() { // Cancel discovery because it will slow down the connection mBluetoothAdapter.cancelDiscovery(); try { // Connect the device through the socket. This will block /

有没有办法知道连接方法是否成功

我有ConnectThread类中的代码:

public void run() {
    // Cancel discovery because it will slow down the connection
    mBluetoothAdapter.cancelDiscovery();

    try {
        // Connect the device through the socket. This will block
        // until it succeeds or throws an exception
        mmSocket.connect();
    } catch (IOException connectException) {
        // Unable to connect; close the socket and get out
        try {
            mmSocket.close();
        } catch (IOException closeException) { }
        return;
    }
}
并尝试将此线程连接为:

BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
Set<BluetoothDevice> pairedDevices = mBluetoothAdapter.getBondedDevices();
if (pairedDevices.size() > 0) 
{
    // Loop through paired devices
    for (BluetoothDevice device : pairedDevices) 
    {
        if (device.getName().equals("HC-06"))
        {
            Thread initialThread = new ConnectThread(device);
            initialThread.run();
        }
    }
}

我想知道这个连接是否成功。任何帮助都将不胜感激,谢谢

如果没有成功,它将抛出一个异常。如果在connect调用后到达该语句,则该语句成功。

如果该语句引发异常,程序是否应该冻结?我试图连接一个随机UUID,在这种情况下,应该抛出一个异常,但程序运行良好。