public final class NfcB extends Object
Tag
.
Acquire a NfcB
object using get(android.nfc.Tag)
.
The primary NFC-B 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_APPDATA |
static String |
EXTRA_PROTINFO |
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 NfcB |
get(Tag tag)
Get an instance of
NfcB for the given tag. |
byte[] |
getApplicationData()
Return the Application Data bytes from ATQB/SENSB_RES at tag discovery.
|
int |
getMaxTransceiveLength()
Return the maximum number of bytes that can be sent with
transceive(byte[]) . |
byte[] |
getProtocolInfo()
Return the Protocol Info bytes from ATQB/SENSB_RES at tag discovery.
|
Tag |
getTag()
Get the
Tag object backing this TagTechnology object. |
boolean |
isConnected()
Helper to indicate if I/O operations should be possible.
|
void |
reconnect()
Re-connect to the
Tag associated with this connection. |
byte[] |
transceive(byte[] data)
Send raw NFC-B commands to the tag and receive the response.
|
public static final String EXTRA_APPDATA
public static final String EXTRA_PROTINFO
public NfcB(Tag tag) throws RemoteException
RemoteException
public static NfcB get(Tag tag)
NfcB
for the given tag.
Returns null if NfcB
was not enumerated in Tag.getTechList()
.
This indicates the tag does not support NFC-B.
Does not cause any RF activity and does not block.
tag
- an NFC-B compatible tagpublic byte[] getApplicationData()
Does not cause any RF activity and does not block.
public byte[] getProtocolInfo()
Does not cause any RF activity and does not block.
public byte[] transceive(byte[] data) throws IOException
Applications must not append the EoD (CRC) to the payload, it will be automatically calculated.
Applications must not send commands that manage the polling loop and initialization (SENSB_REQ, SLOT_MARKER etc).
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
- 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 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()