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

Sending texts to other devices


Android Beam uses the standard NdefMessage parameter to share data between devices, and as we learned in Chapter 3, Writing Tag Content, we can encapsulate the text to NdefMessage. In this recipe, we will create a simple application that sends texts to other devices.

How to do it…

In this application, we will send the content of TextView to another device through an NdefMessage, which is formatted as RTD_TEXT, as shown in the following steps:

  1. Open Eclipse and create a new Android application project named NfcBookCh7Example2 and a package named nfcbook.ch7.example2.

  2. Make sure the AndroidManifest.xml file is configured correctly. Refer to the Requesting NFC permissions recipe in Chapter 1, Getting Started with NFC.

  3. Set the minimum SDK version to 14 with the following code:

    <uses-sdk android:minSdkVersion="14" />
  4. Add the following intent-filters to MainActivity in the AndroidManifest file:

    <intent-filter>
      <action android:name="android.nfc.action.NDEF_DISCOVERED...