W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
本模塊主要用于操作及管理NFC Tag。
本模塊首批接口從API version 7開始支持。后續(xù)版本的新增接口,采用上角標(biāo)單獨(dú)標(biāo)記接口的起始版本。
開發(fā)Tag讀寫相關(guān)應(yīng)用時(shí),需要在應(yīng)用的屬性配置文件中,聲明與NFC相關(guān)的屬性值,比如,在module.json5文件中,聲明下面屬性值:
- {
- "module": {
- // other declared attributes.
- "abilities": [
- {
- "skills": [
- {
- "actions": [
- // other declared actions,
- // add the nfc tag action
- "ohos.nfc.tag.action.TAG_FOUND"
- ]
- }
- ],
- "metadata": [
- {
- "name": "tag-tech",
- "value": "NfcA"
- },
- {
- "name": "tag-tech",
- "value": "IsoDep"
- },
- // add other technology if neccessary,
- // such as: NfcB/NfcF/NfcV/Ndef/MifareClassic/MifareUL/NdefFormatable
- ]
- }
- ],
- "requestPermissions": [
- "name": "ohos.permission.NFC_TAG",
- "reason": "tag",
- ]
- }
- }
在對相關(guān)Tag類型卡片進(jìn)行讀寫之前,必須先獲取TagInfo相關(guān)屬性值,以確認(rèn)設(shè)備讀取到的Tag卡片支持哪些技術(shù)類型。這樣Tag應(yīng)用程序才能調(diào)用正確的接口和所讀取到的Tag卡片進(jìn)行通信。
- import tag from '@ohos.nfc.tag';
- onCreate(want, launchParam) {
- // add other code here...
- // want is initialized by nfc service, contains tag info for this found tag
- var tagInfo;
- try {
- tagInfo = tag.getTagInfo(want);
- } catch (error) {
- console.log("tag.getTagInfo catched error: " + error);
- }
- if (tagInfo == null || tagInfo == undefined) {
- console.log("no TagInfo to be created, ignore it.");
- return;
- }
- // get the supported technologies for this found tag.
- var isNfcATag = false;
- var isIsoDepTag = false;
- for (var i = 0; i < tagInfo.technology.length; i++) {
- if (tagInfo.technology[i] == tag.NFC_A) {
- isNfcATag = true;
- }
- if (tagInfo.technology[i] == tag.ISO_DEP) {
- isIsoDepTag = true;
- }
- // also check for technology: tag.NFC_B/NFC_F/NFC_V/NDEF/MIFARE_CLASSIC/MIFARE_ULTRALIGHT/NDEF_FORMATABLE
- }
- // use NfcA APIs to access the found tag.
- if (isNfcATag) {
- var nfcA;
- try {
- nfcA = tag.getNfcATag(taginfo);
- } catch (error) {
- console.log("tag.getNfcATag catched error: " + error);
- }
- // other code to read or write this found tag.
- }
- // use getIsoDep APIs to access the found tag.
- if (isIsoDepTag) {
- var isoDep;
- try {
- isoDep = tag.getIsoDep(taginfo);
- } catch (error) {
- console.log("tag.getIsoDep catched error: " + error);
- }
- // other code to read or write this found tag.
- }
- // use the same code to handle for "NfcA/NfcB/NfcF/NfcV/Ndef/MifareClassic/MifareUL/NdefFormatable".
- }
getNfcATag(tagInfo: TagInfo): NfcATag
獲取NFC A類型Tag對象,通過該對象可訪問NfcA技術(shù)類型的Tag。
從 API version 7 開始支持,從 API version 9 開始廢棄,建議使用tag.getNfcA替代。
系統(tǒng)能力: SystemCapability.Communication.NFC.Tag
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
taginfo | 是 | 包含Tag技術(shù)類型和相關(guān)參數(shù),從tag.getTagInfo(want: Want)獲取。 |
返回值:
類型 | 說明 |
---|---|
NFC A類型Tag對象。 |
getNfcA(tagInfo: TagInfo): NfcATag
獲取NFC A類型Tag對象,通過該對象可訪問NfcA技術(shù)類型的Tag。
系統(tǒng)能力: SystemCapability.Communication.NFC.Tag
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
taginfo | 是 | 包含Tag技術(shù)類型和相關(guān)參數(shù),從tag.getTagInfo(want: Want)獲取。 |
返回值:
類型 | 說明 |
---|---|
NFC A類型Tag對象。 |
錯(cuò)誤碼:
以下錯(cuò)誤碼的詳細(xì)介紹請參見NFC錯(cuò)誤碼。
錯(cuò)誤碼ID | 錯(cuò)誤信息 |
---|---|
3100201 | Tag running state is abnormal in service. |
getNfcBTag(tagInfo: TagInfo): NfcBTag
獲取NFC B類型Tag對象,通過該對象可訪問NfcB技術(shù)類型的Tag。
從 API version 7 開始支持,從 API version 9 開始廢棄,建議使用tag.getNfcB替代。
系統(tǒng)能力: SystemCapability.Communication.NFC.Tag
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
taginfo | 是 | 包含Tag技術(shù)類型和相關(guān)參數(shù),從tag.getTagInfo(want: Want)獲取。 |
返回值:
類型 | 說明 |
---|---|
NFC B類型Tag對象。 |
getNfcB(tagInfo: TagInfo): NfcBTag
獲取NFC B類型Tag對象,通過該對象可訪問NfcB技術(shù)類型的Tag。
系統(tǒng)能力: SystemCapability.Communication.NFC.Tag
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
taginfo | 是 | 包含Tag技術(shù)類型和相關(guān)參數(shù),從tag.getTagInfo(want: Want)獲取。 |
返回值:
類型 | 說明 |
---|---|
NFC B類型Tag對象。 |
錯(cuò)誤碼:
以下錯(cuò)誤碼的詳細(xì)介紹請參見NFC錯(cuò)誤碼。
錯(cuò)誤碼ID | 錯(cuò)誤信息 |
---|---|
3100201 | Tag running state is abnormal in service. |
getNfcFTag(tagInfo: TagInfo): NfcFTag
獲取NFC F類型Tag對象,通過該對象可訪問NfcF技術(shù)類型的Tag。
從 API version 7 開始支持,從 API version 9 開始廢棄,建議使用tag.getNfcF替代。
系統(tǒng)能力: SystemCapability.Communication.NFC.Tag
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
taginfo | 是 | 包含Tag技術(shù)類型和相關(guān)參數(shù),從tag.getTagInfo(want: Want)獲取。 |
返回值:
類型 | 說明 |
---|---|
NFC F類型Tag對象。 |
getNfcF(tagInfo: TagInfo): NfcFTag
獲取NFC F類型Tag對象,通過該對象可訪問NfcF技術(shù)類型的Tag。
系統(tǒng)能力: SystemCapability.Communication.NFC.Tag
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
taginfo | 是 | 包含Tag技術(shù)類型和相關(guān)參數(shù),從tag.getTagInfo(want: Want)獲取。 |
返回值:
類型 | 說明 |
---|---|
NFC F類型Tag對象。 |
錯(cuò)誤碼:
以下錯(cuò)誤碼的詳細(xì)介紹請參見NFC錯(cuò)誤碼。
錯(cuò)誤碼ID | 錯(cuò)誤信息 |
---|---|
3100201 | Tag running state is abnormal in service. |
getNfcVTag(tagInfo: TagInfo): NfcVTag
獲取NFC V類型Tag對象,通過該對象可訪問NfcV技術(shù)類型的Tag。
從 API version 7 開始支持,從 API version 9 開始廢棄,建議使用tag.getNfcV替代。
系統(tǒng)能力: SystemCapability.Communication.NFC.Tag
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
taginfo | 是 | 包含Tag技術(shù)類型和相關(guān)參數(shù),從tag.getTagInfo(want: Want)獲取。 |
返回值:
類型 | 說明 |
---|---|
NFC V類型Tag對象。 |
getNfcV(tagInfo: TagInfo): NfcVTag
獲取NFC V類型Tag對象,通過該對象可訪問NfcV技術(shù)類型的Tag。
系統(tǒng)能力: SystemCapability.Communication.NFC.Tag
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
taginfo | 是 | 包含Tag技術(shù)類型和相關(guān)參數(shù),從tag.getTagInfo(want: Want)獲取。 |
返回值:
類型 | 說明 |
---|---|
NFC V類型Tag對象。 |
錯(cuò)誤碼:
以下錯(cuò)誤碼的詳細(xì)介紹請參見NFC錯(cuò)誤碼。
錯(cuò)誤碼ID | 錯(cuò)誤信息 |
---|---|
3100201 | Tag running state is abnormal in service. |
getIsoDep(tagInfo: TagInfo): IsoDepTag
獲取IsoDep類型Tag對象,通過該對象可訪問支持IsoDep技術(shù)類型的Tag。
系統(tǒng)能力: SystemCapability.Communication.NFC.Tag
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
taginfo | 是 | 包含Tag技術(shù)類型和相關(guān)參數(shù),從tag.getTagInfo(want: Want)獲取。 |
返回值:
類型 | 說明 |
---|---|
IsoDep類型Tag對象,通過該對象訪問IsoDep類型的相關(guān)接口。 |
錯(cuò)誤碼:
以下錯(cuò)誤碼的詳細(xì)介紹請參見NFC錯(cuò)誤碼。
錯(cuò)誤碼ID | 錯(cuò)誤信息 |
---|---|
3100201 | Tag running state is abnormal in service. |
getNdef(tagInfo: TagInfo): NdefTag
獲取NDEF類型Tag對象,通過該對象可訪問支持NDEF技術(shù)類型的Tag。
系統(tǒng)能力: SystemCapability.Communication.NFC.Tag
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
taginfo | 是 | 包含Tag技術(shù)類型和相關(guān)參數(shù),從tag.getTagInfo(want: Want)獲取。 |
返回值:
類型 | 說明 |
---|---|
NDEF類型Tag對象,通過該對象訪問NDEF類型的相關(guān)接口。 |
錯(cuò)誤碼:
以下錯(cuò)誤碼的詳細(xì)介紹請參見NFC錯(cuò)誤碼。
錯(cuò)誤碼ID | 錯(cuò)誤信息 |
---|---|
3100201 | Tag running state is abnormal in service. |
getMifareClassic(tagInfo: TagInfo): MifareClassicTag
獲取MIFARE Classic類型Tag對象,通過該對象訪問支持MIFARE Classic技術(shù)類型的Tag。
系統(tǒng)能力: SystemCapability.Communication.NFC.Tag
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
taginfo | 是 | 包含Tag技術(shù)類型和相關(guān)參數(shù),從tag.getTagInfo(want: Want)獲取。 |
返回值:
類型 | 說明 |
---|---|
MIFARE Classic類型Tag對象,通過該對象訪問MIFARE Classic類型的相關(guān)接口。 |
錯(cuò)誤碼:
以下錯(cuò)誤碼的詳細(xì)介紹請參見NFC錯(cuò)誤碼。
錯(cuò)誤碼ID | 錯(cuò)誤信息 |
---|---|
3100201 | Tag running state is abnormal in service. |
getMifareUltralight(tagInfo: TagInfo): MifareUltralightTag
獲取MIFARE Ultralight類型Tag對象,通過該對象可訪問支持MIFARE Ultralight技術(shù)類型的Tag。
系統(tǒng)能力: SystemCapability.Communication.NFC.Tag
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
taginfo | 是 | 包含Tag技術(shù)類型和相關(guān)參數(shù),從tag.getTagInfo(want: Want)獲取。 |
返回值:
類型 | 說明 |
---|---|
MIFARE Ultralight類型Tag對象,通過該對象訪問MIFARE Ultralight類型的相關(guān)接口。 |
錯(cuò)誤碼:
以下錯(cuò)誤碼的詳細(xì)介紹請參見NFC錯(cuò)誤碼。
錯(cuò)誤碼ID | 錯(cuò)誤信息 |
---|---|
3100201 | Tag running state is abnormal in service. |
getNdefFormatable(tagInfo: TagInfo): NdefFormatableTag
獲取NDEF Formatable類型Tag對象,通過該對象可訪問支持NDEF Formatable技術(shù)類型的Tag。
系統(tǒng)能力: SystemCapability.Communication.NFC.Tag
返回值:
類型 | 說明 |
---|---|
NDEF Formatable類型Tag對象,通過該對象訪問NDEF Formatable類型的相關(guān)接口。 |
錯(cuò)誤碼:
以下錯(cuò)誤碼的詳細(xì)介紹請參見NFC錯(cuò)誤碼。
錯(cuò)誤碼ID | 錯(cuò)誤信息 |
---|---|
3100201 | Tag running state is abnormal in service. |
getTagInfo(want: Want): TagInfo
從Want中獲取TagInfo,Want是被NFC服務(wù)初始化,包含了TagInfo所需的屬性值。
系統(tǒng)能力: SystemCapability.Communication.NFC.Tag
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
want | 是 | 分發(fā)Ability時(shí),在系統(tǒng)onCreate入口函數(shù)的參數(shù)中獲取。 |
返回值:
類型 | 說明 |
---|---|
TagInfo對象,用于獲取不同技術(shù)類型的Tag對象。 |
makeUriRecord(uri: string): NdefRecord;
根據(jù)輸入的URI,構(gòu)建NDEF標(biāo)簽的Record數(shù)據(jù)對象。
系統(tǒng)能力: SystemCapability.Communication.NFC.Tag
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
uri | string | 是 | 寫入到NDEF Record里面的數(shù)據(jù)內(nèi)容。 |
返回值:
類型 | 說明 |
---|---|
NDEF標(biāo)簽的Record,詳見NDEF技術(shù)規(guī)范《NFCForum-TS-NDEF_1.0》。 |
示例:
- import tag from '@ohos.nfc.tag';
- try {
- let uri = "https://gitee.com/openharmony"; // change it to be correct.
- let ndefRecord = tag.ndef.makeUriRecord(uri);
- if (ndefRecord != undefined) {
- console.log("ndefMessage makeUriRecord rtdType: " + ndefRecord.rtdType);
- console.log("ndefMessage makeUriRecord payload: " + ndefRecord.payload);
- } else {
- console.log("ndefMessage makeUriRecord ndefRecord: " + ndefRecord);
- }
- } catch (busiError) {
- console.log("ndefMessage makeUriRecord catched busiError: " + busiError);
- }
makeTextRecord(text: string, locale: string): NdefRecord;
根據(jù)輸入的文本數(shù)據(jù)和編碼類型,構(gòu)建NDEF標(biāo)簽的Record。
系統(tǒng)能力: SystemCapability.Communication.NFC.Tag
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
text | string | 是 | 寫入到NDEF Record里面的文本數(shù)據(jù)內(nèi)容。 |
locale | string | 是 | 文本數(shù)據(jù)內(nèi)容的編碼方式。 |
返回值:
類型 | 說明 |
---|---|
NDEF標(biāo)簽的Record,詳見NDEF技術(shù)規(guī)范《NFCForum-TS-NDEF_1.0》。 |
示例:
- import tag from '@ohos.nfc.tag';
- try {
- let text = "Hello World"; // change it to be correct.
- let locale = "en"; // change it to be correct.
- let ndefRecord = tag.ndef.makeTextRecord(text, locale);
- if (ndefRecord != undefined) {
- console.log("ndefMessage makeTextRecord rtdType: " + ndefRecord.rtdType);
- console.log("ndefMessage makeTextRecord payload: " + ndefRecord.payload);
- } else {
- console.log("ndefMessage makeTextRecord ndefRecord: " + ndefRecord);
- }
- } catch (busiError) {
- console.log("ndefMessage makeTextRecord catched busiError: " + busiError);
- }
makeMimeRecord(mimeType: string, mimeData: number[]): NdefRecord;
根據(jù)輸入的MIME數(shù)據(jù)和類型,構(gòu)建NDEF標(biāo)簽的Record。
系統(tǒng)能力: SystemCapability.Communication.NFC.Tag
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
mimeType | string | 是 | 符合RFC規(guī)則的MIME類型,比如"text/plain"或"image/jpeg"。 |
mimeData | number[] | 是 | MIME數(shù)據(jù)內(nèi)容,每個(gè)number十六進(jìn)制表示,范圍是0x00~0xFF。 |
返回值:
類型 | 說明 |
---|---|
NDEF標(biāo)簽的Record,詳見NDEF技術(shù)規(guī)范《NFCForum-TS-NDEF_1.0》。 |
示例:
- import tag from '@ohos.nfc.tag';
- try {
- let mimeType = "text/plain"; // change it to be correct.
- let mimeData = [0x01, 0x02, 0x03, 0x04]; // change it to be correct.
- let ndefRecord = tag.ndef.makeMimeRecord(mimeType, mimeData);
- if (ndefRecord != undefined) {
- console.log("ndefMessage makeMimeRecord rtdType: " + ndefRecord.rtdType);
- console.log("ndefMessage makeMimeRecord payload: " + ndefRecord.payload);
- } else {
- console.log("ndefMessage makeMimeRecord ndefRecord: " + ndefRecord);
- }
- } catch (busiError) {
- console.log("ndefMessage makeMimeRecord catched busiError: " + busiError);
- }
makeExternalRecord(domainName: string, type: string, externalData: number[]): NdefRecord;
根據(jù)應(yīng)用程序特定的外部數(shù)據(jù),構(gòu)建NDEF標(biāo)簽的Record。
系統(tǒng)能力: SystemCapability.Communication.NFC.Tag
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
domainName | string | 是 | 外部數(shù)據(jù)發(fā)布組織的域名,一般是應(yīng)用程序的包名。 |
type | string | 是 | 外部數(shù)據(jù)的指定類型。 |
externalData | number[] | 是 | 外部數(shù)據(jù)內(nèi)容,每個(gè)number十六進(jìn)制表示,范圍是0x00~0xFF。 |
返回值:
類型 | 說明 |
---|---|
NDEF標(biāo)簽的Record,詳見NDEF技術(shù)規(guī)范《NFCForum-TS-NDEF_1.0》。 |
示例:
- import tag from '@ohos.nfc.tag';
- try {
- let domainName = "ohos.nfc.application"; // change it to be correct.
- let type = "test"; // change it to be correct.
- let externalData = [0x01, 0x02, 0x03, 0x04]; // change it to be correct.
- let ndefRecord = tag.ndef.makeExternalRecord(domainName, type, externalData);
- if (ndefRecord != undefined) {
- console.log("ndefMessage makeExternalRecord rtdType: " + ndefRecord.rtdType);
- console.log("ndefMessage makeExternalRecord payload: " + ndefRecord.payload);
- } else {
- console.log("ndefMessage makeExternalRecord ndefRecord: " + ndefRecord);
- }
- } catch (busiError) {
- console.log("ndefMessage makeExternalRecord catched busiError: " + busiError);
- }
messageToBytes(ndefMessage: NdefMessage): number[];
把輸入的NDEF消息數(shù)據(jù)對象,轉(zhuǎn)換為字節(jié)格式的數(shù)據(jù)。
系統(tǒng)能力: SystemCapability.Communication.NFC.Tag
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
ndefMessage | 是 | NDEF消息數(shù)據(jù)對象。 |
返回值:
類型 | 說明 |
---|---|
number[] | NDEF消息數(shù)據(jù)對象,所轉(zhuǎn)換成的字節(jié)格式的數(shù)據(jù)。每個(gè)number十六進(jìn)制表示,范圍是0x00~0xFF。 |
示例:
- import tag from '@ohos.nfc.tag';
- let rawData = [0xD1, 0x01, 0x03, 0x54, 0x4E, 0x46, 0x43]; // MUST can be parsed as NDEF Record.
- let ndefMessage;
- try {
- ndefMessage = tag.ndef.createNdefMessage(rawData);
- console.log("ndef createNdefMessage, ndefMessage: " + ndefMessage);
- } catch (busiError) {
- console.log("ndef createNdefMessage busiError: " + busiError);
- }
- try {
- let rawData2 = tag.ndef.messageToBytes(ndefMessage);
- console.log("ndefMessage messageToBytes rawData2: " + rawData2);
- } catch (busiError) {
- console.log("ndefMessage messageToBytes catched busiError: " + busiError);
- }
createNdefMessage(data: number[]): NdefMessage
使用原始字節(jié)數(shù)據(jù)創(chuàng)建NDEF標(biāo)簽的Message。該數(shù)據(jù)必須符合NDEF Record數(shù)據(jù)格式,如果不符合格式,則返回的NdeMessage數(shù)據(jù)對象,所包含的NDE Record列表會為空。
系統(tǒng)能力: SystemCapability.Communication.NFC.Tag
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
data | number[] | 是 | 原始字節(jié),每個(gè)number十六進(jìn)制表示,范圍是0x00~0xFF。要求必須滿足NDEF Record的格式。 |
返回值:
類型 | 說明 |
---|---|
NDEF標(biāo)簽的Message,詳見NDEF技術(shù)規(guī)范《NFCForum-TS-NDEF_1.0》。 |
示例:
- import tag from '@ohos.nfc.tag';
- let rawData = [0xD1, 0x01, 0x03, 0x54, 0x4E, 0x46, 0x43]; // MUST can be parsed as NDEF Record.
- let ndefMessage;
- try {
- ndefMessage = tag.ndef.createNdefMessage(rawData);
- console.log("ndef createNdefMessage, ndefMessage: " + ndefMessage);
- } catch (busiError) {
- console.log("ndef createNdefMessage busiError: " + busiError);
- }
createNdefMessage(ndefRecords: NdefRecord[]): NdefMessage
使用NDEF Records列表,創(chuàng)建NDEF Message。
系統(tǒng)能力: SystemCapability.Communication.NFC.Tag
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
ndefRecords | 是 | NDEF標(biāo)簽的Record列表,詳見NDEF技術(shù)規(guī)范《NFCForum-TS-NDEF_1.0》。 |
返回值:
類型 | 說明 |
---|---|
NDEF標(biāo)簽的Message,詳見NDEF技術(shù)規(guī)范《NFCForum-TS-NDEF_1.0》。 |
示例:
- import tag from '@ohos.nfc.tag';
- let uriRecord = tag.ndef.makeUriRecord("https://gitee.com/openharmony");
- let textRecord = tag.ndef.makeTextRecord("Hello World", "en");
- let ndefRecords = [uriRecord, textRecord];
- let ndefMessage;
- try {
- ndefMessage = tag.ndef.createNdefMessage(ndefRecords);
- console.log("ndef createNdefMessage ndefMessage: " + ndefMessage);
- } catch (busiError) {
- console.log("ndef createNdefMessage busiError: " + busiError);
- }
NFC服務(wù)在讀取到標(biāo)簽時(shí)給出的對象,通過改對象屬性,應(yīng)用知道該標(biāo)簽支持哪些技術(shù)類型,并使用匹配的技術(shù)類型來調(diào)用相關(guān)接口。
系統(tǒng)能力: SystemCapability.Communication.NFC.Tag
需要權(quán)限: ohos.permission.NFC_TAG
名稱 | 類型 | 可讀 | 可寫 | 說明 |
---|---|---|---|---|
uid9+ | number[] | 是 | 否 | 標(biāo)簽的uid,每個(gè)number值是十六進(jìn)制表示,范圍是0x00~0xFF。 |
technology9+ | number[] | 是 | 否 | 支持的技術(shù)類型,每個(gè)number值表示所支持技術(shù)類型的常量值。 |
supportedProfiles | number[] | 是 | 否 | 支持的技術(shù)類型,從API9開始不支持,使用tag.TagInfo#technology替代。 |
NDEF標(biāo)簽Record屬性的定義,參考NDEF標(biāo)簽技術(shù)規(guī)范《NFCForum-TS-NDEF_1.0》的定義細(xì)節(jié)。
系統(tǒng)能力: SystemCapability.Communication.NFC.Tag
名稱 | 類型 | 可讀 | 可寫 | 說明 |
---|---|---|---|---|
tnf | number | 是 | 否 | NDEF Record的TNF(Type Name Field)。 |
rtdType | number[] | 是 | 否 | NDEF Record的RTD(Record Type Definition)類型值,每個(gè)number十六進(jìn)制表示,范圍是0x00~0xFF。 |
id | number[] | 是 | 否 | NDEF Record的ID,每個(gè)number十六進(jìn)制表示,范圍是0x00~0xFF。 |
payload | number[] | 是 | 否 | NDEF Record的PAYLOAD,每個(gè)number十六進(jìn)制表示,范圍是0x00~0xFF。 |
NFC Tag有多種不同的技術(shù)類型,定義常量描述不同的技術(shù)類型。
系統(tǒng)能力: SystemCapability.Communication.NFC.Tag
名稱 | 值 | 說明 |
---|---|---|
NFC_A | 1 | NFC-A (ISO 14443-3A)技術(shù)。 |
NFC_B | 2 | NFC-A (ISO 14443-3B)技術(shù)。 |
ISO_DEP | 3 | ISO-DEP (ISO 14443-4)技術(shù)。 |
NFC_F | 4 | NFC-F (JIS 6319-4)技術(shù)。 |
NFC_V | 5 | NFC-V (ISO 15693)技術(shù)。 |
NDEF | 6 | NDEF技術(shù)。 |
NDEF_FORMATABLE9+ | 7 | 可以格式化的NDEF技術(shù)。 |
MIFARE_CLASSIC | 8 | MIFARE Classic技術(shù)。 |
MIFARE_ULTRALIGHT | 9 | MIFARE Utralight技術(shù)。 |
NDEF Record的TNF(Type Name Field)類型值,參考NDEF標(biāo)簽技術(shù)規(guī)范《NFCForum-TS-NDEF_1.0》的定義細(xì)節(jié)。
系統(tǒng)能力: SystemCapability.Communication.NFC.Tag
名稱 | 值 | 說明 |
---|---|---|
TNF_EMPTY | 0x0 | Empty。 |
TNF_WELL_KNOWN | 0x1 | NFC Forum well-known type [NFC RTD]。 |
TNF_MEDIA | 0x2 | Media-type as defined in RFC 2046 [RFC 2046]。 |
TNF_ABSOLUTE_URI | 0x3 | Absolute URI as defined in RFC 3986 [RFC 3986]。 |
TNF_EXT_APP | 0x4 | NFC Forum external type [NFC RTD]。 |
TNF_UNKNOWN | 0x5 | Unknown。 |
TNF_UNCHANGED | 0x6 | Unchanged (see section 2.3.3)。 |
NDEF Record的RTD(Record Type Definition)類型值,參考NDEF標(biāo)簽技術(shù)規(guī)范《NFCForum-TS-NDEF_1.0》的定義細(xì)節(jié)。
系統(tǒng)能力: SystemCapability.Communication.NFC.Tag
名稱 | 值 | 說明 |
---|---|---|
RTD_TEXT9+ | [0x54] | 文本類型的NDEF Record。 |
RTD_URI9+ | [0x55] | URI類型的NDEF Record。 |
NFC Forum標(biāo)準(zhǔn)里面Tag類型的定義。
系統(tǒng)能力: SystemCapability.Communication.NFC.Tag
名稱 | 值 | 說明 |
---|---|---|
NFC_FORUM_TYPE_1 | 1 | NFC論壇類型1。 |
NFC_FORUM_TYPE_2 | 2 | NFC論壇類型2。 |
NFC_FORUM_TYPE_3 | 3 | NFC論壇類型3。 |
NFC_FORUM_TYPE_4 | 4 | NFC論壇類型4。 |
MIFARE_CLASSIC | 101 | MIFARE Classic類型。 |
MIFARE Classic標(biāo)簽類型的定義。
系統(tǒng)能力: SystemCapability.Communication.NFC.Tag
名稱 | 值 | 說明 |
---|---|---|
TYPE_UNKNOWN | 0 | 未知的MIFARE類型。 |
TYPE_CLASSIC | 1 | MIFARE Classic類型。 |
TYPE_PLUS | 2 | MIFARE Plus類型。 |
TYPE_PRO | 3 | MIFARE Pro類型。 |
MIFARE Classic標(biāo)簽存儲大小的定義。
系統(tǒng)能力: SystemCapability.Communication.NFC.Tag
名稱 | 值 | 說明 |
---|---|---|
MC_SIZE_MINI | 320 | 每個(gè)標(biāo)簽5個(gè)扇區(qū),每個(gè)扇區(qū)4個(gè)塊。 |
MC_SIZE_1K | 1024 | 每個(gè)標(biāo)簽16個(gè)扇區(qū),每個(gè)扇區(qū)4個(gè)塊。 |
MC_SIZE_2K | 2048 | 每個(gè)標(biāo)簽32個(gè)扇區(qū),每個(gè)扇區(qū)4個(gè)塊。 |
MC_SIZE_4K | 4096 | 每個(gè)標(biāo)簽40個(gè)扇區(qū),每個(gè)扇區(qū)4個(gè)塊。 |
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: