views:

53

answers:

0

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