public class AdvertisementData
extends java.lang.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.
|
short |
getAppearance()
Gets the appearance contained in this advertisement data.
|
java.lang.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.
|
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(java.lang.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 byte getFlags()
AdvertisementFlags
).@Nullable public java.lang.String getDeviceName()
null
if it is not defined.public short getAppearance()
0
if it is not defined.@Nullable public byte[] getManufacturerData(int manufacturerId)
manufacturerId
- the manufacturer ID.null
if it is not defined.public void setFlags(int flags)
flags
- the advertisement flags (see AdvertisementFlags
).public void setDeviceName(java.lang.String deviceName)
deviceName
- the device name.public void setAppearance(short appearance)
appearance
- the appearance.public void addManufacturerData(int manufacturerId, byte[] data)
manufacturerId
- the manufacturer ID.data
- the manufacturer data.public byte[] serialize()
public static AdvertisementData parse(byte[] data)
data
- the advertisement data payload.