Examples of NdefRecord


Examples of net.rim.device.api.io.nfc.ndef.NDEFRecord

             * Work our way through each record in the message in turn
             */
            for (int j = 0; j < numRecords; ++j) {
                log("parseMessage record #" + j);

                NDEFRecord currentRecord = records[j];
                JSONObject jsonRecord = new JSONObject();
                recordsArray.put(jsonRecord);

                log("Processing NDEF record#=" + j);

                typeNameFormat = currentRecord.getTypeNameFormat();
                record_type = records[j].getType();

                if (typeNameFormat == NDEFRecord.TNF_WELL_KNOWN) {
                    if (Constants.NDEF_SMART_POSTER_TYPE.equals(records[j]
                            .getType())) {
View Full Code Here

Examples of net.rim.device.api.io.nfc.ndef.NDEFRecord

        String text = (String) _tag_attrs.get(Constants.TAG_ATTRIBUTE_TEXT);

        NDEFMessage rootMessage = new NDEFMessage(); // (SP (TEXT, URL) message
        NDEFMessage ndefMessage = new NDEFMessage(); // (TEXT, URL) message

        NDEFRecord rootRecord = new NDEFRecord(); // Smart Poster Record
        NDEFRecord tagTitleRecord = new NDEFRecord(); // Tag Title TEXT record
        NDEFRecord tagUrlRecord = new NDEFRecord(); // Tag URL record

        ByteArrayOutputStream titlePayload = new ByteArrayOutputStream(); // to build title
        ByteArrayOutputStream urlPayload = new ByteArrayOutputStream(); // to build URL

        /*
         * ================ Record 0 ===========================================
         *
         * This is the NDEF record that represents the title associated with the URL that will the URL part of the Smart Poster
         * Tag
         */
        titlePayload.write((byte) URL_TEXT_LOCALE.length()); // status byte: character encoding indicator bit plus length of
                                                             // locale language field
        titlePayload.write(URL_TEXT_LOCALE.getBytes("US-ASCII")); // locale language
        /*
         * This is the text to be associated with the Smart Poster Tag
         */
        titlePayload.write(text.getBytes("UTF-8")); // Text
        titlePayload.flush();
        /*
         * Construct the record itself
         */
        tagTitleRecord.setId("0"); // record Id
        tagTitleRecord.setType(NDEFRecord.TNF_WELL_KNOWN, "T"); // It's TEXT type
        tagTitleRecord.setPayload(titlePayload.toByteArray()); // construct the record

        /*
         * ================ Record 1 ===========================================
         *
         * This is the NDEF record that represents the URL associated with the title that will the Text part of the Smart Poster
         * Tag
         */
        urlPayload.write((byte) 0x01); // coded abbreviation for "http://www."
        urlPayload.write(uri.getBytes()); // The rest of the URL
        urlPayload.flush();
        /*
         * Construct the record itself
         */
        tagUrlRecord.setId("1"); // record Id
        tagUrlRecord.setType(NDEFRecord.TNF_WELL_KNOWN, "U"); // It's a URL(I) type
        tagUrlRecord.setPayload(urlPayload.toByteArray()); // construct the record

        /*
         * ================ Construct an NDEF MEssage ==========================
         *
         * This NDEF Message comprises the Title and URL records (TEXT, URL)
View Full Code Here

Examples of net.rim.device.api.io.nfc.ndef.NDEFRecord

    public void startNDEFEmulation() {
        // Create the NDEFMessage that will contain the NDEFRecords
        final NDEFMessage ndefMessage = new NDEFMessage();

        // Begin creating the NDEFRecords with "text/plain" payloads
        final NDEFRecord rec1 = new NDEFRecord();
        rec1.setId("1");

        try {
            rec1.setType(NDEFRecord.TNF_MEDIA, "text/plain");
        } catch (final NFCException e) {
            _screen.add(new LabelField("Error: " + e.toString()));
        }

        rec1.setPayload("I am the 1st payload".getBytes());

        final NDEFRecord rec2 = new NDEFRecord();
        rec2.setId("2");

        try {
            rec2.setType(NDEFRecord.TNF_MEDIA, "text/plain");

        } catch (final NFCException e) {
            _screen.add(new LabelField("Error: " + e.toString()));
        }

        rec2.setPayload("I am the 2nd payload".getBytes());
        ndefMessage.setRecords(new NDEFRecord[] { rec1, rec2 });

        // Create the VirtualNDEFTag to be emulated
        _ndefVirtualTarget =
                new VirtualNDEFTag(ndefMessage, new VirtualNDEFTagListener(
View Full Code Here

Examples of org.nfctools.ndef.NdefRecord

  public NdefRecord encodeRecord(Record record, NdefMessageEncoder messageEncoder) {
    if (record.getClass() != EmptyRecord.class) {
      throw new IllegalArgumentException("Unexpected Record " + record.getClass().getName());
    }

    return new NdefRecord(NdefConstants.TNF_EMPTY, NdefConstants.EMPTY_BYTE_ARRAY, record.getId(),
        NdefConstants.EMPTY_BYTE_ARRAY);
  }
View Full Code Here

Examples of org.nfctools.ndef.NdefRecord

   
    if(!absoluteUriRecord.hasUri()) {
      throw new NdefEncoderException("Expected URI", record);
    }
   
    return new NdefRecord(NdefConstants.TNF_ABSOLUTE_URI, AbsoluteUriRecord.TYPE, absoluteUriRecord.getId(),
        absoluteUriRecord.getUri().getBytes(NdefConstants.DEFAULT_CHARSET));
  }
View Full Code Here

Examples of org.nfctools.ndef.NdefRecord

    if(!mimeRecord.hasContentType()) {
      throw new NdefEncoderException("Expected content type", mimeRecord);
    }
   
    return new NdefRecord(NdefConstants.TNF_MIME_MEDIA, mimeRecord.getContentType().getBytes(
            NdefConstants.DEFAULT_CHARSET), record.getId(), mimeRecord.getContentAsBytes());
  }
View Full Code Here

Examples of org.nfctools.ndef.NdefRecord

  @Override
  public NdefRecord encodeRecord(Record record, NdefMessageEncoder messageEncoder) {
    UnknownRecord unknownRecord = (UnknownRecord)record;
   
    return new NdefRecord(NdefConstants.TNF_UNKNOWN, NdefConstants.EMPTY_BYTE_ARRAY, record.getId(),
        unknownRecord.getPayload());

  }
View Full Code Here

Examples of org.nfctools.ndef.NdefRecord

    }
   
    WellKnownRecordConfig config = knownRecordTypes.get(record.getClass());
    byte[] payload = config.getPayloadEncoder().encodePayload((WellKnownRecord)record, messageEncoder);
    byte[] type = config.getRecordType().getType();
    return new NdefRecord(NdefConstants.TNF_WELL_KNOWN, type, key, payload);
  }
View Full Code Here

Examples of org.nfctools.ndef.NdefRecord

  @Override
  public NdefRecord encodeRecord(Record record, NdefMessageEncoder messageEncoder) {
    UnsupportedRecord unsupportedRecord = (UnsupportedRecord)record;
   
    return new NdefRecord(unsupportedRecord.getTnf(), unsupportedRecord.getType(), unsupportedRecord.getId(), unsupportedRecord.getPayload());
  }
View Full Code Here

Examples of org.nfctools.ndef.NdefRecord

    } else {
      throw new NdefEncoderException("Unable to encode external type " + externalType.getClass().getName(), record);
    }
   
    byte[] type = namespace.getBytes(NdefConstants.DEFAULT_CHARSET);
    return new NdefRecord(NdefConstants.TNF_EXTERNAL_TYPE, type, record.getId(), payload);
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.