How to react to directed advertising (ADV_DIRECT_IND == 0001
) in Android?
There is a BLE-gadget which sends directed advertising to an Android phone (using hardcoded MAC address of the phone for now) and in my Android app I would like to react and to initiate a connection to the gadget and read the org.bluetooth.characteristic.location_and_speed value from the gadget:
Please advise if it's possible by the means of Android 5 API.
To partially answer the open question:
I've noticed that the
ScanRecord.getBytes()
is empty - all '\0' - for a directed scan (ADV_DIRECT_IND
) - but would contain the advertising data otherwise (ADV_IND
).Direct advertising does work - at least with HTC M8 phone and Android 5.0 (API level 21 and higher).
The solution has been to add the device addresses to the ScanFilter.
If you leave the filters empty, the scanning callbacks won't be called.
Here my working code:
First the method for initializing BLE:
And then the scanning callbacks:
Finally the code to start the scanning:
One question is still open though:
I don't know how to detect the type of scan at the Android side - that is if the scan was directed or not.