Anthone
Anthone

Reputation: 2290

Android bluetooth socket timeout

Maybe I miss something, but How can I change the timeout of BluetoothSocket.connect() ?

Thanks you

Anthony

Upvotes: 0

Views: 1089

Answers (1)

cxphong
cxphong

Reputation: 857

You can't change timeout of BluetoothSocket.connect(). As documentation:

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.

A workaround.

Ex: timeout 5s. Using CountDownTimer to check if connect is complete(success or fail). After 5s, if connection is incomplete then use BluetoothSocket.close() to cancel.

As BluetoothSocket documentation:

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

Upvotes: 3

Related Questions