Question

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!

Was it helpful?

Solution

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!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top