安卓NFC开发学习笔记探究.doc

  1. 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
  2. 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  3. 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
大家学习android开发建议首选android开发文档,该文档在你下载的sdk中,路径:/sdk/docs/index.html 目前NFC应用的大的框架上的理解: 我使用的API LEVEL是19,支持的API有三个:android.nfc,android.nfc.cardemulator,android.nfc.tech NFC在手机上的应用大体分为两类:读卡器和卡 android.nfc.cardemulator接口是为NFC作为卡应用提供的接口,在较低版本的API上是没有的 android.nfc.tech,android.nfc接口是为NFC作为读卡器应用提供的接口 首先说作为卡,nfc有两种实现方式,一个是使用NFC芯片作为卡,另一个是使用SIM作为卡 Figure 1. NFC card emulation with a secure element. 至于从读卡器发送的指令到底是传递到NFC芯片还是SIM由NFC Controler控制,图中Secure Element是指SIM,Host-CPU指NFC芯片 android提供HostApduService用于NFC芯片,OffHostApduService用于SIM芯片,传递方向在res/xml文件中通过AID来控制 ps:Host-Based Card Emulator 简称为HCE 代码实现: AndroidManifest.xml 中 配置service,因为作为卡实现的话,NFC功能是作为service存在的 ??????? service android:name=com.shhic.nfcapp.NFCService android:exported=true ?????? ??? ?android:permission=android.permission.BIND_NFC_SERVICE ??????????? intent-filter ?????? ??? ??? ?action android:name=android.nfc.cardemulation.action.HOST_APDU_SERVICE/ ?? ??? ??? ?/intent-filter ?? ??? ??? ?meta-data android:name=android.nfc.cardemulation.host_apdu_service ?????? ??? ??? ?android:resource=@xml/apduservice/ ??????? /service res/xml/apduservice.xml 中配置service响应的AID host-apdu-service xmlns:android=/apk/res/android ?????????? android:description=@string/servicedesc ?????????? android:requireDeviceUnlock=false ??? aid-group android:description=@string/aiddescription ??????????????? android:category=other ??????? aid-filter android:name=F0010203040506/ ??? /aid-group /host-apdu-service 配置文件完成后编写service的处理方法: NFCService需要继承HostApduService,如果需要与Activity通信,建议采用广播方式 也可以自己实现观察者模式,只是这样就需要持有Activity的引用,感觉不太好 NFCService.java public class NFCService extends HostApduService { ?? ?private Intent intent = new Intent(munication.RECEIVER); ?? ? ?? ?@Override ?? ?public void onCreate() ?? ?{ ?? ??? ?//启动Acivity ?? ??? ?Intent i = new Intent(); ?? ??? ?i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);//需要启动的Activity不是当前Activity的时候需要用FLAG_ACTIVITY_NEW_TASK ?? ??? ?i.setAction(com.apdu.nfc); ?? ??? ?getApplication().startActivity(i); ?? ??? ?To

文档评论(0)

1112111 + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档