BLE obtain uuid encoded in advertising packet

后端 未结 5 1263
孤城傲影
孤城傲影 2020-12-02 13:49

Im trying to get UUID of ble device. I was following android developers guide and so far I can get only device name and rssi. Im trying to get Uuid of the device that comes

5条回答
  •  星月不相逢
    2020-12-02 14:11

    As mentioned in comments, a BLE device doesn't really have a specific UUID (but rather many for included services). However, some schemes such as iBeacon encode a unique identifier in a manufacturer-specific data record in an advertising packet.

    Here's a quite inefficient but conceptually simple way to convert the entire scanRecord to a hex string representation for debug printing:

    String msg = "payload = ";
    for (byte b : scanRecord)
      msg += String.format("%02x ", b);
    

    Note that this will include both the actual advertising packet and a number of meaningless trailing bytes, which should be ignored after parsing the structure (length field) contained in the advertising packet itself.

提交回复
热议问题