Join us for ⁠#Android11: The Beta Launch Show on June 3!
Added in API level 28

MacAddress

class MacAddress : Parcelable
kotlin.Any
   ↳ android.net.MacAddress

Representation of a MAC address. This class only supports 48 bits long addresses and does not support 64 bits long addresses. Instances of this class are immutable.

Summary

Constants

static Int

Indicates a MAC address is the broadcast address.

static Int

Indicates a MAC address is a multicast address.

static Int

Indicates a MAC address is a unicast address.

Inherited constants

Public methods

Int

Boolean
equals(other: Any?)

static MacAddress

Creates a MacAddress from the given byte array representation.

static MacAddress

Creates a MacAddress from the given String representation.

Int

Returns the type of this address.

Inet6Address?

Create a link-local Inet6Address from the MAC address.

Int

Boolean

Boolean
matches(baseAddress: MacAddress, mask: MacAddress)

Checks if this MAC Address matches the provided range.

ByteArray

String

String

Returns a string representation of the object.

Unit
writeToParcel(out: Parcel!, flags: Int)

Properties

static MacAddress!

The MacAddress representing the unique broadcast MAC address.

static Parcelable.Creator<MacAddress!>

Constants

TYPE_BROADCAST

Added in API level 28
static val TYPE_BROADCAST: Int

Indicates a MAC address is the broadcast address.

Value: 3

TYPE_MULTICAST

Added in API level 28
static val TYPE_MULTICAST: Int

Indicates a MAC address is a multicast address.

Value: 2

TYPE_UNICAST

Added in API level 28
static val TYPE_UNICAST: Int

Indicates a MAC address is a unicast address.

Value: 1

Public methods

describeContents

Added in API level 28
fun describeContents(): Int
Return
Int a bitmask indicating the set of special object types marshaled by this Parcelable object instance. Value is either 0 or android.os.Parcelable#CONTENTS_FILE_DESCRIPTOR

equals

Added in API level 28
fun equals(other: Any?): Boolean
Parameters
obj the reference object with which to compare.
Return
Boolean true if this object is the same as the obj argument; false otherwise.

fromBytes

Added in API level 28
static fun fromBytes(addr: ByteArray): MacAddress

Creates a MacAddress from the given byte array representation. A valid byte array representation for a MacAddress is a non-null array of length 6.

Parameters
addr ByteArray: a byte array representation of a MAC address. This value cannot be null.
Return
MacAddress the MacAddress corresponding to the given byte array representation.
Exceptions
java.lang.IllegalArgumentException if the given byte array is not a valid representation.

fromString

Added in API level 28
static fun fromString(addr: String): MacAddress

Creates a MacAddress from the given String representation. A valid String representation for a MacAddress is a series of 6 values in the range [0,ff] printed in hexadecimal and joined by ':' characters.

Parameters
addr String: a String representation of a MAC address. This value cannot be null.
Return
MacAddress the MacAddress corresponding to the given String representation. This value cannot be null.
Exceptions
java.lang.IllegalArgumentException if the given String is not a valid representation.

getAddressType

Added in API level 28
fun getAddressType(): Int

Returns the type of this address.

Return
Int the int constant representing the MAC address type of this MacAddress. Value is android.net.MacAddress.TYPE_UNKNOWN, android.net.MacAddress#TYPE_UNICAST, android.net.MacAddress#TYPE_MULTICAST, or android.net.MacAddress#TYPE_BROADCAST

getLinkLocalIpv6FromEui48Mac

Added in API level R
fun getLinkLocalIpv6FromEui48Mac(): Inet6Address?

Create a link-local Inet6Address from the MAC address. The EUI-48 MAC address is converted to an EUI-64 MAC address per RFC 4291. The resulting EUI-64 is used to construct a link-local IPv6 address per RFC 4862.

Return
Inet6Address? A link-local Inet6Address constructed from the MAC address. This value may be null.

hashCode

Added in API level 28
fun hashCode(): Int
Return
Int a hash code value for this object.

isLocallyAssigned

Added in API level 28
fun isLocallyAssigned(): Boolean
Return
Boolean true if this MacAddress is a locally assigned address.

matches

Added in API level R
fun matches(
    baseAddress: MacAddress,
    mask: MacAddress
): Boolean

Checks if this MAC Address matches the provided range.

Parameters
baseAddress MacAddress: MacAddress representing the base address to compare with. This value cannot be null.
mask MacAddress: MacAddress representing the mask to use during comparison. This value cannot be null.
Return
Boolean true if this MAC Address matches the given range.

toByteArray

Added in API level 28
fun toByteArray(): ByteArray
Return
ByteArray a byte array representation of this MacAddress. This value cannot be null.

toOuiString

Added in API level 28
fun toOuiString(): String
Return
String a String representation of the OUI part of this MacAddress made of 3 hexadecimal numbers in [0,ff] joined by ':' characters. This value cannot be null.

toString

Added in API level 28
fun toString(): String

Returns a string representation of the object. In general, the toString method returns a string that "textually represents" this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method.

The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of:

getClass().getName() + '@' + Integer.toHexString(hashCode())
  
Return
String This value cannot be null.

writeToParcel

Added in API level 28
fun writeToParcel(
    out: Parcel!,
    flags: Int
): Unit
Parameters
dest The Parcel in which the object should be written.
flags Int: Additional flags about how the object should be written. May be 0 or PARCELABLE_WRITE_RETURN_VALUE. Value is either 0 or a combination of android.os.Parcelable#PARCELABLE_WRITE_RETURN_VALUE, and android.os.Parcelable.PARCELABLE_ELIDE_DUPLICATES

Properties

BROADCAST_ADDRESS

Added in API level 28
static val BROADCAST_ADDRESS: MacAddress!

The MacAddress representing the unique broadcast MAC address.

CREATOR

Added in API level 28
static val CREATOR: Parcelable.Creator<MacAddress!>