我正在开发耳机/免提应用程序并在演示板上运行。成功连接到手机后,当应用程序从手机读取数据时,我通过手机拨打或播放音乐。手机没有发出声音,demoboard也是如此。现在系统日志显示“拒绝传入的SCO连接”,为什么?如何为传入的SCO连接路由音频?我怎样才能听到演示板?
代码,
private boolean connected = false;
private BluetoothSocket sock;
private InputStream in;
private boolean running = true;
public void test() throws Exception {
if (connected) {
return;
}
BluetoothDevice zee = BluetoothAdapter.getDefaultAdapter().getRemoteDevice("00:1C:D4:F7:7F:FD");//The phone's address
UUID myUuid = UUID.fromString("00001112-0000-1000-8000-00805f9b34fb");//headset uuid
sock = zee.createRfcommSocketToServiceRecord(myUuid);
Log.d(TAG, "++++ Connecting " + zee.getName());
sock.connect();
Log.d(TAG, "++++ Connected " + sock.toString());
in = sock.getInputStream();
byte[] buffer = new byte[50];
int read = 0;
Log.d(TAG, "++++ Listening...");
running = true;
try {
while (running) {
read = in.read(buffer);
connected = true;
StringBuilder buf = new StringBuilder();
for (int i = 0; i < read; i++) {
int b = buffer[i] & 0xff;
if (b < 0x10) {
buf.append("0");
}
buf.append(Integer.toHexString(b)).append(" ");
}
Log.d(TAG, "++++ Read "+ read +" bytes: "+ buf.toString());
}
} catch (IOException e) {
Log.e(TAG, "++++ IOException e:" + e.toString());
}
connected = false;
Log.d(TAG, "++++ Done: test()");
}
答案 0 :(得分:1)
AudioManager localAudioManager = (AudioManager) getSystemService("audio");
localAudioManager.setBluetoothScoOn(true);
localAudioManager.startBluetoothSco();
localAudioManager.setMode(2);
答案 1 :(得分:0)
如果我理解您的代码,您正在尝试从RFComm套接字读取音频。应使用RFComm套接字将AT命令发送到设备(而不是读取音频数据)。
发送AT命令时,请确保至少发送/响应免提设备AT+BRSF, AT+CIND=?, AT+CIND?, AT+CMER=x,x,x,x
的3个强制AT命令。请参见Handsfree reference第19页。
在该阶段之后,您应该打开SCO音频连接以获取音频。