Code example for NdefRecord

Methods: getPayload, getTnf, getType

0
     * 
     * @throws IllegalArgumentException if the NdefRecord is not a record 
     *         containing a URI. 
     */ 
    public static ParsedUriRecord parse(NdefRecord record) {
        short tnf = record.getTnf();
        if (tnf == NdefRecord.TNF_WELL_KNOWN) {
            return parseWellKnown(record);
        } else if (tnf == NdefRecord.TNF_ABSOLUTE_URI) {
            return parseAbsolute(record);
        } 
        throw new IllegalArgumentException("Unknown TNF " + tnf);
    } 
 
    /** Parse and absolute URI record */ 
    private static ParsedUriRecord parseAbsolute(NdefRecord record) {
        byte[] payload = record.getPayload();
        Uri uri = Uri.parse(new String(payload, Charset.forName("UTF-8")));
        return new ParsedUriRecord(uri);
    } 
 
    /** Parse an well known URI record */ 
    private static ParsedUriRecord parseWellKnown(NdefRecord record) {
        Preconditions.checkArgument(Arrays.equals(record.getType(), NdefRecord.RTD_URI));
        byte[] payload = record.getPayload();
        /* 
         * payload[0] contains the URI Identifier Code, per the 
         * NFC Forum "URI Record Type Definition" section 3.2.2. 
         * 
         * payload[1]...payload[payload.length - 1] contains the rest of