문제

According to Android Bluetooth documentation (Here), when the client calls BluetoothAdapter#startDiscovery and subsequently get a BluetoothDevice, it should first call BluetoothAdapter#cancelDiscovery before it attempts to call createRfcommSocketToServiceRecord because startDiscovery uses too much bandwidth that might cause the connection to fail if it's running concurrently. However, how do you know which BluetoothDevice is the server you are trying to connect to?

I don't understand how this can avoid the loop where you start discovery, finds a device (not your server), cancels discovery and tries to connect to the device, fails, re-start discovery, and repeat.

Thanks!

도움이 되었습니까?

해결책

One possible solution I came up with is to keep track of the addresses of all the BluetoothDevice that you already tried to connect with and failed, and on the next attempt of startDiscovery simply bypass those. However, I am still calling startDiscovery and cancelDiscovery multiple times and discovering the same wrong devices multiple times, so I would love to hear a better solution if anyone has one!

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top