user1210821
user1210821

Reputation: 21

How to write data in NFC smart poster tag in Android

I am asked to write the following data in smart poster tag.

1) URL of the discount offer 2) Count value (like offer for first 200 entries)

How to write these information in smart poster programmatically?

Is it something that can be written as key/value pairs?

Any pointers to sample code can help me a lot?

Thanks in advance.

Upvotes: 2

Views: 1066

Answers (1)

maze_mx
maze_mx

Reputation: 103

I Think that that requirements 1) and 2), are two different levels. Req. 1) is on the Android/NFC programming level, using TNF_WELL_KNOWN and RTD-SMART_POSTER(since this is a URL, usingRTD_URI works jus right).

here is some code:

    private NdefRecord createRecord(String text)
        throws UnsupportedEncodingException {

    //Intent intent = getIntent();
    //EditText editTextWeb = (EditText)
    EditText editText = (EditText) findViewById(R.id.editTextWeblinks);
    String webLink = editText.getText().toString();
    byte[] uriField = webLink.getBytes(Charset.forName("US-ASCII"));
    byte[] payload = new byte[uriField.length + 1];              //1 =URIPrefix
    payload[0] = 0x01;                                      //http://www. to the URI
    System.arraycopy(uriField, 0, payload, 1, uriField.length);  //appends URI to payload
    NdefRecord rtdUriRecord = new NdefRecord(
        NdefRecord.TNF_WELL_KNOWN, NdefRecord.RTD_URI, new byte[0], payload);

    return rtdUriRecord;
}

On req. 2 we have a tricky part. with Android/NFC API you can Identify each tag that you write but you can not add a sort of counter program logic within the NF Tag, this function have to be performed on an external application (name it on Android, PC, Mac, custom device, etc.).

Fancy way to do it: Build custom NFC terminal for sales and offers of your business. Simpe way to do it: Build a simple app on the cashiers computers to scan a barcode (an image downloaded) and write a counter wi that event.

hope it helps.

Upvotes: 1

Related Questions