2

ここで BluetoothChat サンプル プロジェクトをダウンロードしました: https://android.googlesource.com/platform/development/+/master/samples/BluetoothChat?autodive=0%2F

実際には、2 つのデバイス (ペアリングされていない) でアプリを起動すると、2 つのデバイスのペアリングを要求せずに 2 つのデバイスを接続する必要があります。実際、(ペアリングされていない) 2 つのデバイスを接続しようとすると、デバイスのペアリングを求められます。つまり、BluetoothChatService.java には、安全でないソケットを作成する必要があるこの関数があります。しかし、それは彼の仕事をしていないようですか?

   /**
    * This thread runs while attempting to make an outgoing connection
    * with a device. It runs straight through; the connection either
    * succeeds or fails.
    */
   private class ConnectThread extends Thread {
       private final BluetoothSocket mmSocket;
       private final BluetoothDevice mmDevice;
       private String mSocketType;

       public ConnectThread(BluetoothDevice device, boolean secure) {
           mmDevice = device;
        BluetoothSocket tmp = null;
        mSocketType = secure ? "Secure" : "Insecure";

        // Get a BluetoothSocket for a connection with the
        // given BluetoothDevice
        try {
            if (secure) {
                tmp = device.createRfcommSocketToServiceRecord(
                        MY_UUID_SECURE);
            } else {
                tmp = device.createInsecureRfcommSocketToServiceRecord(
                        MY_UUID_INSECURE);
            }
        } catch (IOException e) {
            Log.e(TAG, "Socket Type: " + mSocketType + "create() failed", e);
        }
        mmSocket = tmp;
    }

2つのデバイスをペアリングするように求められる理由を誰か説明できますか? メソッド createInsecureRfcommSocketToServiceRecord は、ペアリングされていないデバイスのペアリングを要求するべきではありません。x) 私は本当に混乱しています。

4

1 に答える 1