Package net.rim.device.api.io.nfc.ndef

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


        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

    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

TOP

Related Classes of net.rim.device.api.io.nfc.ndef.NDEFRecord

Copyright © 2018 www.massapicom. 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.