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

Getting the tag information

In this recipe, we will see how to obtain several types of information regarding an NFC tag and its content.

How to do it...

We will get the tag information through the Tag object instance, and the information regarding its content will be based on the first NdefRecord present in the tag.

  1. Open Eclipse and create a new Android application project named NfcBookCh7Example1 and package named com.nfcbook.ch7.example1.

  2. Make sure the AndroidManifest.xml file is configured correctly. Refer to the Requesting NFC permissions recipe in Chapter 1, Getting Started with NFC.

  3. Add the following intent-filter to MainActivity:

      <action android:name="android.nfc.action.NDEF_DISCOVERED" />
      <category android:name="android.intent.category.DEFAULT" />
      <data android:mimeType="text/plain" />
  4. Add the following content to the strings.xml file located at /res/values:

    <string name="title_activity_tag_details">Tag Details...