Package ej.bluetooth.util
Class AdvertisementData
- java.lang.Object
-
- ej.bluetooth.util.AdvertisementData
-
public class AdvertisementData extends java.lang.ObjectTheAdvertisementDataclass 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 theparsemethod 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 itsserializemethod.
-
-
Constructor Summary
Constructors Constructor Description AdvertisementData()Creates an advertisement data object with the default advertisement flags and no other content.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddManufacturerData(int manufacturerId, byte[] data)Adds manufacturer data associated with the given manufacturer ID to this advertisement data.voidaddServiceUuid(ej.bluetooth.BluetoothUuid serviceUuid)Adds a service UUID.shortgetAppearance()Gets the appearance contained in this advertisement data.java.lang.StringgetDeviceName()Gets the device name contained in this advertisement data.bytegetFlags()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.intgetNumServiceUuids()Gets the number of service UUIDs.ej.bluetooth.BluetoothUuidgetServiceUuid(int index)Gets the service UUID at the given index.static AdvertisementDataparse(byte[] data)Parses the given advertisement data payload and returns an advertisement data object.byte[]serialize()Serializes this advertisement data into a byte array.voidsetAppearance(short appearance)Sets the appearance of this advertisement data.voidsetDeviceName(java.lang.String deviceName)Sets the device name of this advertisement data.voidsetFlags(int flags)Sets the advertisement flags of this advertisement data.
-
-
-
Method Detail
-
getFlags
public byte getFlags()
Gets the advertisement flags contained in this advertisement data.- Returns:
- the advertisement flags (see
AdvertisementFlags).
-
getDeviceName
@Nullable public java.lang.String getDeviceName()
Gets the device name contained in this advertisement data.- Returns:
- the device name, or
nullif it is not defined.
-
getAppearance
public short getAppearance()
Gets the appearance contained in this advertisement data.- Returns:
- the appearance, or
0if it is not defined.
-
getManufacturerData
@Nullable public byte[] getManufacturerData(int manufacturerId)
Gets the manufacturer data associated with the given manufacturer ID contained in this advertisement data.- Parameters:
manufacturerId- the manufacturer ID.- Returns:
- the manufacturer data associated with the given manufacturer ID, or
nullif it is not defined.
-
getNumServiceUuids
public int getNumServiceUuids()
Gets the number of service UUIDs.- Returns:
- the number of service UUIDs.
-
getServiceUuid
public ej.bluetooth.BluetoothUuid getServiceUuid(int index)
Gets the service UUID at the given index.- Parameters:
index- the index of the service UUID.- Returns:
- the service UUID at the given index.
- Throws:
java.lang.IndexOutOfBoundsException- if the index is out of range (index < 0 || index >= getNumServiceUuids()).
-
setFlags
public void setFlags(int flags)
Sets the advertisement flags of this advertisement data.- Parameters:
flags- the advertisement flags (seeAdvertisementFlags).
-
setDeviceName
public void setDeviceName(java.lang.String deviceName)
Sets the device name of this advertisement data.- Parameters:
deviceName- the device name.
-
setAppearance
public void setAppearance(short appearance)
Sets the appearance of this advertisement data.- Parameters:
appearance- the appearance.
-
addManufacturerData
public void addManufacturerData(int manufacturerId, byte[] data)Adds manufacturer data associated with the given manufacturer ID to this advertisement data.- Parameters:
manufacturerId- the manufacturer ID.data- the manufacturer data.
-
addServiceUuid
public void addServiceUuid(ej.bluetooth.BluetoothUuid serviceUuid)
Adds a service UUID.- Parameters:
serviceUuid- the service UUID.
-
serialize
public byte[] serialize()
Serializes this advertisement data into a byte array.- Returns:
- the serialized payload.
-
parse
public static AdvertisementData parse(byte[] data)
Parses the given advertisement data payload and returns an advertisement data object.- Parameters:
data- the advertisement data payload.- Returns:
- the advertisement data object.
-
-