2011-12-22 71 views
2
配对蓝牙在两个设备

我尝试配对两台设备如何使用NFC

一个是谷歌Nexus S的具有广告应用程式运行的读取写入了该卡在其他手机上的标签上的MAC地址这不是Android的一个。

现在我试图配对设备,因为我点击其他手机时,我的应用程序将读取存储在TAG中的MAC地址并自动创建蓝牙连接。

一切工作正常,但我得到一个配对请求或匹配两个手机上的键不应该来。

这里是蓝牙细分市场,在连接发生

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); 

       Log.d("CHECK", "Sucessfully created insecure socket"); 
      } 
     } catch (IOException e) { 
      Log.e(TAG, "Socket Type: " + mSocketType + "create() failed", e); 
     } 

     mmSocket = tmp; 

    } 

    public void run() { 
     Log.i(TAG, "BEGIN mConnectThread SocketType:" + mSocketType); 
     setName("ConnectThread" + mSocketType); 

     // Always cancel discovery because it will slow down a connection 
     mAdapter.cancelDiscovery(); 

     Log.d("CHECK", "Inside RUN"); 

     // Make a connection to the BluetoothSocket 
     try { 
      // This is a blocking call and will only return on a 
      // successful connection or an exception 

      Log.d("CHECK", "Trying to connect"); 

      mmSocket.connect(); 

      Log.d("CHECK", "Tried to connect"); 

     } catch (IOException e) { 
      // Close the socket 
      try { 
       mmSocket.close(); 

       Log.d("CHECK", "Socket closed"); 

      } catch (IOException e2) { 
       Log.e(TAG, "unable to close() " + mSocketType + 
         " socket during connection failure", e2); 
      } 

      Log.d("CHECK", "Connection failed"); 

      connectionFailed(); 
      return; 
     } 

     // Reset the ConnectThread because we're done 
     synchronized (BluetoothChatService.this) { 
      mConnectThread = null; 
     } 

     // Start the connected thread 
     connected(mmSocket, mmDevice, mSocketType); 

     Log.d("CHECK RESULT", "Sucessfully connected"); 

     // Toast.makeText(BluetoothChatService.ConnectThread.this, "Sucessfully connected" , Toast.LENGTH_LONG).show(); 
    } 

    public void cancel() { 
     try { 
      mmSocket.close(); 
     } catch (IOException e) { 
      Log.e(TAG, "close() of connect " + mSocketType + " socket failed", e); 
     } 
    } 
} 

我想对不安全的连接,但我不知道为什么它被要求同时在手机的配对键。

+0

你好,我需要开发相同的功能。请告诉我如何在设备靠近时配对并开始传输NDEF消息。请回复我。它的紧急请。 – 2012-04-20 15:57:23

回答

0

赤蓝牙版本,因为: (原文如此)“对于蓝牙2.1设备,链路密钥进​​行加密,加密是强制性对于传统设备(预蓝牙2.1的设备)的链路密钥将无法进行。加密“。

+0

感谢您的回复..但我正在使用命令tmp = device.createInsecureRfcommSocketToServiceRecord( MY_UUID_INSECURE); 和该命令的解释说,它会继续并使连接绕过所需的加密链接。 – user1111176 2011-12-22 08:54:08

+0

你确定吗?我的答案是从在线文档的解释中复制而来的。请再次检查。 – jlvaquero 2011-12-22 12:10:11

相关问题