Class AdvertisementData


  • public class AdvertisementData
    extends java.lang.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 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
      void addManufacturerData​(int manufacturerId, byte[] data)
      Adds manufacturer data associated with the given manufacturer ID to this advertisement data.
      void addServiceUuid​(ej.bluetooth.BluetoothUuid serviceUuid)
      Adds a service UUID.
      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.
      int getNumServiceUuids()
      Gets the number of service UUIDs.
      ej.bluetooth.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​(java.lang.String deviceName)
      Sets the device name of this advertisement data.
      void setFlags​(int flags)
      Sets the advertisement flags of this advertisement data.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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 java.lang.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 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 (see AdvertisementFlags).
      • 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.