Android NFC 标签分发系统小析
2014-02-19 14:24
627 查看
要弄清tag dispatch system,首先需要了解一下。几个关键类之间的关系。
NfcService NativeNfcManager NfcDispatcher
NfcService 实现了接口类DeviceHostListener
public class NfcService extends Application implements
DeviceHostListener
并且在onCreate函数中构造NativeNfcManager对象的时候,将自己作为参数传递下去。
mDeviceHost = new NativeNfcManager(this, this);
NativeNfcManager的构造函数如下。
public NativeNfcManager(Context context, DeviceHostListener listener) {
mListener = listener;
initializeNativeStructure();
mContext = context;
}
到这里NativeNfcManager和NfcService就被关联到一起。将来jni就可以和NfcService通信了。
当手机检测到新的tag.会通过jni接口调用NativeNfcManager.notifyNdefMessageListeners
用来通知NFCservice检测到了新的tag.
private void notifyNdefMessageListeners(NativeNfcTag tag) {
mListener.onRemoteEndpointDiscovered(tag);
}
这里实际上调用的就是NfcService的onRemoteEndpointDiscovered
@Override
public void onRemoteEndpointDiscovered(TagEndpoint tag) {
sendMessage(NfcService.MSG_NDEF_TAG, tag);
}
这里的Message会被NfcServiceHandler接受并处理
case MSG_NDEF_TAG:
......
dispatchTagEndpoint(tag);
在函数dispatchTagEndpoint中会调用到NfcDispatcher.dispatchTag
mNfcDispatcher.dispatchTag(tag)
在接口dispatchTag中就实现了如下图所示的分发逻辑。优先级顺序为NDEF_DISCOVERED, TECH_DISCOVERED, TAG_DISCOVERED
NfcService NativeNfcManager NfcDispatcher
NfcService 实现了接口类DeviceHostListener
public class NfcService extends Application implements
DeviceHostListener
并且在onCreate函数中构造NativeNfcManager对象的时候,将自己作为参数传递下去。
mDeviceHost = new NativeNfcManager(this, this);
NativeNfcManager的构造函数如下。
public NativeNfcManager(Context context, DeviceHostListener listener) {
mListener = listener;
initializeNativeStructure();
mContext = context;
}
到这里NativeNfcManager和NfcService就被关联到一起。将来jni就可以和NfcService通信了。
当手机检测到新的tag.会通过jni接口调用NativeNfcManager.notifyNdefMessageListeners
用来通知NFCservice检测到了新的tag.
private void notifyNdefMessageListeners(NativeNfcTag tag) {
mListener.onRemoteEndpointDiscovered(tag);
}
这里实际上调用的就是NfcService的onRemoteEndpointDiscovered
@Override
public void onRemoteEndpointDiscovered(TagEndpoint tag) {
sendMessage(NfcService.MSG_NDEF_TAG, tag);
}
这里的Message会被NfcServiceHandler接受并处理
case MSG_NDEF_TAG:
......
dispatchTagEndpoint(tag);
在函数dispatchTagEndpoint中会调用到NfcDispatcher.dispatchTag
mNfcDispatcher.dispatchTag(tag)
在接口dispatchTag中就实现了如下图所示的分发逻辑。优先级顺序为NDEF_DISCOVERED, TECH_DISCOVERED, TAG_DISCOVERED
相关文章推荐
- 浅谈NFC技术应用
- android NFC
- M2M的利器-Android POS
- BB10请求接收NFC事件
- BB10 处理NFC事件
- BB10 创建一个NDEF消息
- BB10 读取NFC tag
- BB10 写NDEF消息到NFC tag上
- BB10 点对点的向另一个NFC设备发NDEF消息
- BB10 点对点的向另一个NFC设备发NDEF消息
- BB10 写NDEF消息到NFC tag上
- BB10 读取NFC tag
- BB10 创建一个NDEF消息
- BB10 处理NFC事件
- BB10请求接收NFC事件
- [笔记]NFC笔记——主动模式和被动模式下激活协议的流程
- NFC(近场通信)技术的移动应用
- 在Android中访问内置SE和基于SE的卡模拟(一)
- NFC (一)概述
- Android开发中如何监听指定URL地址的标签扫描