Android 2.3 NFC Introduction

Source: Internet
Author: User

Android 2.3 added support for NFC (near field communication). The official website of Developer.android.com is described in English as follows:
near Field Communications (NFC)
Android 2.3 includes an NFC Stack and framework API that lets developers read NDEF tags that is discovered as a user touches an nfc-enabled device to Tag elements embedded in stickers, smart posters, and even other devices.
The platform provides the underlying NFC services the work with the device hardware to discover tags when they come I Nto range. On discovering a tags, the platform notifies applications by broadcasting an Intent, appending the tag ' s NDEF messages to T He Intent as extras. Applications can create Intent filters to recognize and handle targeted tags and messages. For example, after receiving a tagged by Intent, applications extract the NDEF messages, store them, alert the user, or Handl e them in other ways.


The NFC API is available in the ANDROID.NFC package. The key classes is:

    • Nfcadapter, which represents the NFC hardware on the device.
    • Ndefmessage, which represents an NDEF data message, the standard format in which "records" carrying data is Tran Smitted between devices and tags. Applications can receive these messages from Action_tag_discovered Intents.
    • Ndefrecord, delivered in an ndefmessage, which describes the type of data being shared and carries the data Itsel F.

NFC communication relies on wireless technology in the device hardware, "so" for the platform ' s NFC features on spec Ific devices is determined by their manufacturers. To determine the NFC-enabled, applications can call  isenabled ()  to Query the Nfcadapter. The NFC API is always present, however, regardless of underlying hardware support.


To use the NFC API, applications must request permission from the user by declaring < uses-permission an Droid:name= "Android.permission.NFC" > in their manifest files.
Additionally, developers can request filtering on Android market, such that their applications is not discoverable to Users whose devices don't support NFC. To request filtering, add < uses-feature android:name= "ANDROID.HARDWARE.NFC" android:required= "true" > To the application ' s manifest. There are many applications for


NFC, but the Android 2.3 API now only provides the e-tag Reader . It is believed that as the Android version is upgraded, many more scenarios and APIs will be added later. The
function is less, but the first step from scratch is not always easy. From the schema, there are at least a few changes in the following sections:

    • Android framework layer that adds APIs to application development (i.e., the framework APIin English).
    • protocol layer, which increases the NFC stack (the NFC stackin English).
    • A hardware adaptation layer that provides the hardware manufacturer with an adapter interface that should be communicated with the Linux driver of the NFC hardware (the implementation method is to be verified).

workflow is when the NFC-enabled mobile phone or other electronic terminal (hereafter referred to as mobile phone) in Nfcadapter ) is scanned to the electronic label, it is sent to the relevant user program Ndef (NFC Data Exchange Format) messages are included in the Intent,itent extras schema of the action_tag_discovered . How to handle this NDEF message is a matter of the user program. The
NFC API is available in the ANDROID.NFC package, which is offered in three major categories, where: Nfcadapter describes the NFC hardware in the phone, which can be temporarily understood as an electronic label scanner in Android 2.3. Messages in electronic tags and scanners are represented by Ndefmessage, a simple class that encapsulates ndefrecord. Each ndefmessage can contain multiple Ndefrecord, and the Method Getrecords () through the class Ndefmessage can query all Ndefrecord of the message. Ndefrecord is the true carrier of information, and the correct understanding of this class is a key to understanding NFC technology. Technical specifications for NFC [url=link.php?url=http://www.nfc-forum.org%2fspecs%2fspec_list%2f]http://www.nfc-forum.org/specs/spec_ List/[/url] is an indispensable source of understanding of this class.
The programming idea of the application is:

      • Get your phone's objnfcadapter through Android.nfc.NfcAdapter.getDefaultAdapter ()
      • Check whether the phone supports NFC via objnfcadapter.isenabled ()
      • If your phone supports NFC, request to receive action_tag_discovered intent
      • If the action_tag_discovered is received, it extracts the ndefmessage and extracts the Ndefrecord on this basis, and the whole is a message parsing process.

Android 2.3 NFC Introduction

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.