2

我目前正在 Android Studio 中制作一个应该与 HC06 蓝牙模块通信的应用程序。我从我在网上找到的代码开始: http ://android-er.blogspot.com/2015/10/android-communicate-with-arduino-hc-06.html

它有效,但我试图理解以下部分(评论是我的,所以可能是错误的)

private void setup() {
    //store the bluetooth bonded devices in Bluetooth Devices List
    Set<BluetoothDevice> PairedDevices = BluetoothAdapter.getBondedDevices();
    // check if we have something in the list
    if (PairedDevices.size() > 0) {
        PairedDeviceArrayList = new ArrayList<BluetoothDevice>();
        //add each Bluetooth Device in an array
        for (BluetoothDevice device : PairedDevices) {
            PairedDeviceArrayList.add(device);//put everything in a
        }
        PairedDeviceAdapter = new ArrayAdapter<BluetoothDevice>(this, android.R.layout.simple_list_item_1, PairedDeviceArrayList);
        ListViewPairedDevice.setAdapter(PairedDeviceAdapter);

    }
}

为什么需要“PairedDeviceList”?我有包含蓝牙设备的 PairedDevices 列表。另外,我不确定“适配器”对象是如何工作的,所以如果你能帮我解释一下,那将意味着很多。如果您能找到一种更简单的方法来列出设备,请随时分享。谢谢

4

0 回答 0