Class Tag
java.lang.Object
com.codename1.nfc.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:
readNdef()/writeNdef(NdefMessage)for anyTagType.NDEFtaggetIsoDep()for ISO-7816 smart cards / payment / passportgetMifareClassic()/getMifareUltralight()for NXP MIFAREgetNfcA()/getNfcB()/getNfcF()/getNfcV()for raw low-level transceive
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.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal byte[]getId()Tag's hardware identifier (NFCA.uidon iOS /Tag.getId()on Android).Returns anIsoDepview of this tag for ISO 7816 / EMV / passport APDU exchange, ornullif the tag does not advertiseTagType.ISO_DEP.intLargest NDEF message size (in bytes) that fits on this tag.Returns aMifareClassicview of this tag, ornullwhen not supported.Returns aMifareUltralightview, ornullwhen not supported.getNfcA()Raw NFC-A (ISO 14443-3A) transceive view, ornull.getNfcB()Raw NFC-B (ISO 14443-3B) transceive view, ornull.getNfcF()Raw FeliCa (JIS X 6319-4) transceive view, ornull.getNfcV()Raw ISO 15693 / vicinity transceive view, ornull.getTypes()Technologies advertised by this tag.booleanhasNdef()booleantruewhen the tag's NDEF area is writable.Permanently locks the tag's NDEF area against future writes.readNdef()Reads the NDEF message currently stored on this tag.final booleanConvenience:getTypes().contains(t).writeNdef(NdefMessage message) Writes (or overwrites) the NDEF message on this tag.
-
Constructor Details
-
Tag
-
-
Method Details
-
getTypes
-
supports
Convenience:getTypes().contains(t). -
getId
public final byte[] getId()Tag's hardware identifier (NFCA.uidon iOS /Tag.getId()on Android). Defensively copied. Returns an empty array if the platform did not surface a UID. -
readNdef
Reads the NDEF message currently stored on this tag. Fails withNfcError.UNSUPPORTED_TAGifsupports(TagType)ofTagType.NDEFisfalse. -
writeNdef
Writes (or overwrites) the NDEF message on this tag. Fails withNfcError.READ_ONLYif the tag has been locked, and withNfcError.CAPACITY_EXCEEDEDwhen the serialised message is larger thangetMaxNdefSize(). Default implementation reportsNfcError.UNSUPPORTED_TAG. -
makeReadOnly
Permanently locks the tag's NDEF area against future writes. Not all tags expose this operation -- on those the call fails withNfcError.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-1when the platform does not expose the figure (iOS Core NFC hides it on non-NDEF-formatted tags). -
isWritable
public boolean isWritable()truewhen the tag's NDEF area is writable. Defaults tofalseon the base class. -
hasNdef
public boolean hasNdef()Convenience:truewhenreadNdef()returns at least oneNdefRecordright now. Defaults tosupports(TagType.NDEF). -
getIsoDep
Returns anIsoDepview of this tag for ISO 7816 / EMV / passport APDU exchange, ornullif the tag does not advertiseTagType.ISO_DEP. -
getMifareClassic
Returns aMifareClassicview of this tag, ornullwhen not supported. iOS always returnsnullfor MIFARE Classic. -
getMifareUltralight
Returns aMifareUltralightview, ornullwhen not supported. -
getNfcA
Raw NFC-A (ISO 14443-3A) transceive view, ornull. -
getNfcB
Raw NFC-B (ISO 14443-3B) transceive view, ornull. Android-only. -
getNfcF
Raw FeliCa (JIS X 6319-4) transceive view, ornull. -
getNfcV
Raw ISO 15693 / vicinity transceive view, ornull. Android-only.
-