Writing a text-formatted record
As we saw in the Working with the NDEF record recipe, we can write different tag content formats. In this recipe, we will see how to store text in a tag.
How to do it...
We are going to create an application that creates and writes a text-formatted record to a tag:
Open Eclipse and create a new Android application project named
NfcBookCh3Example3
with the package namenfcbook.ch3.example3
.Make sure the
AndroidManifest.xml
file is configured correctly (refer to the Requesting NFC permissions recipe from Chapter 1, Getting Started with NFC).Make sure the foreground dispatch system is enabled (refer to the Understanding the foreground dispatch system recipe from Chapter 2, Detecting a Tag).
Open the
MainActivity.java
file located undernfcbook.ch3.example3
and add the following class member:private NfcAdapter nfcAdapter;
Instantiate the
nfcAdapter
class field in theonCreate
method:protected void onCreate(Bundle savedInstanceState) { ... nfcAdapter = NfcAdapter...