如何获得蓝牙设备作为一个列表? [英] How to get the bluetooth devices as a list?
本文介绍了如何获得蓝牙设备作为一个列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图让我的保税蓝牙设备,但我可以把它作为一个很长的字符串,而不是名单。
I am trying to get my bonded bluetooth devices but I can get it as a long string instead of list.
这是我的code:
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]
。和所有在同一行。
我怎样才能改变它在列表中,而不是所有在同一行?
I am getting something like this: [00:23:7F:1c, f0:09:f1:b4:b0]
. And its all in one line.
How can I change it to be in a list and not all in one line?
另外,我怎样才能获得设备的好记的名称,而不是这些数字?
Also, how can I get the friendly names of the devices and not these numbers?
谢谢!
推荐答案
您应该改变你的code如下:
You should change your code as below:
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));
这篇关于如何获得蓝牙设备作为一个列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文