2

I'm currently making an app in Android Studio that should communicate with the HC06 Bluetooth Module. I've started with a code I found online here : http://android-er.blogspot.com/2015/10/android-communicate-with-arduino-hc-06.html

It works but I'm trying to understand the following part (the comments are mine so it may be wrong)

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);

    }
}

Why is the "PairedDeviceList" needed? I had the PairedDevices list that holds the Bluetooth devices. Also, I'm not sure how an "adapter" object works, so if u could help me with some explanation it would mean a lot. If you could find an easier way to list the devices feel free to share, please. Thanks

Shalu T D
  • 3,921
  • 2
  • 26
  • 37

0 Answers0