Note that there are some explanatory texts on larger screens.

plurals
  1. POandroid bluetooth discovery: ACTION_FOUND happening after ACTION_DISCOVERY_FINISHED
    text
    copied!<p>I am implementing Bluetooth support via implementing a task which searches for devices in the background and provides a list when the search is complete. However, this list occasionally contains a <code>No devices found</code> entry (added only when <code>ACTION_DISCOVERY_FINISHED</code> is received with no devices already in the list) before listing other devices!</p> <pre><code>private BroadcastReceiver mBlueToothInfoDiscoveryListener = new BroadcastReceiver() { /** * This is an overridden function called by the framework whenever there * is some broadcast message for Bluetooth info discovery listener */ @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); // When discovery finds a device if (BluetoothDevice.ACTION_FOUND.equals(action)) { // Get the BluetoothDevice object from the Intent BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); // If it's already paired, skip it, because it's been listed // already if (device.getBondState() != BluetoothDevice.BOND_BONDED) { mNewBtDevicesArrayAdapter.add(device.getName() + "\n" + device.getAddress()); } } else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) { // When discovery is finished, change the Activity title setProgressBarIndeterminateVisibility(false); setTitle("device list"); if (mNewBtDevicesArrayAdapter.getCount() == 0) { String noDevices = "No devices found"; mNewBtDevicesArrayAdapter.add(noDevices); } } } }; </code></pre> <p>I don't expect <code>ACTION_DISCOVERY_FINISHED</code> to ever come <em>before</em> a <code>ACTION_FOUND</code> event, so why would the <code>No devices found</code> string be added to the list before a device is located?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload