0
我在上述问题中挣扎了一段时间。我想获得配对的蓝牙设备列表(现在看起来很好),并且知道所需的蓝牙模块的MAC地址是什么,只需选择此MAC地址并稍后将其用作参数即可。我试图从列表中选出30:14:10:17:06:93的地址时遇到麻烦。通过蓝牙进行通信时,如何从配对设备组中选择要配对的bt模块?
这里是我的代码片段:
Set<BluetoothDevice> pairedDevices = mBluetoothAdapter.getBondedDevices();
TextView devicesInPairWithPhone = (TextView) findViewById(R.id.devicesInPairWithPhone);
devicesInPairWithPhone.setText(pairedDevices.toString());
for (BluetoothDevice device : pairedDevices) {
if (device.toString().equals("30:14:10:17:06:93")) {
mDevice = device;
textView.setText(device.toString());
}
else {
textView.setText("Selecting the correct bt module was unsuccessful.");
}
}
在这种情况下,对TextView的(我知道,没有一个直观的名字,对不起为)我得到“选择正确的BT模块是不成功的。”所有的时间,即if(){}条件永远不会满足。在devicesInPairWithPhone上,我得到了一个公平的集合:[30:14:10:17:06:93,6C:0E:0D:E2:blablabla,...]
有人知道问题可能是什么?先谢谢你!