package android.nfc介绍

本文深入探讨了Android系统中NFC(近场通信)功能的实现与应用,包括关键类解析、接口介绍及实际场景运用,揭示了如何通过Android.Nfc包实现设备间的数据交换与标签交互。

android.nfc 包下:

此包提供可以使用NFC功能,允许应用程序读取NFC标签中的NDEF(NFC数据交换格式)数据。一个“tag”实际上可以是另一个附带标签的设备。

欲知更多信息,请查看Near Field Communication导读。

以下为重要 类的汇总:

NfcManager

这是一个高级管理器,用来获得设备的NfcAdapter。你可以通过getSystemService(String)方法获得NfcAdapter的实例。

NfcAdapter
本类代表 设备的 NfcAdapter,是执行NFC操作入口。你可以通过 getDefaultAdapter() , or  getDefaultAdapter(android.content.Context)来获取实例。
NdefMessage
本类代表 NDEF( NFC数据交换格式)数据的信息,是标准格式"records"中的、在NFC设备与标签之间传递的信息。你的应用程序可以从ACTION_TAG_DISCOVERED意图中接收到这些信息。
NdefRecord
本类代表一条记录,记录用来交付NdefMessage和描述类型的数据共享和数据本身。

提示: 并不是所有的设备提供NFC功能。

接口


NfcAdapter.CreateNdefMessageCallback  :一个回调时要调用能力范围内另一个 具有NDEF推的NFC设备。
NfcAdapter.OnNdefPushCompleteCallback  :一个回调接口,当系统成功的传递你的NdefMessage给另一个设备的时候调用。
NfcAdapter.ReaderCallback   :一个回调接口,当系统发现一个标签在前台可读模式下操作时调用。


NdefMessage  :代表不可改变的 NDEF信息;
NdefRecord   :代表不可改变的NDEF记录;
NfcAdapter   :代表本地NFC适配器;
NfcEvent     :包装与任何NFC事件相关的信息;
NfcManager   :用于获取NfcAdapter实例的高级管理器;
Tag          :代表已被获取到的一个NFC标签。


10-23 15:33:14.063722 5334 5334 W RegisteredComponentCache: Unable to load component info ResolveInfo{f849d88 com.realmestore.app/in.juspay.hypernfc.NfcActivity m=0x108000 userHandle=UserHandle{0}} 10-23 15:33:14.063722 5334 5334 W RegisteredComponentCache: org.xmlpull.v1.XmlPullParserException: No android.nfc.action.TECH_DISCOVERED meta-data 10-23 15:33:14.063722 5334 5334 W RegisteredComponentCache: at com.android.nfc.RegisteredComponentCache.parseComponentInfo(RegisteredComponentCache.java:186) 10-23 15:33:14.063722 5334 5334 W RegisteredComponentCache: at com.android.nfc.RegisteredComponentCache.generateComponentsList(RegisteredComponentCache.java:150) 10-23 15:33:14.063722 5334 5334 W RegisteredComponentCache: at com.android.nfc.RegisteredComponentCache.<init>(RegisteredComponentCache.java:71) 10-23 15:33:14.063722 5334 5334 W RegisteredComponentCache: at com.android.nfc.NfcDispatcher.<init>(NfcDispatcher.java:195) 10-23 15:33:14.063722 5334 5334 W RegisteredComponentCache: at com.android.nfc.NfcService.<init>(NfcService.java:1656) 10-23 15:33:14.063722 5334 5334 W RegisteredComponentCache: at com.android.nfc.NfcApplication.onCreate(NfcApplication.java:116) 10-23 15:33:14.063722 5334 5334 W RegisteredComponentCache: at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1404) 10-23 15:33:14.063722 5334 5334 W RegisteredComponentCache: at android.app.ActivityThread.handleBindApplication(ActivityThread.java:8213) 10-23 15:33:14.063722 5334 5334 W RegisteredComponentCache: at android.app.ActivityThread.-$$Nest$mhandleBindApplication(Unknown Source:0) 10-23 15:33:14.063722 5334 5334 W RegisteredComponentCache: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2642) 10-23 15:33:14.063722 5334 5334 W RegisteredComponentCache: at android.os.Handler.dispatchMessage(Handler.java:107) 10-23 15:33:14.063722 5334 5334 W RegisteredComponentCache: at android.os.Looper.loopOnce(Looper.java:282) 10-23 15:33:14.063722 5334 5334 W RegisteredComponentCache: at android.os.Looper.loop(Looper.java:387) 10-23 15:33:14.063722 5334 5334 W RegisteredComponentCache: at android.app.ActivityThread.main(ActivityThread.java:9500) 10-23 15:33:14.063722 5334 5334 W RegisteredComponentCache: at java.lang.reflect.Method.invoke(Native Method) 10-23 15:33:14.063722 5334 5334 W RegisteredComponentCache: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:600) 10-23 15:33:14.063722 5334 5334 W RegisteredComponentCache: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1005)
最新发布
10-28
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值