public final class NfcF extends Object
Tag
.
Acquire a NfcF
object using get(android.nfc.Tag)
.
The primary NFC-F I/O operation is transceive(byte[])
. Applications must
implement their own protocol stack on top of transceive(byte[])
.
Note: Methods that perform I/O operations
require the android.Manifest.permission#NFC
permission.
Modifier and Type | Field and Description |
---|---|
static String |
EXTRA_PMM |
static String |
EXTRA_SC |
ISO_DEP, MIFARE_CLASSIC, MIFARE_ULTRALIGHT, NDEF, NDEF_FORMATABLE, NFC_A, NFC_B, NFC_BARCODE, NFC_F, NFC_V
Modifier and Type | Method and Description |
---|---|
void |
close()
Disable I/O operations to the tag from this
TagTechnology object, and release resources. |
void |
connect()
Enable I/O operations to the tag from this
TagTechnology object. |
static NfcF |
get(Tag tag)
Get an instance of
NfcF for the given tag. |
byte[] |
getManufacturer()
Return the Manufacturer bytes from tag discovery.
|
int |
getMaxTransceiveLength()
Return the maximum number of bytes that can be sent with
transceive(byte[]) . |
byte[] |
getSystemCode()
Return the System Code bytes from tag discovery.
|
Tag |
getTag()
Get the
Tag object backing this TagTechnology object. |
int |
getTimeout()
Get the current
transceive(byte[]) timeout in milliseconds. |
boolean |
isConnected()
Helper to indicate if I/O operations should be possible.
|
void |
reconnect()
Re-connect to the
Tag associated with this connection. |
void |
setTimeout(int timeout)
Set the
transceive(byte[]) timeout in milliseconds. |
byte[] |
transceive(byte[] data)
Send raw NFC-F commands to the tag and receive the response.
|
public static final String EXTRA_SC
public static final String EXTRA_PMM
public NfcF(Tag tag) throws RemoteException
RemoteException
public static NfcF get(Tag tag)
NfcF
for the given tag.
Returns null if NfcF
was not enumerated in Tag.getTechList()
.
This indicates the tag does not support NFC-F.
Does not cause any RF activity and does not block.
tag
- an NFC-F compatible tagpublic byte[] getSystemCode()
Does not cause any RF activity and does not block.
public byte[] getManufacturer()
Does not cause any RF activity and does not block.
public byte[] transceive(byte[] data) throws IOException
Applications must not append the SoD (length) or EoD (CRC) to the payload, it will be automatically calculated.
Use getMaxTransceiveLength()
to retrieve the maximum amount of bytes
that can be sent with transceive(byte[])
.
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.
data
- bytes to sendTagLostException
- if the tag leaves the fieldIOException
- if there is an I/O failure, or this operation is canceledpublic int getMaxTransceiveLength()
transceive(byte[])
.transceive(byte[])
.public void setTimeout(int timeout)
transceive(byte[])
timeout in milliseconds.
The timeout only applies to transceive(byte[])
on this object,
and is reset to a default value when close()
is called.
Setting a longer timeout may be useful when performing transactions that require a long processing time on the tag such as key generation.
Requires the android.Manifest.permission#NFC
permission.
timeout
- timeout value in millisecondspublic int getTimeout()
transceive(byte[])
timeout in milliseconds.
Requires the android.Manifest.permission#NFC
permission.
public Tag getTag()
TagTechnology
Tag
object backing this TagTechnology
object.getTag
in interface TagTechnology
Tag
backing this TagTechnology
object.public boolean isConnected()
TagTechnology
Returns true if TagTechnology.connect()
has completed, and TagTechnology.close()
has not been
called, and the Tag
is not known to be out of range.
Does not cause RF activity, and does not block.
isConnected
in interface TagTechnology
public void connect() throws IOException
TagTechnology
TagTechnology
object.
May cause RF activity and may block. Must not be called
from the main application thread. A blocked call will be canceled with
IOException
by calling TagTechnology.close()
from another thread.
Only one TagTechnology
object can be connected to a Tag
at a time.
Applications must call TagTechnology.close()
when I/O operations are complete.
Requires the android.Manifest.permission#NFC
permission.
connect
in interface TagTechnology
IOException
- if there is an I/O failure, or connect is canceledTagTechnology.close()
public void reconnect() throws IOException
TagTechnology
Tag
associated with this connection. Reconnecting to a tag can be
used to reset the state of the tag itself.
May cause RF activity and may block. Must not be called
from the main application thread. A blocked call will be canceled with
IOException
by calling TagTechnology.close()
from another thread.
Requires the android.Manifest.permission#NFC
permission.
reconnect
in interface TagTechnology
IOException
- if there is an I/O failure, or connect is canceledTagTechnology.connect()
,
TagTechnology.close()
public void close() throws IOException
TagTechnology
TagTechnology
object, and release resources.
Also causes all blocked I/O operations on other thread to be canceled and
return with IOException
.
Requires the android.Manifest.permission#NFC
permission.
close
in interface TagTechnology
close
in interface Closeable
close
in interface AutoCloseable
IOException
TagTechnology.connect()