public class ADPayloadParser extends Object
public void onLeScan(BluetoothDevice device, int rssi, byte[] scanRecord) { List<ADStructure> structures = ADPayloadParser.getInstance()
.parse
(scanRecord);
Modifier and Type | Method and Description |
---|---|
static ADPayloadParser |
getInstance()
Get the singleton instance.
|
List<ADStructure> |
parse(byte[] payload)
Parse a byte sequence as a list of AD structures.
|
List<ADStructure> |
parse(byte[] payload,
int offset,
int length)
Parse a byte sequence as a list of AD structures.
|
void |
registerBuilder(int type,
ADStructureBuilder builder)
Register an AD structure builder for the AD type.
|
void |
registerManufacturerSpecificBuilder(int companyId,
ADManufacturerSpecificBuilder builder)
Register a builder for the company ID.
|
public static ADPayloadParser getInstance()
public void registerBuilder(int type, ADStructureBuilder builder)
Note that a builder for the type Manufacturer Specific Data
(0xFF) should not be registered by this method. Instead, use
registerManufacturerSpecificBuilder(int,
ADManufacturerSpecificBuilder)
.
type
- AD type. The value must be in the range from 0 to 0xFF.builder
- AD structure builder.public void registerManufacturerSpecificBuilder(int companyId, ADManufacturerSpecificBuilder builder)
companyId
- Company ID. The value must be in the range from 0 to 0xFFFF.builder
- A builder.public List<ADStructure> parse(byte[] payload)
payload
- A byte array containing of AD structures.payload
is null
, this method returns null
.public List<ADStructure> parse(byte[] payload, int offset, int length)
Supported AD structures are as follows.
Data Type Value Data Type Name Class 0x01
Flags Flags
0x02
Incomplete List of 16-bit Service Class UUIDs UUIDs
0x03
Complete List of 16-bit Service Class UUIDs UUIDs
0x04
Incomplete List of 32-bit Service Class UUIDs UUIDs
0x05
Complete List of 32-bit Service Class UUIDs UUIDs
0x06
Incomplete List of 128-bit Service Class UUIDs UUIDs
0x07
Complete List of 128-bit Service Class UUIDs UUIDs
0x14
List of 16-bit Service Solicitation UUIDs UUIDs
0x15
List of 128-bit Service Solicitation UUIDs UUIDs
0x16
Service Data - 16-bit UUID ServiceData
0x1F
List of 32-bit Service Solicitation UUIDs UUIDs
0x20
Service Data - 32-bit UUID ServiceData
0x21
Service Data - 128-bit UUID ServiceData
0xFF
Manufacturer Specific Data ADManufacturerSpecific
In addition, some specific Manufacturer Specific Data are supported.
Data Type Value Company ID Company Name Format Class 0xFF
0x004C
Apple, Inc. iBeacon IBeacon
0xFF
0x0105
Ubiquitous Computing Technology Corporation ucode Ucode
0xFF
0x019A
T-Engine Forum ucode Ucode
registerBuilder
and
registerManufacturerSpecificBuilder
can be used to register your
customized parsers for AD structures.
ServiceData
has subclasses. The table below lists the supported
data formats.
Service UUID Format Class 0xFEAA
(Eddystone)Eddystone UID EddystoneUID
0xFEAA
(Eddystone)Eddystone URL EddystoneURL
0xFEAA
(Eddystone)Eddystone TLM EddystoneTLM
payload
- A byte array containing of AD structures.offset
- The offset from which parsing should be started.length
- The length of bytes to be parsed.payload
is null
, this method returns null
.Copyright © 2016. All rights reserved.