How to scan for peripherals that have a given service UUID as a key in their service data?
See original GitHub issueI’m trying to scan for peripherals that advertise a key-value pair in their service data where the key is a given service UUID and the value is a unique identifier, different for each peripheral. Those peripherals only use serviceData, they do not advertise the service UUID in serviceUuids.
Here is what I tried so far:
AsyncTask.execute {
val scannedBleServices = mapOf(
"ABC" to ParcelUuid(UUID.fromString("00001234-5678-9012-3456-789012345678"))
)
val scanFilters = scannedBleServices.values.map {
ScanFilter.Builder().setServiceData(it, ByteArray(0)).build()
}
val scanSettings = ScanSettings.Builder()
.setLegacy(false)
.setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY)
.setReportDelay(0L)
.setCallbackType(ScanSettings.CALLBACK_TYPE_ALL_MATCHES)
.setMatchMode(ScanSettings.MATCH_MODE_AGGRESSIVE)
.setNumOfMatches(ScanSettings.MATCH_NUM_ONE_ADVERTISEMENT)
.build()
BluetoothLeScannerCompat.getScanner().startScan(
scanFilters,
scanSettings,
leScanCallback
)
}
But with that, the callback is never called. Note that if I pass null as a first parameter to startScan, my callback does get called, which seems to indicate that I have all the permissions working properly, and I have just a problem with my filters.
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
scanForPeripherals(withServices:options:) - Apple Developer
To do this, your app must explicitly scan for one or more services by specifying them in the serviceUUIDs parameter. The CBCentralManager scan...
Read more >Scanning for BLE peripherals with a scan filter based on ...
My peripheral only advertises the UUID as a key in its serviceData associative array, so I switched to the serviceData filter as follows, ......
Read more >The Ultimate Guide to Apple's Core Bluetooth - Punch Through
Learn the major components of Core Bluetooth, basic steps for scanning, connecting to, and interacting with a BLE peripheral, ...
Read more >Best practice: Advanced BLE scanning process on iOS
The data can be exchange a small of information via BLE packets or the ... First, I will generate 5 UUIDs as the...
Read more >Scan peripherals and filter by service UUID #230 - GitHub
Hi, Is it possible to scan peripherals and only consider those with a specific service UUID? BLE addresses change often if using Android...
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

Oh, good to know. Did you try setting
setUseHardwareFilteringIfSupported(false)and see the difference? Is it an issue in the library or just the system does not filter well? https://github.com/NordicSemiconductor/Android-Scanner-Compat-Library/blob/8df7799441def4db80b7c9055ff99ecb57d9dad3/scanner/src/main/java/no/nordicsemi/android/support/v18/scanner/ScanSettings.java#L511The phone I’m testing with is pretty standard and modern: Samsung Galaxy S9. So if that’s what it takes for it to work, I don’t see a lot of other choices.