0

Androidフォン/タブレット(4.0.3)と、イヤリングリーダーであるBluetoothデバイス(Destron Fearring DTR3E、知りたい場合に備えて、私はあなたとは思わない)との間でBluetooth通信を確立しようとしています行う)。

ブルートゥース設定から電話をリーダーとペアリングしました(リーダーにはタグにペアリングパスコードがあります)。もちろんブルートゥースはオンになっており、BluetoothServerSocketを使用してデバイスからの読み取りをリッスンしようとしています。問題は、受け入れ呼び出しが返されないことです。そのため、明らかに私は何か間違ったことをしています。通信は RFCOMM を使用して行われます。

コード:

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

                String uuid  = "00001101-0000-1000-8000-00805F9B34FB";
                tmp = bluetoothAdapter.listenUsingInsecureRfcommWithServiceRecord("pdfParserServer", UUID.fromString(uuid));
            } catch (Exception e) {
            e.printStackTrace();
            }
            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)

                    try {
                        mmServerSocket.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                    break;
                }
            }
        }

        /** Will cancel the listening socket, and cause the thread to finish */
        public void cancel() {
            try {
                mmServerSocket.close();
            } catch (IOException e) { }
        }
    }

足りないものはありますか?

ありがとうございました!

4

1 に答える 1

2

コードが受け入れから戻らない原因となる唯一の理由は、接続しようとしているデバイス「Destron Fearring DTR3E」が、実際には bluetooth クライアントではなく bluetoothserver ソケットを持っているため、デバイスが待機している可能性があることです。 bluetoothserverソケットを作成してAndroidデバイスに接続するのを待つのではなく、実際に接続するには、デバイスの仕様を読んで、接続を開く必要があるのは実際にあなたであることを確認する必要があります「デストロン フィアリング DTR3E」ソケット...

お役に立てれば...

よろしく!

于 2013-08-19T17:37:05.863 に答える