public final class IsoDep extends Object
Tag
.
Acquire an IsoDep
object using get(android.nfc.Tag)
.
The primary ISO-DEP I/O operation is transceive(byte[])
. Applications must
implement their own protocol stack on top of transceive(byte[])
.
Tags that enumerate the IsoDep
technology in Tag.getTechList()
will also enumerate
NfcA
or NfcB
(since IsoDep builds on top of either of these).
Note: Methods that perform I/O operations
require the android.Manifest.permission#NFC
permission.
Modifier and Type | Field and Description |
---|---|
static String |
EXTRA_HI_LAYER_RESP |
static String |
EXTRA_HIST_BYTES |
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 IsoDep |
get(Tag tag)
Get an instance of
IsoDep for the given tag. |
byte[] |
getHiLayerResponse()
Return the higher layer response bytes for
NfcB tags. |
byte[] |
getHistoricalBytes()
Return the ISO-DEP historical bytes for
NfcA tags. |
int |
getMaxTransceiveLength()
Return the maximum number of bytes that can be sent with
transceive(byte[]) . |
Tag |
getTag()
Get the
Tag object backing this TagTechnology object. |
int |
getTimeout()
Get the current timeout for
transceive(byte[]) in milliseconds. |
boolean |
isConnected()
Helper to indicate if I/O operations should be possible.
|
boolean |
isExtendedLengthApduSupported()
Standard APDUs have a 1-byte length field, allowing a maximum of
255 payload bytes, which results in a maximum APDU length of 261 bytes.
|
void |
reconnect()
Re-connect to the
Tag associated with this connection. |
void |
setTimeout(int timeout)
Set the timeout of
transceive(byte[]) in milliseconds. |
byte[] |
transceive(byte[] data)
Send raw ISO-DEP data to the tag and receive the response.
|
public static final String EXTRA_HI_LAYER_RESP
public static final String EXTRA_HIST_BYTES
public IsoDep(Tag tag) throws RemoteException
RemoteException
public static IsoDep get(Tag tag)
IsoDep
for the given tag.
Does not cause any RF activity and does not block.
Returns null if IsoDep
was not enumerated in Tag.getTechList()
.
This indicates the tag does not support ISO-DEP.
tag
- an ISO-DEP compatible tagpublic void setTimeout(int timeout)
transceive(byte[])
in milliseconds.
The timeout only applies to ISO-DEP transceive(byte[])
, 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[])
in milliseconds.
Requires the android.Manifest.permission#NFC
permission.
public byte[] getHistoricalBytes()
NfcA
tags.
Does not cause any RF activity and does not block.
The historical bytes can be used to help identify a tag. They are present
only on IsoDep
tags that are based on NfcA
RF technology.
If this tag is not NfcA
then null is returned.
In ISO 14443-4 terminology, the historical bytes are a subset of the RATS response.
NfcA
tagpublic byte[] getHiLayerResponse()
NfcB
tags.
Does not cause any RF activity and does not block.
The higher layer response bytes can be used to help identify a tag.
They are present only on IsoDep
tags that are based on NfcB
RF technology. If this tag is not NfcB
then null is returned.
In ISO 14443-4 terminology, the higher layer bytes are a subset of the ATTRIB response.
NfcB
tagpublic byte[] transceive(byte[] data) throws IOException
Applications must only send the INF payload, and not the start of frame and
end of frame indicators. Applications do not need to fragment the payload, it
will be automatically fragmented and defragmented by transceive(byte[])
if
it exceeds FSD/FSC limits.
Use getMaxTransceiveLength()
to retrieve the maximum number 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
- command bytes to send, must not be nullTagLostException
- 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 boolean isExtendedLengthApduSupported()
Standard APDUs have a 1-byte length field, allowing a maximum of 255 payload bytes, which results in a maximum APDU length of 261 bytes.
Extended length APDUs have a 3-byte length field, allowing 65535 payload bytes.
Some NFC adapters, like the one used in the Nexus S and the Galaxy Nexus do not support extended length APDUs. They are expected to be well-supported in the future though. Use this method to check for extended length APDU support.
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
- if an I/O error occursTagTechnology.connect()