开发者

How to route audio for incoming SCO connection?

I'm developing a headset/handsfree app and run it in a demoboard.After connecting to a phone successfully and when the app is reading data from the phone,I call or play music with the phone.The phone doesn't make sounds,and so does the demoboard.Now the system log shows "Rejec开发者_如何转开发ting incoming SCO connection",why?How to route audio for incoming SCO connection?How can I hear the demoboard?

The code,

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()");
}


AudioManager localAudioManager = (AudioManager) getSystemService("audio");

localAudioManager.setBluetoothScoOn(true);              

localAudioManager.startBluetoothSco();              

localAudioManager.setMode(2);


If I understand correctly your code, you are trying to read audio from an RFComm socket. RFComm socket should be used to send AT Commands to the device (and not read audio data).

When sending AT commands, make sure that you send / respond to at least the 3 mandatory AT commands for handsfree devices AT+BRSF, AT+CIND=?, AT+CIND?, AT+CMER=x,x,x,x. See Handsfree reference page 19.

After that stage, you should open an SCO Audio connection to get audio.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