如何识别Eddystone URL和uid?

4 android bluetooth-lowenergy android-bluetooth ibeacon-android eddystone

我希望在不使用 Proximity Beacon API 或附近消息 API 的情况下检测 Eddystone Ul 和 uid。我希望使用原生 Android 库(如 BluetoothAdapter、BluetoothGatt 或 BluetoothGap)来解析 eddystone 帧。这可行吗?如果是的话,如何进行?如果不可行,那么还有什么替代方案?

小智 5

所有 Eddystone 数据都包含在蓝牙 4.0(“低能耗”、“BLE”)广告数据包中,因此不需要BluetoothGattBluetoothGap。使用BluetoothLeScanner代替。在onScanResult回调中,您可以通过以下方式访问广告数据:

// assuming `result` is the ScanResult passed to the `onScanResult` callback
byte[] rawData = result
    .getScanRecord()
    .getServiceData(ParcelUuid.fromString("0000FEAA-0000-1000-8000-00805F9B34FB"));
Run Code Online (Sandbox Code Playgroud)

然后,您需要根据 Eddystone 规范解析字节:

UID: https://github.com/google/eddystone/tree/master/eddystone-uid
URL: https://github.com/google/eddystone/tree/master/eddystone-url

Eddystone 存储库中还包含一个示例项目,因此您可以从那里开始,也许可以重用一些代码:

https://github.com/google/eddystone/tree/master/tools/eddystone-validator

  • 非常感谢您的回答。我想知道“0000FEAA-0000-1000-8000-00805F9B34FB”代表什么? (2认同)
  • FEAA 是 Eddystone 使用的 16 位蓝牙服务 UUID。较长的 0000FEAA-0000-1000-8000-00805F9B34FB 是此蓝牙服务 UUID 的 64 位表示形式。 (2认同)