我想在我的应用中通过蓝牙连接4台设备,连接4台设备后,我想停止再连接任何设备。为此,我需要知道已连接设备的数量。
如何以编程方式找到已连接设备的数量?
答案 0 :(得分:1)
getBondedDevices()
返回一组当前已配对的设备
您可以从其size()
Set<BluetoothDevice> devices = bluetoothAdapter.getBondedDevices();
//deviceS.size()
答案 1 :(得分:0)
BluetoothAdapter btAdapter = BluetoothAdapter.getDefaultAdapter(); 设置设备= btAdapter.getBondedDevices();
if (devices.size() == 0) {
Log.i(TAG, " No paired devices : ");
}
else if (devices.size() > 1) {
Log.i(TAG, " Too many paired devices : " + devices.size() );
// Loop and dump the paired devices
for (BluetoothDevice device : devices) {
Log.i(TAG, " Device: " + device.getName() + ", " + device);
Log.i(TAG, " Address: " + device.getAddress() + ", " + device);
}
}
else {
retVal = devices.iterator().next().getAddress();
}