2014-12-26 59 views
0

我正面臨藍牙API的問題 我想要獲取綁定設備的列表與我們的SDK之一將連接並繼續卡處理,我們面臨的問題是getBonded方法的BTAdapter返回不可修改的哈希集,有沒有什麼辦法可以改變序列,以便我們的第三部分SDK連接到我想要的設備?配對的藍牙設備總是返回哈希集

+0

你試圖將設備添加到組?這聽起來像你應該使用其他方法來添加一個新的設備... –

+0

我不是想添加新設備。我試圖回顧配對設備和框架返回集,它是不可修改的..任何想法? –

+0

那是不是你想要的?你會得到一組配對的設備。爲什麼重要的是它是不可修改的? –

回答

0

this website

如果您在BluetoothAdapter調用方法 「getBondedDevices」, 它返回:

不可修改集BluetoothDevice類的,或空的錯誤

如果您想要更改BondedDevices對象的序列,請使用ArrayList。

下面是示例代碼:

BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); 
Set<BluetoothDevice> myBondedDevices = mBluetoothAdapter.getBondedDevices(); 
// change the set of the Bluetooth devices to modifiable object 
ArrayList<BluetoothDevice> myBondedDevices2 = new ArrayList<BluetoothDevice>(); 
for (BluetoothDevice device: myBondedDevices){ 
    myBondedDevices2.add(device); 
}