2014-05-22 64 views
0

我試圖連接到需要該設備的藍牙硬件地址來連接遠程設備:如何從其屬性獲取遠程設備的藍牙硬件地址?

bdDevice = mBluetoothAdapter.getRemoteDevice(<bluetooth_hardware_address>); 

怎樣才能發現遠端設備的藍牙地址?

這是我已經知道了遠程設備的參數 - 序列號,設備號,VIN號。

在這種使用遠程設備的性能,以獲得藍牙硬件地址來實現的iOS,它是如何在Android上完成的。

我試圖連接到需要該設備的藍牙硬件地址來連接遠程設備:

bdDevice = mBluetoothAdapter.getRemoteDevice(<bluetooth_hardware_address>); 

怎樣才能發現遠端設備的藍牙地址?

這是我已經知道了遠程設備的參數 - 序列號,設備號,VIN號。

在這種使用遠程設備的性能,以獲得藍牙硬件地址來實現的iOS,它是如何在Android上完成的。

UPDATE:

我可以用下面的代碼獲取地址,但是這並沒有給序列號,以配合 -

String ui_serial_number = "000055557F9FC"; //I want to use this SN to connect. 
BluetoothAdapter bluetoothAdapter; 
Set<BluetoothDevice> pairedDevices = bluetoothAdapter.getBondedDevices(); 
for (BluetoothDevice device : pairedDevices) { 
    // here you get the mac using device.getAddress() 

    //But there is nothing like device.getSerialNumber() 
    if(device.getSerialNumber().equals(ui_serial_number)) //What to do here? 
    { 
     //This is the <bluetooth_hardware_address> that I want to connect with. 
     bdDevice = mBluetoothAdapter.getRemoteDevice(device.getAddress()); 
     break; 
    } 
} 

但是有沒有像device.getSerialNumber(),以配合序列號在用戶界面和連接。

+0

無法從設備獲得SN,你只能得到MAC地址。它也是獨一無二的,不用擔心) –

回答

2

當您BluetoothAdapter.startLeScan()掃描BLE設備,您將得到所有BluetoothDevices回調。然後你就可以得到每個BluetoothDevice類解決BluetoothDevice.getAddress()

+1

如果設備已經配對,該怎麼辦?我們能否獲得配對設備的序列號並將其與已知設備的序列號進行匹配。如果匹配,則只能連接,否則不能。 –

+0

查看我的問題更新。 –

+0

@VedPrakash你可以掃描設備,你會得到在範圍內的所有設備,甚至已經粘合。然後你可以得到每個設備的mac地址。在綁定之前,您無法獲得找到的設備的任何其他數據,然後將數據作爲GATT客戶端讀取。 –

0

你可以得到一個設置你的所有保稅設備:

BluetoothAdapter bluetoothAdapter; 
Set<BluetoothDevice> pairedDevices = bluetoothAdapter.getBondedDevices(); 
for (BluetoothDevice device : pairedDevices) { 
    // here you get the mac using device.getAddress() 
} 
+0

沒錯,但我需要將這些配對設備中的每一個與我的給定設備進行匹配,這些設備位於用戶已知我的序列號(不是地址)的用戶界面中。如果任何配對的設備匹配,則連接其他不。我們可以獲得配對設備的序列號以匹配嗎? –

+0

查看我的問題更新。 –

相關問題