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 (12 chapters)
11
Index

Choosing the best format for our data


While developing other recipes, we have seen different ways of storing our data in an NFC tag. From a simple plain text to a raw object, it all depends on the data we need to store. In this recipe, we will learn about some other formats to store our data.

How to do it…

We will create several NdefMessages that contain a product representation in several formats by performing the following steps:

  1. Open Eclipse and create a new Android application project named NfcBookCh10Example2 and a package named nfcbook.ch10.example2.

  2. Download the google-gson library from https://code.google.com/p/google-gson/ and import the .jar file to the libs folder in the project.

  3. Set the minimum SDK version to 16 using the following code:

    <uses-sdk android:minSdkVersion="16" />
  4. Add the strings given in the following code to the strings.xml file available at res/values/:

    <string name="label_raw">Raw</string>
    <string name="label_json">JSON</string>
    <string...