Android BLE // Using custom service UUID

左心房为你撑大大i 提交于 2020-01-02 07:09:12

问题


We are developping a custom bluetooth low energy peripheral and we need to define our custom service. Based on this link: https://www.bluetooth.org/en-us/specification/assigned-numbers/service-discovery

All short UUID (16 bits) are reserved pending future revisions of the BT services specs. And it seems that current version of Android (4.4) doesn't support the 128 bits UUID.

So basically i can't use a 16 bits UUID for defining my service, but i can't filter my services with Android for a 128 bits UUID. Anyone got an idea on the best way to implement it ? Thanks


回答1:


I'm still not sure if it's ok to use custom 16 bits UUIDS so we manage to do something else based on this SO question. startLeScan with 128 bit UUIDs doesn't work on native Android BLE implementation

We scan all the devices and search for our service in the byte[] scanRecord returned by the LeScanCallback.




回答2:


Apparently not all 16 bit UUIDs are reserved. The mentioned UUIDs and UUIDs in range 0x000E – 0x01FF are reserved. I have used the UUIDs FFF0 - FFFA for my custom profile and it is still working fine.

Take a look at simpleGATTProfile in TI's simple peripheral example.




回答3:


The 16-bit UUID is a shortcut for a longer UUID. For example, blood-pressure UUID (0x1810) is the same as

UUID.fromString("00001810-0000-1000-8000-00805F9B34FB")

With that, you can do:

val ids = arrayOf(UUID.fromString("00001810-0000-1000-8000-00805F9B34FB"))
startLeScan(ids, myCallback)


来源:https://stackoverflow.com/questions/21428455/android-ble-using-custom-service-uuid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!