In Android, it is not possible to directly start a Bluetooth scan after you enabled Bluetooth on a device. If you would do this, you will get the following error:
D/BluetoothLeScanner: Scan failed, reason: app registration failed
The onScanFailed
method will be called with error code 2 in the implemented ScanCallBack
. Not much is known behind the reason of this error. But I found out the following (after a few hours of trying):
If you would wait ~5 seconds after you enabled Bluetooth and then start a scan (so not directly), it works. The scan starts with success. I came up with this temporary solution by the first answer of this question: Android BLE: "Scan failed, reason app registration failed for UUID"
As you can see that question is over a year old, however the questioner is using a separate Android library to handle BLE.
My question is, is there a better solution than the one I described above?