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

Handling tag-reading errors


In this recipe, we will implement generic validation methods to identify the tag format. This way, we can implement different payload handling mechanisms for the content that our application knows to handle, preventing unwanted exceptions.

Getting ready

We will be using the project from the previous recipe, so make sure you have gone through it before starting this one.

How to do it...

In this application, we will be adding some methods to your NfcHelper class to facilitate the identification of the tag content. To do this, perform the following steps:

  1. Open the project files from the Handling tag-writing errors recipe.

  2. Implement the isTextRecord method in the NfcHelper class with the following code:

      public boolean isTextRecord(NdefRecord record) {
    
        if (record == null) {
          return false;
        }
    
        return isNdefRecordOfTnfAndRdt(record, NdefRecord.TNF_WELL_KNOWN, NdefRecord.RTD_TEXT);
      }
  3. Implement the isUrlRecord method in the NfcHelper class:

      public boolean...