Android 蓝牙套接字超时

Android bluetooth socket timeout

也许我错过了什么,但是如何更改 BluetoothSocket.connect() 的超时时间?

谢谢

安东尼

您无法更改 BluetoothSocket.connect() 的超时。作为文档:

This method will block until a connection is made or the connection fails. If this method returns without an exception then this socket is now connected.

解决方法。

例:超时5秒。 使用 CountDownTimer 检查连接是否完成(成功或失败)。 5 秒后,如果连接未完成,则使用 BluetoothSocket.close() 取消。

作为 BluetoothSocket 文档:

close() can be used to abort this call from another thread.