public abstract class Tag

  1. Object
  2. Tag

A tag discovered by Nfc.readTag(NfcReadOptions) or Nfc.addTagListener(NfcListener). The lifetime of a Tag is tied to the reader session that produced it: once the tag leaves the field (or the caller closes the session) all subsequent calls on this instance fail with NfcError.TAG_LOST.

Apps inspect the tag via getTypes() to learn which technologies are available and call one of:

A Tag may return null from a technology accessor when the underlying tag does not support that technology (consult supports(TagType) first). Ports subclass Tag to provide the native transceive implementation – application code never instantiates Tag directly.

Constructors

protected Tag(Set<TagType> types, byte[] id)Subclasses populate the technology list and (when known) the tag’s hardware UID.

Methods

public final Set<TagType> getTypes()Technologies advertised by this tag.
public final boolean supports(TagType t)Convenience: getTypes().contains(t).
public final byte[] getId()Tag’s hardware identifier (NFCA.uid on iOS / Tag.getId() on Android).
public AsyncResource<NdefMessage> readNdef()Reads the NDEF message currently stored on this tag.
public AsyncResource<Boolean> writeNdef(NdefMessage message)Writes (or overwrites) the NDEF message on this tag.
public AsyncResource<Boolean> makeReadOnly()Permanently locks the tag’s NDEF area against future writes.
public int getMaxNdefSize()Largest NDEF message size (in bytes) that fits on this tag.
public boolean isWritable()true when the tag’s NDEF area is writable.
public boolean hasNdef()Convenience: true when readNdef() returns at least one NdefRecord right now.
public IsoDep getIsoDep()Returns an IsoDep view of this tag for ISO 7816 / EMV / passport APDU exchange, or null if the tag does not advertise TagType.ISO_DEP.
public MifareClassic getMifareClassic()Returns a MifareClassic view of this tag, or null when not supported.
public MifareUltralight getMifareUltralight()Returns a MifareUltralight view, or null when not supported.
public NfcA getNfcA()Raw NFC-A (ISO 14443-3A) transceive view, or null.
public NfcB getNfcB()Raw NFC-B (ISO 14443-3B) transceive view, or null.
public NfcF getNfcF()Raw FeliCa (JIS X 6319-4) transceive view, or null.
public NfcV getNfcV()Raw ISO 15693 / vicinity transceive view, or null.

Inherited methods

Constructor details

Tag

protected Tag(Set<TagType> types, byte[] id)
Subclasses populate the technology list and (when known) the tag’s hardware UID. Pass an empty array for id if the platform does not expose one.

Method details

getTypes

public final Set<TagType> getTypes()
Technologies advertised by this tag. Always at least one entry on a discovered tag; an empty set indicates a tag the platform could not classify (rare).

supports

public final boolean supports(TagType t)
Convenience: getTypes().contains(t).

getId

public final byte[] getId()
Tag’s hardware identifier (NFCA.uid on iOS / Tag.getId() on Android). Defensively copied. Returns an empty array if the platform did not surface a UID.

readNdef

public AsyncResource<NdefMessage> readNdef()
Reads the NDEF message currently stored on this tag. Fails with NfcError.UNSUPPORTED_TAG if supports(TagType) of TagType.NDEF is false.

writeNdef

public AsyncResource<Boolean> writeNdef(NdefMessage message)
Writes (or overwrites) the NDEF message on this tag. Fails with NfcError.READ_ONLY if the tag has been locked, and with NfcError.CAPACITY_EXCEEDED when the serialised message is larger than getMaxNdefSize(). Default implementation reports NfcError.UNSUPPORTED_TAG.

makeReadOnly

public AsyncResource<Boolean> makeReadOnly()
Permanently locks the tag’s NDEF area against future writes. Not all tags expose this operation – on those the call fails with NfcError.UNSUPPORTED_TAG. Irreversible – a locked tag cannot be re-armed.

getMaxNdefSize

public int getMaxNdefSize()
Largest NDEF message size (in bytes) that fits on this tag. Returns -1 when the platform does not expose the figure (iOS Core NFC hides it on non-NDEF-formatted tags).

isWritable

public boolean isWritable()
true when the tag’s NDEF area is writable. Defaults to false on the base class.

hasNdef

public boolean hasNdef()
Convenience: true when readNdef() returns at least one NdefRecord right now. Defaults to supports(TagType.NDEF).

getIsoDep

public IsoDep getIsoDep()
Returns an IsoDep view of this tag for ISO 7816 / EMV / passport APDU exchange, or null if the tag does not advertise TagType.ISO_DEP.

getMifareClassic

public MifareClassic getMifareClassic()
Returns a MifareClassic view of this tag, or null when not supported. iOS always returns null for MIFARE Classic.

getMifareUltralight

public MifareUltralight getMifareUltralight()
Returns a MifareUltralight view, or null when not supported.

getNfcA

public NfcA getNfcA()
Raw NFC-A (ISO 14443-3A) transceive view, or null.

getNfcB

public NfcB getNfcB()
Raw NFC-B (ISO 14443-3B) transceive view, or null. Android-only.

getNfcF

public NfcF getNfcF()
Raw FeliCa (JIS X 6319-4) transceive view, or null.

getNfcV

public NfcV getNfcV()
Raw ISO 15693 / vicinity transceive view, or null. Android-only.