展会信息港展会大全

android nfc(官方翻译)
来源:互联网   发布日期:2015-09-28 16:14:54   浏览:1676次  

导读:为了充分详细的学习nfc相关的知识,决定阅读官方英文文档,并翻译下来供大家阅读。NFC BasicsThere are two major uses cases when working...

为了充分详细的学习nfc相关的知识,决定阅读官方英文文档,并翻译下来供大家阅读。

NFC Basics

There are two major uses cases when working with NDEF data and Android:

Reading NDEF data from an NFC tag

Beaming NDEF messages from one device to another with Android Beam?

The Tag Dispatch System

Parsing the NFC tag and figuring out the MIME type or a URI that identifies the data payload in the tag.

解析NFC标签,计算出MINE类型或者一个URI,用于标示数据负载的身份

Encapsulating the MIME type or URI and the payload into an intent. These first two steps are described in How NFC tags are mapped to MIME types and URIs.

封装MIME类型或者URI和负载放入intent对象,这两步由 How NFC tags are mapped to MIME types and URIs描述。

Starts an activity based on the intent. This is described in How NFC Tags are Dispatched to Applications.

启动一个activity根据这个intent对象,这部分由How NFC Tags are Dispatched to Applications.描述

How NFC tags are mapped to MIME types and URIs(NFC标签是如何映射到MINE类型和URI的?)

Before you begin writing your NFC applications, it is important to understand the different types of NFC tags, how the tag dispatch system parses NFC tags, and the special work that the tag dispatch system does when it detects

an NDEF message. NFC tags come in a wide array of technologies and can also have data written to them in many different ways. Android has the most support for the NDEF standard, which is defined by the NFC Forum.

在你开始写NFC应用之前,理解不同类型的NFC标签,标签调度系统如何解析NFC标签,当标签调度系统检测到NDEC message所要做的特殊工作,NFC标签来着不同类型的技术,写入标签有不同的方式,Android推荐使用NDEF标准,它是由NFC社区发起的

NDEF data is encapsulated inside a message (NdefMessage) that contains one or more records (NdefRecord). Each NDEF record must be well-formed according to the specification of the type of record that you want to create. Android

also supports other types of tags that do not contain NDEF data, which you can work with by using the classes in the android.nfc.tech package. To learn more about these technologies, see the Advanced NFC topic. Working with these other types of tags involves

writing your own protocol stack to communicate with the tags, so we recommend using NDEF when possible for ease of development and maximum support for Android-powered devices.

NDEF数据封装在一个由多个NdefRecord组成的NdefMessage中,每一个NDEF记录必须是格式良好的根据你要创建的具体类型,Android也支持其他不包含NDEF数据的类型,你能够使用android.nfc.tech进行工作,为了学习这些技术,请看Advanced NFC topic,操作这些标签会牵涉到你自己的协议栈和标签进行交流,因此为了简化开发和最大化支持android设备,我们建议使用NDEF尽可能。

Note: To download complete NDEF specifications, go to the NFC Forum Specification Download site and see Creating common types of NDEF records for examples of how to construct NDEF records.

注意:为了下载完整的NDEF详情,去NFC社区下载然后阅读如何构建公共类型的NDEF记录的例子。

Now that you have some background in NFC tags, the following sections describe in more detail how Android handles NDEF formatted tags. When an Android-powered device scans an NFC tag containing NDEF formatted data, it parses

the message and tries to figure out the data's MIME type or identifying URI. To do this, the system reads the first NdefRecord inside the NdefMessage to determine how to interpret the entire NDEF message (an NDEF message can have multiple NDEF records). In

a well-formed NDEF message, the first NdefRecord contains the following fields:

现在你要具有NFC标签的背景,如下部分描述如何如何处理NDEF格式标签的更多详情。当一个android支持的设别检测到NFC包含NDEF格式的标签后,解析里面的信息然后试图计算数据的MIME类型和URI身份,为了读取它,系统阅读NDEF信息的第一个记录然后说明整个NDEF信息(一个NDEF信息有多个NDEF记录),在一个格式良好的NDEF信息内,第一个NdefRecord包含如下字段:

3-bit TNF (Type Name Format)

Indicates how to interpret the variable length type field. Valid values are described in described in Table 1.

指明了如何解析可变长度字段,有效值被描述在表1.

Variable length type

Describes the type of the record. If using TNF_WELL_KNOWN, use this field to specify the Record Type Definition (RTD). Valid RTD values are described in Table 2.

详细record的类型,如有使用了TNF_WELL_KNOWN,使用这个字段具体得记录的类型,有效的RTD值被描述在表2。

Variable length ID

A unique identifier for the record. This field is not used often, but if you need to uniquely identify a tag, you can create an ID for it.

record唯一的身份,这个字段不是经常使用的,除非你需要唯一确定一个标签,你可以为它创建一个ID

Variable length payload

The actual data payload that you want to read or write. An NDEF message can contain multiple NDEF records, so don't assume the full payload is in the first NDEF record of the NDEF message.

