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

Filtering tags by their technology


There are several types of NFC tags. They mostly differ on the storage capacity and on the communication standard used. In our application, we may want to use only a specific type of tag because of a certain characteristic of that specific tag. The Android SDK supports the most frequent tag types such as MIFARE Classic and MIFARE Ultralight tags.

How to do it...

We will create an application that is executed only when the tag technology matches the one specified by us:

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

  2. Open the MainActivity.java file, override the onNewIntent method, and insert the following code:

    @Override
    protected void onNewIntent(Intent intent) {
    
      if ( isNfcIntent(intent) ) {
            
        Toast.makeText( this, "NFC intent received", Toast.LENGTH_SHORT).show();
        
      }
    }
  3. Implement the isNfcIntent method:

    boolean isNfcIntent(Intent intent) {
    return intent.hasExtra...