Book Image

Near Field Communication with Android Cookbook

By : Subtil
Book Image

Near Field Communication with Android Cookbook

By: Subtil

Overview of this book

An easy-to-follow guide, full of hands-on examples of and real-world applications. Each recipe is explained and placed in context. If you want to learn how to create NFC-enabled Android applications, this is the book for you. Perhaps you already know a bit about Android application developments but have never used NFC, or perhaps you know a little about NFC android development but want some more advanced features and examples. In either case, this book will get you up and running quickly. You are expected to have Android programming knowledge.
Table of Contents (17 chapters)
Near Field Communication with Android Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Writing a URI-formatted record


URI is probably the most common content written to NFC tags. It allows you to share a website, an online service, or a link to the online content. This can be used, for example, in advertising and marketing.

How to do it...

We are going to create an application that writes URI records to a tag by performing the following steps. The URI will be hardcoded and will point to the Packt Publishing website.

  1. Open Eclipse and create a new Android application project named NfcBookCh3Example2.

  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. Set the minimum SDK version to 14:

    <uses-sdk android:minSdkVersion="14" /> 
  4. Implement the enableForegroundDispatch, isNfcIntent, formatTag, and writeNdefMessage methods from the previous recipe—steps 2, 4, 6, and 7.

  5. Add the following class member and instantiate it in the onCreate method:

    private NfcAdapter nfcAdapter; 
    
    protected...