我正在开发一个耳机/免提应用程序并在演示板上运行它。成功连接到手机后,当应用程序从手机读取数据时,我用手机打电话或播放音乐。手机不发出声音,演示板也是如此。现在系统日志显示“拒绝传入 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()");
}