我们来看一下NFC在Android代码中的位置:
1.frameworks/base/core/java/android/nfc
Java代码
ErrorCodes.java
This 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;
}
}
弄了个iserror方法 定义了一堆小于0的常量!等于0就success
public static boolean isError(int code) {
if (code < 0) {
return true;
} else {
return false;
}
}
TagLostException.java
FormatException.java
FormatException.java
自定义的一个类型转化异常!
public FormatException(String message) {
super(message);
}
自己抛出异常
public FormatException(String message) {
super(message);
}
自己抛出异常
LlcpPacket.java
Represents a LLCP packet received in a LLCP Connectionless communication
LLCP –其在定義一個通訊協定,以管理架構在ISO 18092/NFC IP-1的NFC設備間的邏輯連結,當然這個通訊協定主要是為了Peer-to-Peer模式下,設備間通訊時使用。
private final int mRemoteSap;private final byte[] mDataBuffer;
LLCP –其在定義一個通訊協定,以管理架構在ISO 18092/NFC IP-1的NFC設備間的邏輯連結,當然這個通訊協定主要是為了Peer-to-Peer模式下,設備間通訊時使用。
private final int mRemoteSap;private final byte[] mDataBuffer;
NdefMessage.java
Represents 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);
Represents 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 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 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);
private native byte[] generate(short flags, short tnf, byte[] type, byte[] id, byte[] data);
NfcAdapter.java
Represents the device's local NFC adapter.
NfcManager.java
High level manager used to obtain an instance of an
其实只有一个getDefaultAdapter()说明NfcAdapter其实正扮演着manager的角色
其实只有一个getDefaultAdapter()说明NfcAdapter其实正扮演着manager的角色
NfcSecureElement.java
This 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的管理所有安全方面的元素
这个类提供了主要的API的管理所有安全方面的元素
Tag.java
Represents 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;
Represents 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;
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.java
private String[][] mTechLists;
public TechListParcel(String[]... strings) {
mTechLists = strings;
}
private String[][] mTechLists;
public TechListParcel(String[]... strings) {
mTechLists = strings;
}
TransceiveResult.java
Class used to pipe transceive result from the NFC service.
private final boolean mTagLost;
private final boolean mSuccess;
private final byte[] mResponseData;
private final boolean mTagLost;
private final boolean mSuccess;
private final byte[] mResponseData;
ILlcpConnectionlessSocket.aidl
ILlcpServiceSocket.aidl
ILlcpSocket.aidl
INfcAdapter.aidl
INfcSecureElement.aidl
INfcTag.aidl
IP2pInitiator.aidl
IP2pTarget.aidl
LlcpPacket.aidl
NdefMessage.aidl
NdefRecord.aidl
Tag.aidl
TechListParcel.aidl
TransceiveResult.aidl
ILlcpServiceSocket.aidl
ILlcpSocket.aidl
INfcAdapter.aidl
INfcSecureElement.aidl
INfcTag.aidl
IP2pInitiator.aidl
IP2pTarget.aidl
LlcpPacket.aidl
NdefMessage.aidl
NdefRecord.aidl
Tag.aidl
TechListParcel.aidl
TransceiveResult.aidl
2.frameworks/base/core/java/android/nfc/tech
Java代码
NFC Protocol Bindings –在Peer-to-Peer模式下,NFC Forum不自己另定高層的資料傳輸協定,而是直接使用其他既有的資料傳輸協定,如IP、OBEX等,來實現該模式下設備間資料的傳輸。
Java代码
NFC Protocol Bindings –在Peer-to-Peer模式下,NFC Forum不自己另定高層的資料傳輸協定,而是直接使用其他既有的資料傳輸協定,如IP、OBEX等,來實現該模式下設備間資料的傳輸。
BasicTagTechnology.java
A 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;
A 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.java
A low-level connection to a
{@link Tag} using the ISO-DEP technology, also known as ISO1443-4.
MifareClassic.java
即Philips的Mifare,现有悠游卡即属此类
MifareUltralight.java
Ndef.java
NDEF – 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]
目前整個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 call
NdefFormatable.java
An interface to a
{@link Tag} allowing to format the tag as NDEF.
NfcA.java
A low-level connection to a
{@link Tag} using the NFC-A technology, also known as ISO1443-3A.
NfcB.java
A low-level connection to a
{@link Tag} using the NFC-B technology, also known as ISO1443-3B.
NfcF.java
A low-level connection to a
{@link Tag} using the NFC-F technology, also known as JIS6319-4.
NfcV.java
A low-level connection to a
{@link Tag} using NFC vicinity technology, also known as ISO15693.
TagTechnology.java
最上层的接口这里定义集中协议类型的标识 继承closeable便于克隆
拥有方法getTag connect reconnect close isConnected
最上层的接口这里定义集中协议类型的标识 继承closeable便于克隆
拥有方法getTag connect reconnect close isConnected