gpt4 book ai didi

android - 如何将蓝牙设备作为列表获取?

转载 作者:IT老高 更新时间:2023-10-28 22:15:38 25 4
gpt4 key购买 nike

我正在尝试获取绑定(bind)的蓝牙设备,但我可以将其作为长字符串而不是列表获取。

这是我的代码:

BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
Set<BluetoothDevice> pairedDevices = mBluetoothAdapter.getBondedDevices();
ArrayList<String> listview =
new ArrayList<String>(Arrays.asList(pairedDevices.toString()));
setListAdapter(new ArrayAdapter<String>(this, R.layout.list, listview));

我得到这样的东西:[00:23:7F:1c, f0:09:f1:b4:b0]。它都在一条线上。如何将其更改为列表而不是全部在一行中?

另外,我怎样才能得到设备的友好名称而不是这些数字?

谢谢!!!

最佳答案

你应该改变你的代码如下:

BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
Set<BluetoothDevice> pairedDevices = mBluetoothAdapter.getBondedDevices();

List<String> s = new ArrayList<String>();
for(BluetoothDevice bt : pairedDevices)
s.add(bt.getName());

setListAdapter(new ArrayAdapter<String>(this, R.layout.list, s));

关于android - 如何将蓝牙设备作为列表获取?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10795424/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com