NFCDemo - NFC Demo

Near-field Communication or NFC is a standard defined by the NFC Forum . NFC Data Exchange Format (NDEF) defines a common data format between NFC-compliant devices and tags. This demo application shows how to read a NDEF Tags using using Android 2.3 SDK APIs. The NFC Tags consist of data encoded in NDEF Message format specified by NFC Forum Type 2 Specification. Each NDEF message consists of one or more NDEF Records. You need a NFC compliant device and a NFC compliant Tag to use this sample app. Or else, you could use the FakeTagsActivity displayed at launch of this sample app, to generate fake Tag broadcasts from the emulator.

The application includes:

  • TagViewer — an Activity that handles a broadcast of a new tag that the device just discovered, parses it, and displays its record contents in a ListActivity
  • NdefMessageParser — parses the record type of records within the NDEF message.
  • ParsedNdefRecord — an interface implemented by all parsed NdefRecord types.
  • SmartPoster — a representation of an NFC Forum Smart Poster Record Type.
  • TextRecord — a representation of an NFC Forum Text Record Type.
  • UriRecord — a representation of an NFC Forum Uri Record Type.
  • FakeTagsActivity — A activity that launches tags as if they had been scanned. This is useful if you don't have access to NFC enabled device or tag.
  • MockNdefMessages — this class provides a list of fake NFC Ndef format Tags.

If you are developing an application that uses the NFC API, remember that the feature is supported only on Android 2.3 (API level 9) and higher versions of the platform. Also, among devices running Android 2.3 (API level 9) or higher, not all devices will offer NFC support. To ensure that your application can only be installed on devices that are capable of supporting NFC, remember to add the following to the application's manifest before publishing to Android Market:

  • <uses-sdk android:minSdkVersion="9" /> , which indicates to Android Market and the platform that your application requires Android 2.3 or higher. For more information, see API Levels and the documentation for the <uses-sdk> element.

To control how Android Market filters your application from devices that do not support NFC, remember to add the following to the application's manifest

  • <uses-feature android:name="android.hardware.nfc" /> , which tells Android Market that your application uses the NFC API. The declaration should include an android:required attribute that indicates whether you want Android Market to filter the application from devices that do not offer NFC support. Other <uses-feature> declarations may also be needed, depending on your implementation. For more information, see the documentation for the <uses-feature> element.

For more information about using the NFC API, see the android.nfc documentation.

You can find the source code for this sample in your SDK at:

<sdk>/platforms/android-<version>/samples/