Home > Enterprise >  How to covert UUID to 16bit in android kotlin
How to covert UUID to 16bit in android kotlin

Time:10-09

I am working on bluetooth in my application. I found the article to display allocated UUID from the enter image description here

Another error

Type mismatch.
Required:
ParcelUuid!
Found:
ByteArray

or

Type mismatch.
Required:
ParcelUuid!
Found:
String

val scanFilter = ScanFilter.Builder().setServiceUuid(setServiceData, serviceUuidMaskString).build()

enter image description here

CodePudding user response:

You can express a 16-bit service UUID as a 128-bit service UUID like this:

0000xxxx-0000-1000-8000-00805F9B34FB

So for Blood Pressure Management with 16-bit Service UUID 0x2A35 you can use:

00002A35-0000-1000-8000-00805F9B34FB

And for Blood Pressure with 16-bit Service UUID 0x1810 you can use:

00001810-0000-1000-8000-00805F9B34FB

You can only put one service UUID in a single filter, so if you want to look for both, you need to use two filters. Here's how you do that:

val filter1 = ScanFilter.Builder().setServiceUuid(ParcelUuid(
  UUID.fromString("00002A35-0000-1000-8000-00805F9B34FB"))).build();

val filter2 = ScanFilter.Builder().setServiceUuid(ParcelUuid(
  UUID.fromString("00001810-0000-1000-8000-00805F9B34FB"))).build();

scanFilterList.add(scanFilter1)
scanFilterList.add(scanFilter2)
  • Related