public class AdvertisementData extends Object
AdvertisementData
class represents the content of a Bluetooth advertisement data payload.
This helper class may be used to parse the advertisement data received in the
scan result
callback
, by using the parse
method of this class.
This class may also be used in order to build an advertisement data payload which is used in the
start advertising API
, by using the constructor of
this class, its set/add methods and finally its serialize
method.
Constructor and Description |
---|
AdvertisementData()
Creates an advertisement data object with the default advertisement flags and no other content.
|
Modifier and Type | Method and Description |
---|---|
void |
addManufacturerData(int manufacturerId,
byte[] data)
Adds manufacturer data associated with the given manufacturer ID to this advertisement data.
|
void |
addServiceUuid(BluetoothUuid serviceUuid)
Adds a service UUID.
|
short |
getAppearance()
Gets the appearance contained in this advertisement data.
|
String |
getDeviceName()
Gets the device name contained in this advertisement data.
|
byte |
getFlags()
Gets the advertisement flags contained in this advertisement data.
|
byte[] |
getManufacturerData(int manufacturerId)
Gets the manufacturer data associated with the given manufacturer ID contained in this advertisement data.
|
int |
getNumServiceUuids()
Gets the number of service UUIDs.
|
BluetoothUuid |
getServiceUuid(int index)
Gets the service UUID at the given index.
|
static AdvertisementData |
parse(byte[] data)
Parses the given advertisement data payload and returns an advertisement data object.
|
byte[] |
serialize()
Serializes this advertisement data into a byte array.
|
void |
setAppearance(short appearance)
Sets the appearance of this advertisement data.
|
void |
setDeviceName(String deviceName)
Sets the device name of this advertisement data.
|
void |
setFlags(int flags)
Sets the advertisement flags of this advertisement data.
|
public AdvertisementData()
public void addManufacturerData(int manufacturerId, byte[] data)
manufacturerId
- the manufacturer ID.data
- the manufacturer data.public void addServiceUuid(BluetoothUuid serviceUuid)
serviceUuid
- the service UUID.public short getAppearance()
0
if it is not defined.@Nullable public String getDeviceName()
null
if it is not defined.public byte getFlags()
AdvertisementFlags
).@Nullable public byte[] getManufacturerData(int manufacturerId)
manufacturerId
- the manufacturer ID.null
if it is not defined.public int getNumServiceUuids()
public BluetoothUuid getServiceUuid(int index)
index
- the index of the service UUID.IndexOutOfBoundsException
- if the index is out of range (index < 0 || index >= getNumServiceUuids()
).public static AdvertisementData parse(byte[] data)
data
- the advertisement data payload.public byte[] serialize()
public void setAppearance(short appearance)
appearance
- the appearance.public void setDeviceName(String deviceName)
deviceName
- the device name.public void setFlags(int flags)
flags
- the advertisement flags (see AdvertisementFlags
).