首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Android >

Android学习札记之NFC近距离无线通讯技术(Dean)(转载)

2012-06-29 
Android学习笔记之NFC近距离无线通讯技术(Dean)(转载)ErrorCodes.javaThis class defines all the error c

Android学习笔记之NFC近距离无线通讯技术(Dean)(转载)
ErrorCodes.javaThis class defines all the error codes that can be returned by the service and producing an exception on the application level. These are needed since binders does not support exceptions.弄了个iserror方法 定义了一堆小于0的常量!等于0就success public static boolean isError(int code) { if (code < 0) { return true; } else { return false; } }TagLostException.javaFormatException.java自定义的一个类型转化异常!public FormatException(String message) { super(message); }自己抛出异常LlcpPacket.javaRepresents a LLCP packet received in a LLCP Connectionless communicationLLCP –其在定義一個通訊協定,以管理架構在ISO 18092/NFC IP-1的NFC設備間的邏輯連結,當然這個通訊協定主要是為了Peer-to-Peer模式下,設備間通訊時使用。private final int mRemoteSap;private final byte[] mDataBuffer;NdefMessage.javaRepresents an NDEF (NFC Data Exchange Format) data message that contains one or more 数据的数据交换格式public NdefMessage(byte[] data) throws FormatException { mRecords = null; // stop compiler complaints about final field if (parseNdefMessage(data) == -1) { throw new FormatException("Error while parsing NDEF message"); } }private native int parseNdefMessage(byte[] data);NdefRecord.java逻辑记录数据交换的格式。 private final byte mFlags; private static final byte FLAG_MB = (byte) 0x80; private static final byte FLAG_ME = (byte) 0x40; private static final byte FLAG_CF = (byte) 0x20; private static final byte FLAG_SR = (byte) 0x10; private static final byte FLAG_IL = (byte) 0x08; private final short mTnf; 表示格式如何解读型态栏位 private final byte[] mType;描述了记录格式 private final byte[] mId;一个唯一的标识符备案 private final byte[] mPayload;实际数据的有效载荷 private native int parseNdefRecord(byte[] data); private native byte[] generate(short flags, short tnf, byte[] type, byte[] id, byte[] data);NfcAdapter.javaRepresents the device's local NFC adapter.NfcManager.javaHigh level manager used to obtain an instance of an其实只有一个getDefaultAdapter()说明NfcAdapter其实正扮演着manager的角色NfcSecureElement.javaThis class provides the primary API for managing all aspects Secure Element.Get an instance of this class by calling Context.getSystemService(Context.NFC_SERVICE).这个类提供了主要的API的管理所有安全方面的元素Tag.javaRepresents a (generic) discovered tag. /*package*/ final byte[] mId;The tag identifier /*package*/ final int[] mTechList; /*package*/ final String[] mTechStringList; /*package*/ final Bundle[] mTechExtras; /*package*/ final int mServiceHandle; // for use by NFC service, 0 indicates a mock /*package*/ final INfcTag mTagService; /*package*/ int mConnectedTechnology;public Tag(byte[] id, int[] techList, Bundle[] techListExtras, int serviceHandle, INfcTag tagService) { if (techList == null) { throw new IllegalArgumentException("rawTargets cannot be null"); } mId = id; mTechList = Arrays.copyOf(techList, techList.length); mTechStringList = generateTechStringList(techList); // Ensure mTechExtras is as long as mTechList mTechExtras = Arrays.copyOf(techListExtras, techList.length); mServiceHandle = serviceHandle; mTagService = tagService; mConnectedTechnology = -1; }TechListParcel.javaprivate String[][] mTechLists; public TechListParcel(String[]... strings) { mTechLists = strings; }TransceiveResult.javaClass used to pipe transceive result from the NFC service. private final boolean mTagLost; private final boolean mSuccess; private final byte[] mResponseData;ILlcpConnectionlessSocket.aidlILlcpServiceSocket.aidlILlcpSocket.aidlINfcAdapter.aidlINfcSecureElement.aidlINfcTag.aidlIP2pInitiator.aidlIP2pTarget.aidlLlcpPacket.aidlNdefMessage.aidlNdefRecord.aidlTag.aidlTechListParcel.aidlTransceiveResult.aidl

?

2.frameworks/base/core/java/android/nfc/tech
Java代码

NFC Protocol Bindings –在Peer-to-Peer模式下,NFC Forum不自己另定高層的資料傳輸協定,而是直接使用其他既有的資料傳輸協定,如IP、OBEX等,來實現該模式下設備間資料的傳輸。 BasicTagTechnology.javaA base class for tag technologies that are built on top of transceive().这个应该是最顶端的transceive()方法!IsoDep.java NfcA.javaNfcB.javaNfcF.javaNfcV.java全部调用此方法实现!    /*package*/ final Tag mTag;    /*package*/ boolean mIsConnected;    /*package*/ int mSelectedTechnology;IsoDep.javaA low-level connection to a {@link Tag} using the ISO-DEP technology, also known as ISO1443-4.MifareClassic.java即Philips的Mifare,现有悠游卡即属此类MifareUltralight.javaNdef.javaNDEF – NFC Data Exchange Format (NDEF) 主要在定義一個簡潔與共同的資料格式,此資料格式將可作為NFC設備在讀取標籤(Tag)資料時的一個依據。此規格於2006年便完成制定並已公告。 目前整個NFC相關技術規格標準的制定,主要是由NFC Forum負責下圖為NFC Forum所展示的NFC技術規格架構[img]http://dl.iteye.com/upload/attachment/471075/a760e498-60e7-398c-8f23-e7bae2f0f83a.jpg[/img]A high-level connection to a {@link Tag} using one of the NFC type 1, 2, 3, or 4 technologies to interact with NDEF data. MiFare Classic cards that present NDEF data may also be used via this class. To determine the exact technology being used callNdefFormatable.javaAn interface to a {@link Tag} allowing to format the tag as NDEF.NfcA.javaA low-level connection to a {@link Tag} using the NFC-A technology, also known as ISO1443-3A.NfcB.javaA low-level connection to a {@link Tag} using the NFC-B technology, also known as ISO1443-3B.NfcF.javaA low-level connection to a {@link Tag} using the NFC-F technology, also known as JIS6319-4.NfcV.javaA low-level connection to a {@link Tag} using NFC vicinity technology, also known as ISO15693.TagTechnology.java最上层的接口这里定义集中协议类型的标识 继承closeable便于克隆拥有方法getTag connect reconnect close isConnected

?

?

?

这里涉及到几个协议一起来看一下

3.frameworks/base/core/java/com/android/internal/nfcLlcpConnectionlessSocket.javaLlcpException.javaLlcpServiceSocket.javaLlcpSocket.javaNfcException.javaP2pDevice.javaP2pDevice is the abstract base class for all supported P2P targets theNfcManager can handle.P2pInitiator.javaP2pInitiator represents the initiator in an NFC-IP1 peer-to-peercommunication.P2pTarget.javaP2pTarget represents the target in an NFC-IP1 peer-to-peer communication.

?

原文地址:http://www.apkbus.com/forum.php?mod=viewthread&tid=1186

热点排行