だから私はこのAndroid Bluetooth Projectを持っていて、本当に厄介な問題を抱えています。文脈を説明しましょう:
接続される 2 つの電話は、Android 開発者サイト (こちら)の Bluetooth ドキュメントに記載されている正確な方法を使用して、BluetoothSockets を取得します。したがって、接続には次のスレッドを使用します。
private class AcceptThread extends Thread {
    private final BluetoothServerSocket mmServerSocket;
    public AcceptThread() {
        // Use a temporary object that is later assigned to mmServerSocket,
        // because mmServerSocket is final
        BluetoothServerSocket tmp = null;
        try {
            // MY_UUID is the app's UUID string, also used by the client code
            tmp = mBluetoothAdapter.listenUsingRfcommWithServiceRecord(NAME, MY_UUID);
        } catch (IOException e) { }
        mmServerSocket = tmp;
    }
    public void run() {
        BluetoothSocket socket = null;
        // Keep listening until exception occurs or a socket is returned
        while (true) {
            try {
                socket = mmServerSocket.accept();
            } catch (IOException e) {
                break;
            }
            // If a connection was accepted
            if (socket != null) {
                // Do work to manage the connection (in a separate thread)
                manageConnectedSocket(socket);
                try {
                    mmServerSocket.close();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                break;
            }
        }
    }
    /** Will cancel the listening socket, and cause the thread to finish */
    public void cancel() {
        try {
            mmServerSocket.close();
        } catch (IOException e) { }
    }
}
それが受け入れスレッドであり、
private class ConnectThread extends Thread {
    private final BluetoothSocket mmSocket;
    private final BluetoothDevice mmDevice;
    public ConnectThread(BluetoothDevice device) {
        // Use a temporary object that is later assigned to mmSocket,
        // because mmSocket is final
        BluetoothSocket tmp = null;
        mmDevice = device;
        // Get a BluetoothSocket to connect with the given BluetoothDevice
        try {
            // MY_UUID is the app's UUID string, also used by the server code
            tmp = device.createRfcommSocketToServiceRecord(MY_UUID);
        } catch (IOException e) { }
        mmSocket = tmp;
    }
    public void run() {
        // Cancel discovery because it will slow down the connection
        mBluetoothAdapter.cancelDiscovery();
        try {
            // Connect the device through the socket. This will block
            // until it succeeds or throws an exception
            mmSocket.connect();
        } catch (IOException connectException) {
            // Unable to connect; close the socket and get out
            try {
                mmSocket.close();
            } catch (IOException closeException) { }
            return;
        }
        // Do work to manage the connection (in a separate thread)
        manageConnectedSocket(mmSocket);
    }
    /** Will cancel an in-progress connection, and close the socket */
    public void cancel() {
        try {
            mmSocket.close();
        } catch (IOException e) { }
    }
}
これが ConnectThread です。(実際には上のリンクからコピーされていることに気付くかもしれません);
問題は、接続しようとすると、connectthread が実際にソケットを返す (managesocket() を呼び出す) ことですが、何も起こらなかったかのように、受け入れスレッドは socket = mmServerSocket.accept() のままです。しかし、他のデバイス (ConnectThread を持つデバイス) から接続を開始すると、受け入れデバイスの logcat が更新されるため、AcceptThread で実際に何かが発生しています。接続が実際に適切に作成されることもありますが、強制終了、無効化-> Bluetooth の有効化などの後でのみです。
これはlogcatの興味深い行です(.accept()呼び出しによって生成されたと思います):
07-19 18:04:47.484: D/BLZ20_WRAPPER(3143): btlif_signal_event: ### イベント BTLIF_BTS_RFC_CON_IND が一致しません ###
では、何が問題になるのでしょうか?