FileDocCategorySizeDatePackage
IsoDep.javaAPI DocAndroid 5.1 API7913Thu Mar 12 22:22:10 GMT 2015android.nfc.tech

IsoDep

public final class IsoDep extends BasicTagTechnology
Provides access to ISO-DEP (ISO 14443-4) properties and I/O operations on a {@link Tag}.

Acquire an {@link IsoDep} object using {@link #get}.

The primary ISO-DEP I/O operation is {@link #transceive}. Applications must implement their own protocol stack on top of {@link #transceive}.

Tags that enumerate the {@link IsoDep} technology in {@link Tag#getTechList} will also enumerate {@link NfcA} or {@link NfcB} (since IsoDep builds on top of either of these).

Note: Methods that perform I/O operations require the {@link android.Manifest.permission#NFC} permission.

Fields Summary
private static final String
TAG
public static final String
EXTRA_HI_LAYER_RESP
public static final String
EXTRA_HIST_BYTES
private byte[]
mHiLayerResponse
private byte[]
mHistBytes
Constructors Summary
public IsoDep(android.nfc.Tag tag)

hide

        super(tag, TagTechnology.ISO_DEP);
        Bundle extras = tag.getTechExtras(TagTechnology.ISO_DEP);
        if (extras != null) {
            mHiLayerResponse = extras.getByteArray(EXTRA_HI_LAYER_RESP);
            mHistBytes = extras.getByteArray(EXTRA_HIST_BYTES);
        }
    
Methods Summary
public static android.nfc.tech.IsoDepget(android.nfc.Tag tag)
Get an instance of {@link IsoDep} for the given tag.

Does not cause any RF activity and does not block.

Returns null if {@link IsoDep} was not enumerated in {@link Tag#getTechList}. This indicates the tag does not support ISO-DEP.

param
tag an ISO-DEP compatible tag
return
ISO-DEP object


                                                         
         
        if (!tag.hasTech(TagTechnology.ISO_DEP)) return null;
        try {
            return new IsoDep(tag);
        } catch (RemoteException e) {
            return null;
        }
    
public byte[]getHiLayerResponse()
Return the higher layer response bytes for {@link 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 {@link IsoDep} tags that are based on {@link NfcB} RF technology. If this tag is not {@link NfcB} then null is returned.

In ISO 14443-4 terminology, the higher layer bytes are a subset of the ATTRIB response.

return
ISO-DEP historical bytes, or null if this is not a {@link NfcB} tag

        return mHiLayerResponse;
    
public byte[]getHistoricalBytes()
Return the ISO-DEP historical bytes for {@link 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 {@link IsoDep} tags that are based on {@link NfcA} RF technology. If this tag is not {@link NfcA} then null is returned.

In ISO 14443-4 terminology, the historical bytes are a subset of the RATS response.

return
ISO-DEP historical bytes, or null if this is not a {@link NfcA} tag

        return mHistBytes;
    
public intgetMaxTransceiveLength()
Return the maximum number of bytes that can be sent with {@link #transceive}.

return
the maximum number of bytes that can be sent with {@link #transceive}.

        return getMaxTransceiveLengthInternal();
    
public intgetTimeout()
Get the current timeout for {@link #transceive} in milliseconds.

Requires the {@link android.Manifest.permission#NFC} permission.

return
timeout value in milliseconds

        try {
            return mTag.getTagService().getTimeout(TagTechnology.ISO_DEP);
        } catch (RemoteException e) {
            Log.e(TAG, "NFC service dead", e);
            return 0;
        }
    
public booleanisExtendedLengthApduSupported()

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.

return
whether the NFC adapter on this device supports extended length APDUs.

        try {
            return mTag.getTagService().getExtendedLengthApdusSupported();
        } catch (RemoteException e) {
            Log.e(TAG, "NFC service dead", e);
            return false;
        }
    
public voidsetTimeout(int timeout)
Set the timeout of {@link #transceive} in milliseconds.

The timeout only applies to ISO-DEP {@link #transceive}, and is reset to a default value when {@link #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 {@link android.Manifest.permission#NFC} permission.

param
timeout timeout value in milliseconds

        try {
            int err = mTag.getTagService().setTimeout(TagTechnology.ISO_DEP, timeout);
            if (err != ErrorCodes.SUCCESS) {
                throw new IllegalArgumentException("The supplied timeout is not valid");
            }
        } catch (RemoteException e) {
            Log.e(TAG, "NFC service dead", e);
        }
    
public byte[]transceive(byte[] data)
Send raw ISO-DEP data to the tag and receive the response.

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 {@link #transceive} if it exceeds FSD/FSC limits.

Use {@link #getMaxTransceiveLength} to retrieve the maximum number of bytes that can be sent with {@link #transceive}.

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 {@link IOException} if {@link #close} is called from another thread.

Requires the {@link android.Manifest.permission#NFC} permission.

param
data command bytes to send, must not be null
return
response bytes received, will not be null
throws
TagLostException if the tag leaves the field
throws
IOException if there is an I/O failure, or this operation is canceled

        return transceive(data, true);