-
Notifications
You must be signed in to change notification settings - Fork 158
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handling of onScannerRegistered() status=6 (Scanning too frequently) #18
Comments
Hmm.. I think you'd have to count it in your app. As you wrote, the callback isn't called and as I can imagine, it depends on the Android version and phone manufacturer, because why not. |
@philips77 Sure, I could check if i performed a scan within the last 2 seconds and if that is the case then back off and wait for 2 seconds to go by. But how will i know that is enough? Maybe some manufacturer requires 30 seconds? |
True. So the best idea is to assume that users aren't stupid and aren't changing screens over and over to kill the scanner, or design the app so it's now possible. I don't think anything else could be done, actually. You may also check if you aren't getting any records for some time and write preform some action based on this. |
The correct checking for this "no more than 5 start/stop in 30 seconds" This behavior was documented on developer.android.com when Nougat was in developer preview 4, but since has been removed and didn't make to the official documentation (https://developer.android.com/about/versions/nougat/) For now there's still a copy of that page on the web archive: https://web.archive.org/web/20160820074825/https://developer.android.com/preview/support.html#dp4
To fix this on our app, our scanner is a singleton and we wrapped in a I wonder if that is something that Nordic would be interest in implementing on their library, or they rather leave it as a "thin" compat layer. I hope it helps. |
@budius Nice find. Too bad this is just emitted as an error code when trying to start a scan. I'll leave this issue open for Nordic to decide what they want to do with it. If this is something you want to add to the CompatScanner library or not. |
I'll close the issue here, but marked it with a label and will mentioned it in the Readme. Thanks @budius for all the information. |
Hey @philips77 , I just stumbled about this issue. It seems onScanFailed() is not called, only the following is printed. onScannerRegistered() - status=6 scannerId=-1 mScannerId=0 Shouldn't the onScanFailed() callback be triggered in this case? |
Well... the lib calls it when the native API is called. But in fact the native |
Thanks for this discussion. This issue was driving me nuts until i found the logcat entry "onScannerRegistered() status=6 ...". |
@philips77 I have checked the readme file and seems you have forgotten to add information been discussed here |
My implementation to handle this is below `
` |
Hello,
If a scan is started too often it will fail silently, only printing a onScannerRegistered where you have to read the status code. Is there a way to catch this even? When a scan fails because user or app initiated the scan too often? The ScanCallback does not yeild a onScanFailed.
In my app a scan happens directly when a user enters a certain view, thus toggling in and out of the app (resume/pause) several times will cause the scan to start/stop several times. Sometimes the scan fails to start and thus user is unaware that the scan is not actually running because it fails silently.
The same issue can be found in the nRF Connect app and can be easily reproduced there, happily button mashing the Scan button will cause the app to show a state of scanning (button showing "STOP SCANNING") even though the starting of the scan failed.
I kept getting source code not matching byte code when trying to trace down the error so it was hard for me to research this issue further. Tried looking through the Android Source code but it seems like they are not propagating this information to layers above:
https://android.googlesource.com/platform/frameworks/base/+/refs/heads/master/core/java/android/bluetooth/le/BluetoothLeScanner.java#394
Is there any way to know if you are scanning to often and let the user know or just delay the scan until the module is ready?
Best regards
David
The text was updated successfully, but these errors were encountered: