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
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...