Android 2.3 NFC简介
Android 2.3加入了NFC(近场通讯)的支持。官网developer.android.com的英文介绍如下:
Near Field Communications (NFC)
Android 2.3 includes an NFC stack and framework API that lets developers read NDEF tags that are 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 that work with the device hardware to discover tags when they come into range. On discovering a tag, the platform notifies applications by broadcasting an Intent, appending the tag's NDEF messages to the Intent as extras. Applications can create Intent filters to recognize and handle targeted tags and messages. For example, after receiving a tag by Intent, applications extract the NDEF messages, store them, alert the user, or handle them in other ways.
The NFC API is available in the android.nfc package. The key classes are:
- NfcAdapter, which represents the NFC hardware on the device.
- NdefMessage, which represents an NDEF data message, the standard format in which "records" carrying data are transmitted 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 itself.
NFC communication relies on wireless technology in the device hardware, so support for the platform's NFC features on specific devices is determined by their manufacturers. To determine the NFC support on the current device, 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 android:name="android.permission.NFC"> in their manifest files.
Additionally, developers can request filtering on Android Market, such that their applications are not discoverable to users whose devices do not support NFC. To request filtering, add <uses-feature android:name="android.hardware.nfc" android:required="true"> to the application's manifest.
NFC的应用场景有很多,但Android 2.3目前API只提供了电子标签阅读器的功能。相信随着Android的版本升级,后续会增加很多应用场景和 API。
功能是少一点,但从无到有的第一步总是不容易的。从架构上看,至少有以下几部分的改动:
- Android Framework层,为应用开发增加了相关API(即英文中的framework API)。
- 协议层,增加NFC的协议栈(即英文中的NFC Stack)。
- 硬件适配层,为硬件生产商提供适配接口,此层应该与NFC硬件的 Linux驱动通讯(实现方式待验证)。
工作流程是当支持NFC功能的手机或其他电子终端(后面简称手机)在用户开启NFC功能的时候,如果手机内置的NFC扫描器(相当于类NfcAdapter的功能)扫描到电子标签后,就会向相关用户程序发送ACTION_TAG_DISCOVERED的Intent,Itent的 extras架构中会包含NDEF(NFC Data Exchange Format)消息。如何处理此NDEF消息,就是用户程序的事情了。
NFC的API在android.nfc的包中提供,这个包主要提供三个大类,其中:NfcAdapter描述的就是手机中的NFC硬件,Android 2.3中可以暂时理解为电子标签扫描器。电子标签和扫描器中的消息通过NdefMessage来表示,这个类很简单,只是封装了NdefRecord。每个NdefMessage中可以包含多个NdefRecord,通过类NdefMessage的方法getRecords() 可以查询到消息的所有NdefRecord。NdefRecord才是信息的真正载体,正确理解这个类是理解NFC技术的一个重点。NFC的技术规范[url=link.php?url=http://www.nfc-forum.org%2Fspecs%2Fspec_list%2F]http://www.nfc-forum.org/specs/spec_list/[/url]是理解这个类不可或缺的资料。
应用程序的编程思路是:
- 通过android.nfc.NfcAdapter.getDefaultAdapter() 取得手机的objNfcAdapter
- 通过objNfcAdapter.isEnabled()查询该手机是否支持NFC
- 如果手机支持NFC,就申请接收ACTION_TAG_DISCOVERED 的Intent
- 如果接收到ACTION_TAG_DISCOVERED,就提取NdefMessage,并在此基础上进而提取 NdefRecord,整个是一个消息解析过程
Android 2.3 NFC简介的更多相关文章
- NFC简介
NFC简介 NFC是Near Field Communication缩写,即近距离无线通讯技术.由飞利浦和索尼公司共同开发的NFC是一种非接触式识别和互联技术,可以在移动设备.消费类电子产品.PC 和 ...
- Android – 学习操作NFC – 2
在<Android – 学习操作NFC – 1>说明了Android在处理NFC tag的机制.tag dispatch system的运作流程,以及三种ACTION_NDEF_DISCO ...
- 【转】Android 防破解技术简介
http://www.cnblogs.com/likeandroid/p/4888808.html Android 防破解技术简介 这几年随着互联网的不断发展,Android App 也越来越多!但是 ...
- 移动支付之智能IC卡与Android手机进行NFC通信
本文来自http://blog.csdn.net/hellogv/ .引用必须注明出处. 眼下常见的智能IC卡执行着JavaCard虚拟机.智能IC卡上能够执行由精简后的Java语言编写 ...
- GitHub Android Librarys Top 100 简介
GitHub Android Librarys Top 100 简介 本项目主要对目前 GitHub 上排名前 100 的 Android 开源库进行简单的介绍, 至于排名完全是根据GitHub搜索J ...
- Android Activity动画属性简介
Android Activity动画属性简介 在Android当中 设置activity的动画 需要复写 android:windowAnimationStyle这个属性 我们自定义一个动画样式来继承 ...
- Android 防破解技术简介
Android 防破解技术简介 这几年随着互联网的不断发展,Android App 也越来越多!但是随之而来的问题也越来越多,这其中比较令人头疼的问题就是:有些不法分子利用反编译技术破解 App,修改 ...
- <Android开源库 ~ 1> GitHub Android Libraries Top 100 简介
转载自GitHub Android Libraries Top 100 简介 本项目主要对目前 GitHub 上排名前 100 的 Android 开源库进行简单的介绍, 至于排名完全是根据 GitH ...
- android hook 框架 libinject2 简介、编译、运行
Android so注入-libinject2 简介.编译.运行 Android so注入-libinject2 如何实现so注入 Android so注入-Libinject 如何实现so注入 A ...
随机推荐
- 视图缩放、移动、旋转--ios
UIView *view=[[UIView alloc] initWithFrame:CGRectMake(50, 50, 100, 100)]; view.backgroundColor=[UICo ...
- Unity3D研究院编辑器之脚本设置ToolBar
Unity版本5.3.2 如下图所示,ToolBar就是Unity顶部的那一横条.这里的所有按钮一般情况下都得我们手动的用鼠标去点击.这篇文章我们说说如果自动操作它们 1.自动点击左边四个按钮 (拖动 ...
- Unity3D研究院之Editor下监听Transform变化
美术有可以直接在Editor下操作Transform,我想去修正他们编辑的数值,所以我就得监听Transform. C# 1 2 3 4 5 6 7 8 9 10 11 12 13 1 ...
- linux -redhat rpm 和zabbix和各种rpm包下载地址
redhat ftp://ftp.redhat.com/pub/redhat/linux/enterprise/6Client/en/os/SRPMS/ zabbix https://sourcefo ...
- unity, Graphics.Blit (null, null, mat,0);
我使用 Graphics.Blit (null, finalRT, mat); 合成出一张finalRT,然后将finalRT用在editor脚本的OnInspector中使用 Graphics.Dr ...
- The repository for high quality TypeScript type definitions
Best practices This is a guide to the best practices to follow when creating typing files. There are ...
- 一个重构的js分页类
// JavaScript Document /**//** * js分页类 * @param iAbsolute 每页显示记录数 * @param sTableId 分页表格属性ID值,为Strin ...
- javascript中的cookie,以及事件解析
Cookie: 它的意思是在本地的客户端的磁盘上以很小的文件形式保存数据,Cookie的处理原则上需要在服务器环境下运行,目前Chrome不可以在客户端操作Cookie,其他浏览器均可以, Coo ...
- ORA-01013:用户请求取消当前的操作
ORA-01013:用户请求取消当前的操作 在测试一个通过ODBC连接ORACLE数据库的VB程序时,总是出现该错误,估计应该是数据量比较大,导致超时. 查到解决方法有如下四种 (选任意一种即可): ...
- 查看SqlServer的内存使用情况
上一篇提到动态T-SQL会产生较多的执行计划,这些执行计划会占用多少内存呢?今天从徐海蔚的书中找到了答案.动态视图不仅可以查到执行计划的缓存,数据表的页面缓存也可以查到,将SQL整理一下,做个标记. ...