如何连接到蓝牙A2DP设备? [英] How to connect to a bluetooth a2dp device?
问题描述
我试图配对一个能够支持A2DP音频接收器运行的是Android 4.1的Android设备。我能做到这一点从没有蓝牙设置屏幕的问题,但我struggeling做到在code。
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.
基本上我能发现的设备,但我无法通过套接字连接到它。也许是我使用了错误的UUID或者我应该使用predefined android.bluetooth.BluetoothA2dp类。下面是我在做什么:
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)
我也尝试使用该设备提供的UUID连接通过 device.getUuids()
,但这些并没有帮助任何连接到A2DP设备。
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.
如何连接到A2DP设备的任何帮助将不胜AP preciated。谢谢你。
Any help on how to connect to an a2dp device would be greatly appreciated. Thanks.
推荐答案
A2DP是不是在做RFCOMM,所以你不能使用 createRfcommSocket
的API。 L2CAP之上具有规定协议多路复用的ID(一个用于控制,另一个用于流数据)流数据被直接输送。
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).
这篇关于如何连接到蓝牙A2DP设备?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!