as someone’s who’s just starting to get into Android/Java programming, I’ve read the docs at https://developer.android.com/reference/android/bluetooth/BluetoothAdapter.html#ACTION_DISCOVERY_FINISHED and i’m trying to figure out what whether I would only get ACTION_DISCOVERY_FINISHED when the bluetooth 12 second scan is completed, and it comes back WITH NO DEVICES, or, does it return ACTION_DISCOVERY_FINISHED every time it scans, and it has some sort of return code that I don’t see in the docs?
The scenario is: I’m building a broadcast receiver that would listen in to BT, and if it is turned on, starts discovery and ends discovery AND finds nothing, I wanna turn off BT.
If it does return codes, I would love a link/the codes themselves.
Thanks for reading and helping out!
The ACTION_DISCOVERY_FINISHED tells you that discovery has finished, no more or less.
There is a separate Intent, ACTION_FOUND, that is sent when a device is discovered.
To accomplish your desired functionality, you want to check in your broadcast receiver
If an intent is received such that this evaluates to true, then you have discovered a BluetoothDevice. If you want to do processing on that device, you can access it via
Edit: If you only want to know that no devices were found, you can just set a flag in the ACTION_FOUND-handling code. If the flag isn’t set, then no devices were found.
EDIT2: The process of Bluetooth Device discovery will send out this sequence of intents:
1 ACTION_DISCOVERY_STARTED
0 or more ACTION_FOUND
1 ACTION_DISCOVERY_ENDED