Book Image

Near Field Communication with Android Cookbook

By : Vitor Subtil
Book Image

Near Field Communication with Android Cookbook

By: Vitor Subtil

Overview of this book

Table of Contents (17 chapters)
Near Field Communication with Android Cookbook
About the Author
About the Reviewers

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:

  1. Open Eclipse and create a new Android application project named NfcBookCh3Example3 with the package name nfcbook.ch3.example3.

  2. Make sure the AndroidManifest.xml file is configured correctly (refer to the Requesting NFC permissions recipe from Chapter 1, Getting Started with NFC).

  3. Make sure the foreground dispatch system is enabled (refer to the Understanding the foreground dispatch system recipe from Chapter 2, Detecting a Tag).

  4. Open the file located under nfcbook.ch3.example3 and add the following class member:

    private NfcAdapter nfcAdapter;
  5. Instantiate the nfcAdapter class field in the onCreate method:

    protected void onCreate(Bundle savedInstanceState) { 
    nfcAdapter = NfcAdapter...