I am trying to perform BLE scans in a foreground service (Android 12) after some start scan end stop scan I receive the error SCAN_FAILED_APPLICATION_REGISTRATION_FAILED
, I cannot figure out what is the reason of the error.
I do startScan and stopScan in sequence (the scan is a long-running scan)
The app target SDK 32 so I have the new Bluetooth permissions.
This is the complete scenario:
- I open the app and I start the foreground service
- I close the application (the foreground service is still running)
- The foreground service scan and connect to my device and then I stop scanning
- I turn off my BLE device and the foreground service start to scan again
- I turn on my ble device and the foreground service detect it and connect to it.
- Repeat step 4 and suddenly the error
SCAN_FAILED_APPLICATION_REGISTRATION_FAILED
show.
I also notice this error in the logcat App 'com.sample.xxx' is scanning too much clientif
(I look into AOSP source code and seems that this string is specific of Xiaomi ROM)
https://github.com/appersiano/TestingBackgroundConnection
P.S. Tested on Xiaomi Mi11 Lite 5g
How can I solve?