question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Scanning stops while backgrounded if no filters are provided

See original GitHub issue

Hi 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:closed
  • Created 2 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
twyattcommented, Jan 6, 2022

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.

1reaction
somqcommented, Jan 6, 2022

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?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found