Cherry-picking NFC sample into Honeycomb branch, since it wasn't merged during it's original commit to Gingerbread. Change-Id: I79308f04c1b2edd6cb5bb675fa13b9e5083a8432
130 lines
4.7 KiB
HTML
130 lines
4.7 KiB
HTML
<p>
|
|
Near-field Communication or NFC is a standard defined by the
|
|
<a href=http://www.nfc-forum.org/home>NFC Forum
|
|
</a>.
|
|
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.
|
|
</p>
|
|
|
|
<p>The application includes:
|
|
</p>
|
|
<ul>
|
|
<li>
|
|
<a href="src/com/example/android/nfc/TagViewer.html">
|
|
<code>TagViewer
|
|
</code>
|
|
</a>
|
|
— an
|
|
<code>Activity
|
|
</code> that handles a broadcast of a new tag that the device
|
|
just discovered, parses it, and displays its record contents in a
|
|
<code>ListActivity
|
|
</code>
|
|
</li>
|
|
<li>
|
|
<a href="src/com/example/android/nfc/NdefMessageParser.html">
|
|
<code> NdefMessageParser
|
|
</code>
|
|
</a>
|
|
— parses the record type of records within the NDEF message.
|
|
</li>
|
|
<li>
|
|
<a href="src/com/example/android/nfc/record/ParsedNdefRecord.html">
|
|
<code>ParsedNdefRecord
|
|
</code>
|
|
</a>
|
|
— an interface implemented by all parsed NdefRecord types.
|
|
</li>
|
|
<li>
|
|
<a href="src/com/example/android/nfc/record/SmartPoster.html">
|
|
<code>SmartPoster
|
|
</code>
|
|
</a>
|
|
— a representation of an NFC Forum Smart Poster Record Type.
|
|
</li>
|
|
<li>
|
|
<a href="src/com/example/android/nfc/record/TextRecord.html">
|
|
<code>TextRecord
|
|
</code>
|
|
</a>
|
|
— a representation of an NFC Forum Text Record Type.
|
|
</li>
|
|
<li>
|
|
<a href="src/com/example/android/nfc/record/UriRecord.html">
|
|
<code>UriRecord
|
|
</code>
|
|
</a>
|
|
— a representation of an NFC Forum Uri Record Type.
|
|
</li>
|
|
<li>
|
|
<a href="src/com/example/android/nfc/simulator/FakeTagsActivity.html">
|
|
<code>FakeTagsActivity
|
|
</code>
|
|
</a>
|
|
— 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.
|
|
</li>
|
|
<li>
|
|
<a href="src/com/example/android/nfc/simulator/MockNdefMessages.html">
|
|
<code>MockNdefMessages
|
|
</code>
|
|
</a>
|
|
— this class provides a list of fake NFC Ndef format Tags.
|
|
</li>
|
|
|
|
</ul>
|
|
<p>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:
|
|
</p>
|
|
<ul>
|
|
<li>
|
|
<code><uses-sdk android:minSdkVersion="9" />
|
|
</code>,
|
|
which indicates to Android Market and the platform that your application requires
|
|
Android 2.3 or higher. For more information, see
|
|
<a href="../../../guide/appendix/api-levels.html">API Levels
|
|
</a>
|
|
and the documentation for the
|
|
<a href="../../../guide/topics/manifest/uses-sdk-element.html">
|
|
<code><uses-sdk>
|
|
</code>
|
|
</a> element.
|
|
</li>
|
|
</ul>
|
|
<p>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
|
|
<ul>
|
|
<li>
|
|
<code><uses-feature android:name="android.hardware.nfc" />
|
|
</code>,
|
|
which tells Android Market that your application uses the NFC API. The declaration
|
|
should include an
|
|
<code>android:required
|
|
</code> attribute that indicates whether you want
|
|
Android Market to filter the application from devices that do not offer NFC support. Other
|
|
<code><uses-feature>
|
|
</code> declarations may also be needed, depending on your
|
|
implementation. For more information, see the documentation for the
|
|
<a href="../../../guide/topics/manifest/uses-feature-element.html">
|
|
<code><uses-feature>
|
|
</code>
|
|
</a> element.
|
|
</li>
|
|
</ul>
|
|
<p>For more information about using the NFC API, see the
|
|
<a href="../../../reference/android/nfc/package-summary.html">
|
|
<code>android.nfc</code>
|
|
</a>
|
|
documentation.
|
|
</p>
|
|
<img alt="" src="../images/NfcDemo.png"/>
|