Package ej.bluetooth

Class BluetoothAddress


  • public class BluetoothAddress
    extends Object
    The BluetoothAddress class represents the address of a Bluetooth device.

    Addresses may be created by using the class constructor or retrieved by listening to connection events while scanning.

    A string representation of an address may be retrieved by calling the toString() method of the object. The Object.equals(Object) method may be used in order to check if an address is equal to an other.

    • Constructor Detail

      • BluetoothAddress

        public BluetoothAddress​(byte[] bytes,
                                int offset,
                                boolean isPublic)
        Creates an address from the given byte array.
        Parameters:
        bytes - a byte array containing a Bluetooth address (in big-endian).
        offset - the offset of the address in the byte array.
        isPublic - true to create a public address, false to create a private address.
        Throws:
        ArrayIndexOutOfBoundsException - if the given byte array is not 6 bytes long.
      • BluetoothAddress

        public BluetoothAddress​(String string,
                                boolean isPublic)
        Creates an address from the given string.
        Parameters:
        string - a string representing a Bluetooth address (in big-endian).
        isPublic - true to create a public address, false to create a private address.
        Throws:
        IllegalArgumentException - if the given string does not represent a Bluetooth address.
    • Method Detail

      • getBytes

        public void getBytes​(byte[] buffer,
                             int offset)
        Writes this address to the given byte array.
        Parameters:
        buffer - the buffer to write to (in big-endian).
        offset - the index in the buffer to write at.
        Throws:
        ArrayIndexOutOfBoundsException - if the given buffer is not big enough to hold the address.
      • isPublic

        public boolean isPublic()
        Returns whether this address is a public address.
        Returns:
        true if this address is a public address, false if it is private.