NfcTagCache

Simple in-memory cache for the most recently scanned NFC tag.

The host Activity should call update from its onNewIntent() when a tag is discovered via NFC foreground dispatch. ReadNfcTagTool and WriteNfcTagTool operate on whatever tag is cached here.

Alongside the Tag handle, update snapshots the tag's NDEF contents as delivered at discovery time (Ndef.getCachedNdefMessage(), which needs no radio I/O) plus its maxSize / isWritable. Tags usually leave the field long before an LLM asks to read them, so ReadNfcTagTool serves this snapshot (with cached = true) when the live read fails with TagLostException.

Properties

Link copied to clipboard

the most recently scanned Tag, or null if none seen yet.

Functions

Link copied to clipboard
fun clear()

Clears the cached tag.

Link copied to clipboard
fun update(tag: Tag)

Records tag as the most recently scanned tag and snapshots its NDEF data.

fun update(tag: Tag, message: NdefMessage?)

Records tag as the most recently scanned tag. message overrides the snapshotted NDEF message — pass the first entry of NfcAdapter.EXTRA_NDEF_MESSAGES if you already have it; otherwise the tag's own cached message is used.