4
votes

I am trying to pair an android device running android 4.1 with a a2dp capable audio receiver. I can do that without problems from the bluetooth settings screen but i am struggeling to do it in code.

Basically i am able to discover the device but i can not connect to it via the socket. Maybe i am using the wrong UUID or maybe i should use the predefined android.bluetooth.BluetoothA2dp classes. Here is what i am doing:

UUID uuid = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");
socket = device.createInsecureRfcommSocketToServiceRecord(uuid);
socket.connect();

But i get an exception stating that it can not connect.

java.io.IOException: Service discovery failed
at android.bluetooth.BluetoothSocket$SdpHelper.doSdp(BluetoothSocket.java:403)
at android.bluetooth.BluetoothSocket.connect(BluetoothSocket.java:213)

I have also tried to connect using the UUIDs the device provides via device.getUuids() but those did not help either to connect to the a2dp device.

Any help on how to connect to an a2dp device would be greatly appreciated. Thanks.

1
are you able to search and pair to this deviceNarendra Pal
I can find the device when searching for devices. I was under the impression that creating a socket connection with a device automatically pairs them. Finding and pairing in the settings is no problem.Moritz
Hi Mortiz, could I ask if you ever got anywhere with this? I'm trying to connect a 4.2+ Android device to an A2DP Bluetooth speaker at the moment, and am struggling to work out how to approach it too. Thanks for any help in advance.Ted
Hi @Ted. Unfortunately my research did not come to a successful conclusion.Moritz
How do you create the socket for bluetooth?Skizo-ozᴉʞS

1 Answers

2
votes

A2DP is not done over RFCOMM, so you can't use the createRfcommSocket APIs. The data is transported directly over L2CAP streams with specified protocol mux IDs (one for control, another for streaming data).