FileDocCategorySizeDatePackage
NfcBarcode.javaAPI DocAndroid 5.1 API4522Thu Mar 12 22:22:10 GMT 2015android.nfc.tech

NfcBarcode

public final class NfcBarcode extends BasicTagTechnology
Provides access to tags containing just a barcode.

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

Fields Summary
public static final int
TYPE_KOVIO
Kovio Tags
public static final int
TYPE_UNKNOWN
public static final String
EXTRA_BARCODE_TYPE
private int
mType
Constructors Summary
public NfcBarcode(android.nfc.Tag tag)
Internal constructor, to be used by NfcAdapter

hide

        super(tag, TagTechnology.NFC_BARCODE);
        Bundle extras = tag.getTechExtras(TagTechnology.NFC_BARCODE);
        if (extras != null) {
            mType = extras.getInt(EXTRA_BARCODE_TYPE);
        } else {
            throw new NullPointerException("NfcBarcode tech extras are null.");
        }
    
Methods Summary
public static android.nfc.tech.NfcBarcodeget(android.nfc.Tag tag)
Get an instance of {@link NfcBarcode} for the given tag.

Returns null if {@link NfcBarcode} was not enumerated in {@link Tag#getTechList}.

Does not cause any RF activity and does not block.

param
tag an NfcBarcode compatible tag
return
NfcBarcode object


                                                 
         
        if (!tag.hasTech(TagTechnology.NFC_BARCODE)) return null;
        try {
            return new NfcBarcode(tag);
        } catch (RemoteException e) {
            return null;
        }
    
public byte[]getBarcode()
Returns the barcode of an NfcBarcode tag.

Tags of {@link #TYPE_KOVIO} return 16 bytes:

    The first byte is 0x80 ORd with a manufacturer ID, corresponding to ISO/IEC 7816-6.

    The second byte describes the payload data format. Defined data format types include the following:

    • 0x00: Reserved for manufacturer assignment
    • 0x01: 96-bit URL with "http://www." prefix
    • 0x02: 96-bit URL with "https://www." prefix
    • 0x03: 96-bit URL with "http://" prefix
    • 0x04: 96-bit URL with "https://" prefix
    • 0x05: 96-bit GS1 EPC
    • 0x06-0xFF: reserved

    The following 12 bytes are payload:

    The last 2 bytes comprise the CRC.

Does not cause any RF activity and does not block.

return
a byte array containing the barcode
see
Kovio 128-bit NFC barcode datasheet
see
Kovio 128-bit NFC barcode data format

        switch (mType) {
            case TYPE_KOVIO:
                // For Kovio tags the barcode matches the ID
                return mTag.getId();
            default:
                return null;
        }
    
public intgetType()
Returns the NFC Barcode tag type.

Currently only one of {@link #TYPE_KOVIO} or {@link #TYPE_UNKNOWN}.

Does not cause any RF activity and does not block.

return
the NFC Barcode tag type

        return mType;