2011-12-22 31 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