Android-Scanner-Compat-Library
Android-Scanner-Compat-Library copied to clipboard
Android 14 - Samsung devices do receive notification when beacon is present.
When the app is in the background, and a beacon comes into range, app does not receive notification that beacon is present. The beacon can be around for quite a bit of time with no detection.
If I open up the system settings and navigate to BT menu, I can see the beacon. As soon as this happens, the app receives the notification the beacon is present. The Nordic Scanner library does not seem to be performing scans in the background at all.
NOTE: We have tested this on quite a few devices. It is most prevalent on Samsung but does occasionally occur on Pixel phones as well.
Hello,
Remember, to set a filter and setUseHardwareFilteringIfSupported(true):
https://github.com/NordicSemiconductor/Android-Scanner-Compat-Library/blob/9e4094195ae2ea44617eca851ad208dda8143ec6/scanner/src/main/java/no/nordicsemi/android/support/v18/scanner/ScanSettings.java#L517
With this disabled Android will stop scanning when app goes to background. Also, the filter can't be empty. It is checked in Android 14 and wasn't checked in ~Android 11.
We are definitely setting a ScanFilter based on the Device address.
for (device in devices) {
Log.d(LOG_TAG, "Set background filter for $device")
scanFilters.add(ScanFilter.Builder().setDeviceAddress(device.address).build())
}
What is the default value for setUseHardwareFilteringIfSupported?
I have also added setUseHardwareFilteringIfSupported(true) to the ScanSettings.
Is there anything wrong with the ScanSettings we have currently?
val settings = ScanSettings.Builder().apply {
setUseHardwareFilteringIfSupported(true)
setScanMode(ScanSettings.SCAN_MODE_BALANCED)
setReportDelay(0)
setMatchMode(ScanSettings.MATCH_MODE_AGGRESSIVE)
setNumOfMatches(ScanSettings.MATCH_NUM_ONE_ADVERTISEMENT)
setCallbackType(ScanSettings.CALLBACK_TYPE_ALL_MATCHES)
}.build()
Note, that setting a Device Address works ONLY on public address types. If your device is advertising using a random address the scan will not return devices.
Have a look at: https://cs.android.com/android/platform/superproject/main/+/main:packages/modules/Bluetooth/framework/java/android/bluetooth/le/ScanFilter.java;l=747?q=scanfilter
Understood. The address we are setting is the public address and it does not seem to ever change. We have a deployment of our app working fine as is using just the MAC (other than Samsung devices running Android 14). We will add additional filters as backup in case this is the issue, however I don't think this will solve it.
The issue seems to be predominantly on Samsung devices running Android 14. I want to re-iterate that during testing, when a device is NOT responding to a beacon, the user can simply go into the Android System BT settings (this triggers the OS to do a scan)... and this seems to trigger the OS waking up our app. This leads me to believe it is NOT our implementation but maybe a bug in the scanning library OR a bug in the OS.
I think you may use any scanner app, e.g. nRF Connect, not necessarily the BT settings. It's just that when any app is in foreground it triggers scanning, while if an app is in background without filter its scan gets downgraded to opportunistic. That's why your app gets a result if another app is scanning.
The address we are setting is the public address
Are you really using the public address type, and have it registered in IEEE?