I'm working on an Android app using Bluetooth connectivity between two paired smartphones. The Bluetooth logic is based on the famous BluetoothChat SDK example: a "service" Class managing a thread for server accept()
, a thread for client connect()
and a thread for reading/writing on the socket.
Everything works fine, except if I close an active connection (both from client or server side), then all successive attempts to start a new connection will fail with this error:
java.io.IOException: Service discovery failed
After some research, I've come to think this is a problem with UUID. I'm using the UUID of the BTChat example (fa87c0d0-afac-11de-8a39-0800200c9a66
), but the problem remains with another random UUID (it was 31ef5990-dc20-11e2-a28f-0800200c9a66
).
Here is the relevant client logcat. (The client connect()
is what fails):
E/BluetoothService.cpp: stopDiscoveryNative: D-Bus error in StopDiscovery: org.bluez.Error.Failed (Invalid discovery session)
D/BluetoothService: Cleaning up failed UUID channel lookup: 30:17:C8:A7:C6:C3 fa87c0d0-afac-11de-8a39-0800200c9a66
java.io.IOException: Service discovery failed
The D-Bus error probably is caused by the cancelDiscovery()
that Android docs suggests to call before connect()
. I think that failed UUID channel lookup
is the real problem, but I have no idea how to fix this. Should I use another (well-known?) UUID?
If needed, I can show code snippets. Yet this problem is very logically similar to BluetoothChat.