NdefFormatable
class NdefFormatable : TagTechnology
kotlin.Any | |
↳ | android.nfc.tech.NdefFormatable |
Provide access to NDEF format operations on a Tag
.
Acquire a NdefFormatable
object using get
.
Android devices with NFC must only enumerate and implement this class for tags for which it can format to NDEF.
Unfortunately the procedures to convert unformated tags to NDEF formatted tags are not specified by NFC Forum, and are not generally well-known. So there is no mandatory set of tags for which all Android devices with NFC must support NdefFormatable
.
Note: Methods that perform I/O operations require the android.Manifest.permission#NFC
permission.
Summary
Public methods | |
---|---|
Unit |
close() |
Unit |
connect() |
Unit |
format(firstMessage: NdefMessage!) Format a tag as NDEF, and write a |
Unit |
formatReadOnly(firstMessage: NdefMessage!) Formats a tag as NDEF, write a |
static NdefFormatable! |
Get an instance of |
Tag! |
getTag() |
Boolean |
Public methods
close
fun close(): Unit
Exceptions | |
---|---|
java.lang.Exception |
if this resource cannot be closed |
java.io.IOException |
if an I/O error occurs |
java.lang.SecurityException |
if the tag object is reused after the tag has left the field |
connect
fun connect(): Unit
Exceptions | |
---|---|
TagLostException |
if the tag leaves the field |
java.io.IOException |
if there is an I/O failure, or connect is canceled |
java.lang.SecurityException |
if the tag object is reused after the tag has left the field |
format
fun format(firstMessage: NdefMessage!): Unit
Format a tag as NDEF, and write a NdefMessage
.
This is a multi-step process, an IOException is thrown if any one step fails.
The card is left in a read-write state after this operation.
This is an I/O operation and will block until complete. It must not be called from the main application thread. A blocked call will be canceled with IOException
if #close is called from another thread.
Requires the android.Manifest.permission#NFC
permission.
Parameters | |
---|---|
firstMessage |
NdefMessage!: the NDEF message to write after formatting, can be null |
Exceptions | |
---|---|
android.nfc.TagLostException |
if the tag leaves the field |
java.io.IOException |
if there is an I/O failure, or the operation is canceled |
android.nfc.FormatException |
if the NDEF Message to write is malformed |
formatReadOnly
fun formatReadOnly(firstMessage: NdefMessage!): Unit
Formats a tag as NDEF, write a NdefMessage
, and make read-only.
This is a multi-step process, an IOException is thrown if any one step fails.
The card is left in a read-only state if this method returns successfully.
This is an I/O operation and will block until complete. It must not be called from the main application thread. A blocked call will be canceled with IOException
if #close is called from another thread.
Requires the android.Manifest.permission#NFC
permission.
Parameters | |
---|---|
firstMessage |
NdefMessage!: the NDEF message to write after formatting |
Exceptions | |
---|---|
android.nfc.TagLostException |
if the tag leaves the field |
java.io.IOException |
if there is an I/O failure, or the operation is canceled |
android.nfc.FormatException |
if the NDEF Message to write is malformed |
java.lang.SecurityException |
if the tag object is reused after the tag has left the field |
get
static fun get(tag: Tag!): NdefFormatable!
Get an instance of NdefFormatable
for the given tag.
Does not cause any RF activity and does not block.
Returns null if NdefFormatable
was not enumerated in Tag.getTechList
. This indicates the tag is not NDEF formatable by this Android device.
Parameters | |
---|---|
tag |
Tag!: an NDEF formatable tag |
Return | |
---|---|
NdefFormatable! |
NDEF formatable object |
getTag
fun getTag(): Tag!
Return | |
---|---|
Tag! |
the Tag backing this TagTechnology object. |
isConnected
fun isConnected(): Boolean
Return | |
---|---|
Boolean |
true if I/O operations should be possible |