Class AdvertisementData


  • public class AdvertisementData
    extends Object
    The 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 Detail

      • AdvertisementData

        public AdvertisementData()
        Creates an advertisement data object with the default advertisement flags and no other content.
    • Method Detail

      • getFlags

        public byte getFlags()
        Gets the advertisement flags contained in this advertisement data.
        Returns:
        the advertisement flags (see AdvertisementFlags).
      • getDeviceName

        @Nullable
        public String getDeviceName()
        Gets the device name contained in this advertisement data.
        Returns:
        the device name, or null if it is not defined.
      • getAppearance

        public short getAppearance()
        Gets the appearance contained in this advertisement data.
        Returns:
        the appearance, or 0 if 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 null if it is not defined.
      • getNumServiceUuids

        public int getNumServiceUuids()
        Gets the number of service UUIDs.
        Returns:
        the number of service UUIDs.
      • getServiceUuid

        public 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:
        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 (see AdvertisementFlags).
      • setDeviceName

        public void setDeviceName​(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​(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.