Android near Field Communication---NFC Basics (ii)

Source: Internet
Author: User

Transfer from http://blog.csdn.net/think_soft/article/details/8171256

How an application dispatches an NFC tag

When the label dispatch system completes the creation of an intent object encapsulated by an NFC tag and its identity information, it sends the intent object to the application of interest. If more than one application is able to process the intent object, the activity selector is displayed, allowing the user to select Activity. The label dispatch system defines three intent objects, and the following three intent objects are listed as high-to-low priority:

1. Action_ndef_discovered: This intent is used to initiate activity that contains NDEF loads and known types of labels. This is the highest priority intent, and the label dispatch system attempts to start the activity with this type of intent as much as possible before any other intent.

2. action_tech_discovered: If there is no activity registered to handle intent of the action_ndef_discovered type, the label dispatch system will attempt to use this type of intent to start the application. If the scanned label contains NDEF data that cannot be mapped to a MIME type or URI, or does not contain NDEF data, but is known as a label technology, this type of intent object is also started directly (instead of starting action_ndef_ Discovered type of intent)

3. action_tab_discovered: This type of intent is initiated if the activity of the action_ndef_discovered or action_tech_discovered type intent is not processed.

The basic working methods of the label dispatch system are as follows:

1. Try to start the activity by using the intent object (action_ndef_discovered or action_tech_discovered) created by the label dispatch system when parsing the NFC tag;

2. If there is no corresponding activity to process intent, then the next priority intent (action_tech_discovered or action_tag_discovered) will be attempted to start the activity, Until there is a corresponding application to handle this intent, or until the label dispatch system tries all possible intent.

3. If there is no application to handle any type of intent, then do nothing.

Figure 1: Label scheduling system

Where possible, the NDEF message and the action_ndef_discovered type of intent are used to work because it is the most standard of the three intent. Compared to the other two intent, this intent allows you to launch your application at a more appropriate time, giving users a better experience.

Request NFC access in Android manifest

Before you access your device's NFC hardware and properly handle NFC intent, make the following statement in the Androidmanifest.xml file:

1. Declare access to the NFC hardware in the <uses-permission> element:

<uses-permission android:name= "Android.permission.NFC"/>

2. The minimum SDK version supported by your application. API Level 9 supports limited label scheduling only through action_tag_discovered, and can only access NDEF messages through Extra_ndef_messages. No other label properties or I/O operations are available. API level 10 includes extensive read-write support to better drive Ndef's application prospects, and API Leve 14 provides an easier way to push ndef messages to other devices with Android Beam and an additional convenient way to create Ndef records.

<uses-sdkandroid:minsdkversion= "Ten"/>

3. Use the Uses-feature element on Google Play so that your app can be displayed only for devices that have NFC hardware.

<uses-featureandroid:name= "ANDROID.HARDWARE.NFC" android:required= "true"/>

If your application uses NFC functionality, but the related functionality is not a key feature of your application, you can ignore the uses-feature element and check whether NFC is valid at run time by calling the Getdefaultadapter () method.

Android near Field communication---NFC Basis (ii) (RPM)

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.