I'm trying to build a little Bluetooth-Android-App for a project in school.

I'm quite new to Android (got my phone since 2 days). I'm experimenting since 2 weeks with android programming on my laptop. Installed a VirtualBox with Android x86 (eeepc) so I can use the `BluetoothAdapter` of the laptop. Emulator doesn't support Bluetooth and is quite slow. That's about the project...

The problem/question:
A Bluetoothconnection has 2 devices - a connecting and a listening one. The listening device has a `BluetoothServerSocket`, that loops `accept()` method until `accept()` returns a `BluetoothSocket`.
In my case the `accept()` method doesn't return so I get stuck and the app freezes with blackscreen asking mit to stop the app or just to wait. When I pass a timeout to `accept()` --> `accept(10000)` I get an `IOException` after the timeout.

listening device:

```
private class AcceptThread extends Thread {

    private BluetoothSocket tSocket;
    private BluetoothServerSocket bss = null;

    public void run() {
        try {
            Log.d(TAG, "erzeuge ServerSocket");
            bss = BluetoothAdapter.getDefaultAdapter().listenUsingInsecureRfcommWithServiceRecord("BluetoothChatInsecure", MainActivity.BT_UUID);
            Log.d(TAG, "ServerSocket OK");
        } catch (IOException e) {
            e.printStackTrace();
            Log.e(TAG, "Fehler Serversocket");
        }

        while (true)  {

            Log.d(TAG, "Versuche zu akzeptieren");
            try {
                Log.d(TAG, "Akzeptieren Anfang");
                tSocket = bss.accept(10000);
                //this line is never reached
                Log.d(TAG, "Akzeptieren Ende");

                if (tSocket != null){
                    //Hier wollen wir hin!
                    Log.d(TAG, "Verbindung akzeptiert");
                    ConnectedThread conThread = new ConnectedThread(tSocket);
                    conThread.run();
                    bss.close();
                    break;
                } else {
                    Log.e(TAG, "Fehler, keine Verbindung");
                }
            } catch (IOException e) {
                Log.e(TAG, "IOException währent accept-loop");
                //this exception is triggered every 10 sec, when the accept(10000) times out
                e.printStackTrace();
            }   
        }
        Log.i(TAG, "Acceptthread hat fertig");          
    }

}

```

connecting device:

```
try {
    socket = device.createInsecureRfcommSocketToServiceRecord(MainActivity.BT_UUID);

    outstr = socket.getOutputStream();
    instr = socket.getInputStream();

    ois = new ObjectInputStream(instr);
    oos = new ObjectOutputStream(outstr);

} catch (IOException e) {
    e.printStackTrace();
}

```

I've read a lot of threads on stackoverflow and some other forums about this topic, but I didn't got a solution for the problem.
Sorry about my English, but I am not a native speaker.

Thanks for any help!

EDIT:

I forgot to write, that I test the app with 2 devices. My laptop does accept-loop, while I use my phone and try to connect.