确切的你将要读写的数据的payload,一个DNEF message能包含大量的 NDEF records,所以不要假定所有的payload在NDEF message的第一个NDEF record。

The tag dispatch system uses the TNF and type fields to try to map a MIME type or URI to the NDEF message. If successful, it encapsulates that information inside of a ACTION_NDEF_DISCOVERED intent along with the actual payload.

However, there are cases when the tag dispatch system cannot determine the type of data based on the first NDEF record. This happens when the NDEF data cannot be mapped to a MIME type or URI, or when the NFC tag does not contain NDEF data to begin with. In

such cases, a Tag object that has information about the tag's technologies and the payload are encapsulated inside of a ACTION_TECH_DISCOVERED intent instead.

标签调度系统使用TNF和type字段尝试映射一个MIME类型或者URI到一个NDEF message。如果成功,它将封装信息进一个ACTION_NDEF_DISCOVERED的intent伴随了确切的payload,这儿关心当调度系统不能决定数据的类型根据第一个NDEF record,这个情况发生在当NDEF data不能映射到一个MIME类型或者一个URI或者当NFC标签不包含NDEF的头信息时,这些情况,一个标签对象的的信息技术和负载将由ACTION_TECH_DISCOVERED的intent取代

Table 1. describes how the tag dispatch system maps TNF and type fields to MIME types or URIs. It also describes which TNFs cannot be mapped to a MIME type or URI. In these cases, the tag dispatch system falls back to ACTION_TECH_DISCOVERED.

表1:描述标签调度系统映射TNF and type field到一个MIME类型或者URIs。它也描述了TNFs不能被映射的MIME类型和 URI,如果这样的话,标签调度系统将回落给ACTION_TECH_DISCOVERED

For example, if the tag dispatch system encounters a record of type TNF_ABSOLUTE_URI, it maps the variable length type field of that record into a URI. The tag dispatch system encapsulates that URI in the data field of an ACTION_NDEF_DISCOVERED

intent along with other information about the tag, such as the payload. On the other hand, if it encounters a record of type TNF_UNKNOWN, it creates an intent that encapsulates the tag's technologies instead.

例如:如果标签 调度系统检测到一个TNF_ABSOLUTE_URI类型的记录,它映射记录的the variable length type field到一个URI,标签调度系统封装URI数据和相应payload的到ACTION_NDEF_DISCOVEREDintent,另一个方面,如果遇到一个TNF_UNKNOWN的记录,它将创建一个tag's

technologies 封装取代(ACTION_TECH_DISCOVERED)。

Table 1. Supported TNFs and their mappings

Type Name Format (TNF)

Mapping

TNF_ABSOLUTE_URI

URI based on the type field.

TNF_EMPTY

Falls back to ACTION_TECH_DISCOVERED.

TNF_EXTERNAL_TYPE

URI based on the URN in the type field. The URN is encoded into the NDEF type field in a shortened form: :. Android maps

this to a URI in the form: vnd.android.nfc://ext/:.

TNF_MIME_MEDIA

MIME type based on the type field.

TNF_UNCHANGED

Invalid in the first record, so falls back to ACTION_TECH_DISCOVERED.

TNF_UNKNOWN

Falls back to ACTION_TECH_DISCOVERED.

TNF_WELL_KNOWN

MIME type or URI depending on the Record Type Definition (RTD), which you set in the type field. See Table

2. for more information on available RTDs and their mappings.

Table 2. Supported RTDs for TNF_WELL_KNOWN and their mappings

Record Type Definition (RTD)

Mapping

RTD_ALTERNATIVE_CARRIER

Falls back to ACTION_TECH_DISCOVERED.

RTD_HANDOVER_CARRIER

Falls back to ACTION_TECH_DISCOVERED.

RTD_HANDOVER_REQUEST

Falls back to ACTION_TECH_DISCOVERED.

RTD_HANDOVER_SELECT

Falls back to ACTION_TECH_DISCOVERED.

RTD_SMART_POSTER

URI based on parsing the payload.

RTD_TEXT

MIME type of text/plain.

RTD_URI

URI based on payload.

How NFC Tags are Dispatched to Applications

When the tag dispatch system is done creating an intent that encapsulates the NFC tag and its identifying information, it sends the intent to an interested application that filters for the intent. If more than one application

can handle the intent, the Activity Chooser is presented so the user can select the Activity. The tag dispatch system defines three intents, which are listed in order of highest to lowest priority:

当标签调度系统完成创建一个封装了NFC标签和它的身份信息的Intent后,它将发送由过滤器过滤后的intent到对应的应用,如果一个intent有多个应用可以处理,用户根据Activity Chooser选择器选择启动的Activity,标签调度系统定义了三种intent类型,优先级由高到低。

Requesting NFC Access in the Android Manifest

赞助本站

人工智能实验室

相关热词: android开发

AiLab云推荐
展开

热门栏目HotCates

Copyright © 2010-2024 AiLab Team. 人工智能实验室 版权所有    关于我们 | 联系我们 | 广告服务 | 公司动态 | 免责声明 | 隐私条款 | 工作机会 | 展会港