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. This class provides implementations of hashCode() and equals() that make it suitable for use as keys in standard implementations of java.util.Map.

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?)

Indicates whether some other object is "equal to" this one.

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

Convert this MacAddress to a byte array.

String

String

Returns a human-readable representation of this MacAddress.

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

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
obj the reference object with which to compare.
o This value may be null.
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 30
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 30
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

Convert this MacAddress to a byte array. The returned array is in network order. For example, if this MacAddress is 01:02:03:04:05:06, the returned array is [1, 2, 3, 4, 5, 6].

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 human-readable representation of this MacAddress. The exact format is implementation-dependent and should not be assumed to have any particular format.

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. This value cannot be null.
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!>