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)