我认为,如果A2DP无法正常工作,我们最好转移到较低层,我们可以创建一个基本流,可用于发送任何形式的日期 . 我成功通过J2ME设备之间的蓝牙发送字节流 .
如果在两个设备上安装应用程序是可以接受的,我会通过套接字创建蓝牙服务器和客户端进行通信的示例代码,一旦套接字 Build ,你就可以发送音频流:)
这里有一些核心代码:
1)服务器设备:
// you can generate your own UUID and use it as an port to eatablish a socket
private static final UUID MY_UUID = UUID.fromString("20687DAD-B023-F19E-2F60-A135554CC3FD")
BluetoothServerSocket serverSocket = mBluetoothAdapter.listenUsingRfcommWithServiceRecord(NAME_INSECURE, MY_UUID);
现在你有了serverSocket,只需将它用作普通的ServerSocket:
BluetoothSocket socket = serverSocket.accept();
然后你可以从这个 BluetoothSocket 获得 InputStream 和 OutputStream 并发送音频流就像 HttpConnection
2)客户端设备:
假设你已经拥有 BluetoothDevice
// you should implement the method getBlutoothDevice
BluetoothDevice device = getBluetoothDevice();
BluetoothSocket socket = device.createRfcommSocketToServiceRecord(MY_UUID_SECURE);