• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps BluetoothAdapter List

mcdom34

Lurker
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:
Set<BluetoothDevice> pairedDevices = mBluetoothAdapter.getBondedDevices();
		if (pairedDevices.size() > 0) {
		    for (BluetoothDevice device : pairedDevices)
		        mArrayAdapter.add(device.getName());
		} 
					
		final BroadcastReceiver mReceiver = new BroadcastReceiver() {
		   public void onReceive(Context context, Intent intent) {
		       String action = intent.getAction();
		       		if (BluetoothDevice.ACTION_FOUND.equals(action)) {
		       			BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
					    mArrayAdapter.add(device.getName());
					 }
		   }
		};
For some reason, the array list isn't populating. Any suggestions? Also, how can I display the array list in a ListView
 
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.
 
Back
Top Bottom