1. Are you ready for the Galaxy S20? Here is everything we know so far!

BluetoothAdapter List

Discussion in 'Android Development' started by mcdom34, Dec 8, 2013.

  1. mcdom34

    mcdom34 Lurker
    Thread Starter

    Hello all!

    I'm writing a small program in which I'm using my phone to detect Bluetooth devices. I'm currently stuck on populating an array list with the names of all the device names that have Bluetooth.
    Code (Text):
    2. Set<BluetoothDevice> pairedDevices = mBluetoothAdapter.getBondedDevices();
    3.         if (pairedDevices.size() > 0) {
    4.             for (BluetoothDevice device : pairedDevices)
    5.                 mArrayAdapter.add(device.getName());
    6.         }
    8.         final BroadcastReceiver mReceiver = new BroadcastReceiver() {
    9.            public void onReceive(Context context, Intent intent) {
    10.                String action = intent.getAction();
    11.                     if (BluetoothDevice.ACTION_FOUND.equals(action)) {
    12.                         BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
    13.                         mArrayAdapter.add(device.getName());
    14.                      }
    15.            }
    16.         };
    For some reason, the array list isn't populating. Any suggestions? Also, how can I display the array list in a ListView

    1. Download the Forums for Android™ app!


  2. Rukbat

    Rukbat Extreme Android User

    How about displaying pairedDevices.size() first. If it's 0, the array is populating exactly as it should - with 0 elements.

    Something is also bothering me about this construct

    for (BluetoothDevice device : pairedDevices)

    but I can't put my finger on it.

Share This Page