Scanning stops while backgrounded if no filters are provided
See original GitHub issueHi there,
I’m trying to run Kable within a LifecycleService
and collect advertisements while the device screen is off (sleeping).
I have to admit I’m having a hard time understanding how to perform this, though I’m able to run a custom Flow while the device screen is off, I can’t get the same success with a simple scan. It works while the app is in background but as soon as I shut the screen off or turn in back on, advertisements stop and start again.
val scanner = Scanner {}
scanner
.advertisements
.onEach { Log.i("TAG", "Scan advertisement => $it") }
.launchIn(lifecycleScope)
Here is a sample repo as an example
And the interesting part is here
Any help would be appreciated, Thanks!
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
How to scan for ble peripherals without uuid filter in ...
I need to scan for iOS device that can't broadcast their UUIDs when in background mode when my android screen is off.
Read more >BLE Android 9 - Scanning stops when screen turned off
The background scan works fine with no filter, just kill the battery. Seems like a dead end at the moment.
Read more >Android Pie (Nokia) - Foreground Scanning Service ...
Scanning works for sometime(1-2 hours) and then scanning stops when the app is kept in background for a long time. Steps to reproduce...
Read more >Android Restrictions You May Encounter During ...
Starting from Android 8 there is a restriction for background scanning — now you can start scan only once per 30 minutes. It...
Read more >How to enable or disable a background scan
A background scan is interrupted when any of the following conditions is met: The computer becomes active again. If an Idle Scan has...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I believe this has been addressed, although the fix is not yet released (currently on the
main
branch).Once the issues for 0.11.0 milestone have been resolved, then that release should have this fix.
Your welcome! This behavior exists since Android 8.1. You can find some refs. here, and here is the culprit.
I’m not sure how you’d like to shape this info into the docs so I’ll let you do it.
EDIT: Some people are reporting that even an empty
scanFilter
is a workaround (for how long until patched?) though I did not test this by myself.Therefore a quickfix might be an option?