Companion device pairing: how to filter using UUID?

598 Views Asked by At

I am using Companion device pairing and followed this guide.

I want to scan for devices and filter them using UUID. I tried the following

  val deviceFilter: BluetoothLeDeviceFilter = BluetoothLeDeviceFilter.Builder()
                .setScanFilter(
                        ScanFilter.Builder().setServiceUuid(ParcelUuid(advertisementServiceUuid))
                                .setDeviceName("Heart Rate")
                                .build())
               .build()

and when I filter for device name it works. it doesn't work when I filter using uuid.

any idea why?

2

There are 2 best solutions below

0
On

Are u filtering by using the 16 Bit number? Because u have to take the full 128 Bit to make it work.

0
On

Sorry I can not post a comment:

You are most likely doing it correctly. It is the same story with BT classic, where the problem is that BluetoothDeviceFilter filters devices based on cached UUIDs rather than fresh ones.

Maybe you can confirm this:

  1. try removing the filter,
  2. get the device and run fetchUuidsWithSdp;
  3. connect to the device (making sure to cancel discovery, or whatever other traps Android puts in place for poor developers to stumble into);
  4. disconnect;
  5. add the filter back in - and this time, with Your UUID cached, the filter should work as expected...

You could also try filtering based on one of the services already cached.

This kind of filtering was probably intended for things like smart-watches, where the service runs non-stop. There is a reason why none of the official BT samples use this technology yet. Probably best to try and file a bug report. Good luck!