• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.nfc.tag (Standard NFC Tags)
2
3The **nfcTag** module provides APIs for managing Near-Field Communication (NFC) tags.
4
5> **NOTE**
6>
7> The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
8
9## **Declaration**
10
11Before developing applications related to tag read and write, you must declare NFC-related attributes in the attribute configuration file of the applications. For example, declare the following attributes in the **module.json5** file:
12```js
13{
14    "module": {
15        // Attributes to declare.
16
17        "abilities": [
18            {
19                "skills": [
20                    {
21                        "actions": [
22                            // Actions to declare.
23
24                            // Add the nfc tag action.
25                            "ohos.nfc.tag.action.TAG_FOUND"
26                        ]
27                    }
28                ],
29                "metadata": [
30                    {
31                        "name": "tag-tech",
32                        "value": "NfcA"
33                    },
34                    {
35                        "name": "tag-tech",
36                        "value": "IsoDep"
37                    },
38                    // Add other technologies,
39                    // such as NfcB, NfcF, NfcV, Ndef, MifareClassic, MifareUL, and NdefFormatable.
40                ]
41            }
42        ],
43        "requestPermissions": [
44            "name": "ohos.permission.NFC_TAG",
45            "reason": "tag",
46        ]
47    }
48}
49```
50> **CAUTION**<br>
51>
52> - The **actions** field is mandatory. It must be **ohos.nfc.tag.action.TAG_FOUND** and cannot be changed.
53> - The **name** field under **metadata** is mandatory. It must be **tag-tech** and cannot be changed.
54> - The **value** field under **metadata** is mandatory. It can be **NfcA**, **NfcB**, **NfcF**, **NfcV**, **IsoDep**, **Ndef**, **MifareClassic**, **MifareUL**, **NdefFormatable** or any of their combinations. Incorrect settings of this field will cause a parsing failure.
55> - The **name** field under **requestPermissions** is mandatory. It must be **ohos.permission.NFC_TAG** and cannot be changed.
56
57## **Modules to Import**
58
59```js
60import tag from '@ohos.nfc.tag';
61```
62
63## **tag.TagInfo**
64
65Before a card with tags is read or written, **TagInfo** must be obtained to determine the tag technologies supported by the card. In this way, the application can invoke the correct API to communicate with the card.
66```js
67import tag from '@ohos.nfc.tag';
68
69onCreate(want, launchParam) {
70    // Add other code here.
71
72    // want is initialized by the NFC service and contains tagInfo.
73    var tagInfo;
74    try {
75        tagInfo = tag.getTagInfo(want);
76    } catch (error) {
77        console.log("tag.getTagInfo caught error: " + error);
78    }
79    if (tagInfo == null || tagInfo == undefined) {
80        console.log("no TagInfo to be created, ignore it.");
81        return;
82    }
83
84    // get the supported technologies for this found tag.
85    var isNfcATag =  false;
86    var isIsoDepTag =  false;
87    for (var i = 0; i < tagInfo.technology.length; i++) {
88        if (tagInfo.technology[i] == tag.NFC_A) {
89            isNfcATag = true;
90        }
91
92        if (tagInfo.technology[i] == tag.ISO_DEP) {
93            isIsoDepTag = true;
94        }
95        // Also check for technology tag.NFC_B, NFC_F, NFC_V, ISO_DEP, NDEF, MIFARE_CLASSIC, MIFARE_ULTRALIGHT, and NDEF_FORMATABLE.
96    }
97
98    // use NfcA APIs to access the found tag.
99    if (isNfcATag) {
100        var nfcA;
101        try {
102            nfcA = tag.getNfcATag(tagInfo);
103        } catch (error) {
104            console.log("tag.getNfcATag caught error: " + error);
105        }
106        // Other code to read or write this tag.
107    }
108
109    // use getIsoDep APIs to access the found tag.
110    if (isIsoDepTag) {
111        var isoDep;
112        try {
113            isoDep = tag.getIsoDep(tagInfo);
114        } catch (error) {
115            console.log("tag.getIsoDep caught error: " + error);
116        }
117        // Other code to read or write this tag.
118    }
119
120    // Use the same code to handle "NfcA/NfcB/NfcF/NfcV/Ndef/MifareClassic/MifareUL/NdefFormatable".
121}
122```
123
124## tag.getNfcATag
125
126getNfcATag(tagInfo: [TagInfo](#taginfo)): [NfcATag](js-apis-nfctech.md#nfcatag)
127
128Obtains an **NfcATag** object, which allows access to the tags that use the NFC-A technology.
129
130> **NOTE**
131> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [tag.getNfcA](#taggetnfca9).
132
133**System capability**: SystemCapability.Communication.NFC.Tag
134
135**Parameters**
136
137| Name      | Type                       | Mandatory  | Description                                      |
138| --------- | ------------------------- | ---- | ---------------------------------------- |
139| taginfo      | [TagInfo](#taginfo)                   | Yes| Tag information including the technology type and related parameters, which are obtained from **tag.getTagInfo(want: Want)**.
140
141**Return value**
142
143| **Type**                               | **Description**       |
144| ------------------------------------- | ------------- |
145| [NfcATag](js-apis-nfctech.md#nfcatag) | **NfcATag** object obtained.|
146
147## tag.getNfcA<sup>9+</sup>
148
149getNfcA(tagInfo: [TagInfo](#taginfo)): [NfcATag](js-apis-nfctech.md#nfcatag)
150
151Obtains an **NfcATag** object, which allows access to the tags that use the NFC-A technology.
152
153**System capability**: SystemCapability.Communication.NFC.Tag
154
155**Parameters**
156
157| Name      | Type                       | Mandatory  | Description                                      |
158| --------- | ------------------------- | ---- | ---------------------------------------- |
159| taginfo      | [TagInfo](#taginfo)                   | Yes| Tag information including the technology type and related parameters, which are obtained from **tag.getTagInfo(want: Want)**.
160
161**Return value**
162
163| **Type**                               | **Description**       |
164| ------------------------------------- | ------------- |
165| [NfcATag](js-apis-nfctech.md#nfcatag) | **NfcATag** object obtained.|
166
167**Error codes**
168
169For details about the error codes, see [NFC Error Codes](../errorcodes/errorcode-nfc.md).
170
171| ID  | Error Message                                    |
172| ------- | ---------------------------------------- |
173| 3100201 | Tag running state is abnormal in service. |
174
175## tag.getNfcBTag
176
177getNfcBTag(tagInfo: [TagInfo](#taginfo)): [NfcBTag](js-apis-nfctech.md#nfcbtag)
178
179Obtains an **NfcBTag** object, which allows access to the tags that use the NFC-B technology.
180
181> **NOTE**
182> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [tag.getNfcB](#taggetnfcb9).
183
184**System capability**: SystemCapability.Communication.NFC.Tag
185
186**Parameters**
187
188| Name      | Type                       | Mandatory  | Description                                      |
189| --------- | ------------------------- | ---- | ---------------------------------------- |
190| taginfo      | [TagInfo](#taginfo)                   | Yes| Tag information including the technology type and related parameters, which are obtained from **tag.getTagInfo(want: Want)**.
191
192**Return value**
193
194| **Type**                               | **Description**       |
195| ------------------------------------- | ------------- |
196| [NfcBTag](js-apis-nfctech.md#nfcbtag) | **NfcBTag** object obtained.|
197
198## tag.getNfcB<sup>9+</sup>
199
200getNfcB(tagInfo: [TagInfo](#taginfo)): [NfcBTag](js-apis-nfctech.md#nfcbtag)
201
202Obtains an **NfcBTag** object, which allows access to the tags that use the NFC-B technology.
203
204**System capability**: SystemCapability.Communication.NFC.Tag
205
206**Parameters**
207
208| Name      | Type                       | Mandatory  | Description                                      |
209| --------- | ------------------------- | ---- | ---------------------------------------- |
210| taginfo      | [TagInfo](#taginfo)                   | Yes| Tag information including the technology type and related parameters, which are obtained from **tag.getTagInfo(want: Want)**.
211
212**Return value**
213
214| **Type**                               | **Description**       |
215| ------------------------------------- | ------------- |
216| [NfcBTag](js-apis-nfctech.md#nfcbtag) | **NfcBTag** object obtained.|
217
218**Error codes**
219
220For details about the error codes, see [NFC Error Codes](../errorcodes/errorcode-nfc.md).
221
222| ID  | Error Message                                    |
223| ------- | ---------------------------------------- |
224| 3100201 | Tag running state is abnormal in service. |
225
226## tag.getNfcFTag
227
228getNfcFTag(tagInfo: [TagInfo](#taginfo)): [NfcFTag](js-apis-nfctech.md#nfcftag)
229
230Obtains an **NfcFTag** object, which allows access to the tags that use the NFC-F technology.
231
232> **NOTE**
233> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [tag.getNfcF](#taggetnfcf9).
234
235**System capability**: SystemCapability.Communication.NFC.Tag
236
237**Parameters**
238
239| Name      | Type                       | Mandatory  | Description                                      |
240| --------- | ------------------------- | ---- | ---------------------------------------- |
241| taginfo      | [TagInfo](#taginfo)                   | Yes| Tag information including the technology type and related parameters, which are obtained from **tag.getTagInfo(want: Want)**.
242
243**Return value**
244
245| **Type**                               | **Description**       |
246| ------------------------------------- | ------------- |
247| [NfcFTag](js-apis-nfctech.md#nfcftag) | **NfcFTag** object obtained.|
248
249## tag.getNfcF<sup>9+</sup>
250
251getNfcF(tagInfo: [TagInfo](#taginfo)): [NfcFTag](js-apis-nfctech.md#nfcftag)
252
253Obtains an **NfcFTag** object, which allows access to the tags that use the NFC-F technology.
254
255**System capability**: SystemCapability.Communication.NFC.Tag
256
257**Parameters**
258
259| Name      | Type                       | Mandatory  | Description                                      |
260| --------- | ------------------------- | ---- | ---------------------------------------- |
261| taginfo      | [TagInfo](#taginfo)                   | Yes| Tag information including the technology type and related parameters, which are obtained from **tag.getTagInfo(want: Want)**.
262
263**Return value**
264
265| **Type**                               | **Description**       |
266| ------------------------------------- | ------------- |
267| [NfcFTag](js-apis-nfctech.md#nfcftag) | **NfcFTag** object obtained.|
268
269**Error codes**
270
271For details about the error codes, see [NFC Error Codes](../errorcodes/errorcode-nfc.md).
272
273| ID  | Error Message                                    |
274| ------- | ---------------------------------------- |
275| 3100201 | Tag running state is abnormal in service. |
276
277## tag.getNfcVTag
278
279getNfcVTag(tagInfo: [TagInfo](#taginfo)): [NfcVTag](js-apis-nfctech.md#nfcvtag)
280
281Obtains an **NfcVTag** object, which allows access to the tags that use the NFC-V technology.
282
283> **NOTE**
284> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [tag.getNfcV](#taggetnfcv9).
285
286**System capability**: SystemCapability.Communication.NFC.Tag
287
288**Parameters**
289
290| Name      | Type                       | Mandatory  | Description                                      |
291| --------- | ------------------------- | ---- | ---------------------------------------- |
292| taginfo      | [TagInfo](#taginfo)                   | Yes| Tag information including the technology type and related parameters, which are obtained from **tag.getTagInfo(want: Want)**.
293
294**Return value**
295
296| **Type**                               | **Description**       |
297| ------------------------------------- | ------------- |
298| [NfcVTag](js-apis-nfctech.md#nfcvtag) | **NfcVTag** object obtained.|
299
300## tag.getNfcV<sup>9+</sup>
301
302getNfcV(tagInfo: [TagInfo](#taginfo)): [NfcVTag](js-apis-nfctech.md#nfcvtag)
303
304Obtains an **NfcVTag** object, which allows access to the tags that use the NFC-V technology.
305
306**System capability**: SystemCapability.Communication.NFC.Tag
307
308**Parameters**
309
310| Name      | Type                       | Mandatory  | Description                                      |
311| --------- | ------------------------- | ---- | ---------------------------------------- |
312| taginfo      | [TagInfo](#taginfo)                   | Yes| Tag information including the technology type and related parameters, which are obtained from **tag.getTagInfo(want: Want)**.
313
314**Return value**
315
316| **Type**                               | **Description**       |
317| ------------------------------------- | ------------- |
318| [NfcVTag](js-apis-nfctech.md#nfcvtag) | **NfcVTag** object obtained.|
319
320**Error codes**
321
322For details about the error codes, see [NFC Error Codes](../errorcodes/errorcode-nfc.md).
323
324| ID  | Error Message                                    |
325| ------- | ---------------------------------------- |
326| 3100201 | Tag running state is abnormal in service. |
327
328## tag.getIsoDep<sup>9+</sup>
329
330getIsoDep(tagInfo: [TagInfo](#taginfo)): [IsoDepTag](js-apis-nfctech.md#isoDepTag9 )
331
332Obtains an **IsoDepTag** object, which allows access to the tags that use the ISO-DEP technology.
333
334**System capability**: SystemCapability.Communication.NFC.Tag
335
336**Parameters**
337
338| Name    | Type                 | Mandatory  | Description                                      |
339| ------- | ------------------- | ---- | ---------------------------------------- |
340| taginfo | [TagInfo](#taginfo) | Yes   | Tag information including the technology type and related parameters, which are obtained from **tag.getTagInfo(want: Want)**.|
341
342**Return value**
343
344| **Type**                                  | **Description**                             |
345| ---------------------------------------- | ----------------------------------- |
346| [IsoDepTag](js-apis-nfctech.md#isodeptag9) | **IsoDepTag** object obtained.|
347
348**Error codes**
349
350For details about the error codes, see [NFC Error Codes](../errorcodes/errorcode-nfc.md).
351
352| ID  | Error Message                                    |
353| ------- | ---------------------------------------- |
354| 3100201 | Tag running state is abnormal in service. |
355
356## tag.getNdef<sup>9+</sup>
357
358getNdef(tagInfo: [TagInfo](#taginfo)): [NdefTag](js-apis-nfctech.md#ndeftag9)
359
360Obtains an **NdefTag** object, which allows access to the tags in the NFC Data Exchange Format (NDEF).
361
362**System capability**: SystemCapability.Communication.NFC.Tag
363
364**Parameters**
365
366| Name    | Type                 | Mandatory  | Description                                      |
367| ------- | ------------------- | ---- | ---------------------------------------- |
368| taginfo | [TagInfo](#taginfo) | Yes   | Tag information including the technology type and related parameters, which are obtained from **tag.getTagInfo(want: Want)**.|
369
370**Return value**
371
372| **Type**                                | **Description**                         |
373| -------------------------------------- | ------------------------------- |
374| [NdefTag](js-apis-nfctech.md#ndeftag9) | **NdefTag** object obtained.|
375
376**Error codes**
377
378For details about the error codes, see [NFC Error Codes](../errorcodes/errorcode-nfc.md).
379
380| ID  | Error Message                                    |
381| ------- | ---------------------------------------- |
382| 3100201 | Tag running state is abnormal in service. |
383
384## tag.getMifareClassic<sup>9+</sup>
385
386getMifareClassic(tagInfo: [TagInfo](#taginfo)): [MifareClassicTag](js-apis-nfctech.md#mifareclassictag-9)
387
388Obtains a **MifareClassicTag** object, which allows access to the tags that use MIFARE Classic.
389
390**System capability**: SystemCapability.Communication.NFC.Tag
391
392**Parameters**
393
394| Name    | Type                 | Mandatory  | Description                                      |
395| ------- | ------------------- | ---- | ---------------------------------------- |
396| taginfo | [TagInfo](#taginfo) | Yes   | Tag information including the technology type and related parameters, which are obtained from **tag.getTagInfo(want: Want)**.|
397
398**Return value**
399
400| **Type**                                  | **Description**                                  |
401| ---------------------------------------- | ---------------------------------------- |
402| [MifareClassicTag](js-apis-nfctech.md#mifareclassictag-9) | **MifareClassicTag** object obtained.|
403
404**Error codes**
405
406For details about the error codes, see [NFC Error Codes](../errorcodes/errorcode-nfc.md).
407
408| ID  | Error Message                                    |
409| ------- | ---------------------------------------- |
410| 3100201 | Tag running state is abnormal in service. |
411
412## tag.getMifareUltralight<sup>9+</sup>
413
414getMifareUltralight(tagInfo: [TagInfo](#taginfo)): [MifareUltralightTag](js-apis-nfctech.md#mifareultralighttag9)
415
416Obtains a **MifareUltralightTag** object, which allows access to the tags that use MIFARE Ultralight.
417
418**System capability**: SystemCapability.Communication.NFC.Tag
419
420**Parameters**
421| Name    | Type                 | Mandatory  | Description                                      |
422| ------- | ------------------- | ---- | ---------------------------------------- |
423| taginfo | [TagInfo](#taginfo) | Yes   | Tag information including the technology type and related parameters, which are obtained from **tag.getTagInfo(want: Want)**.|
424
425**Return value**
426
427| **Type**                                  | **Description**                                  |
428| ---------------------------------------- | ---------------------------------------- |
429| [MifareUltralightTag](js-apis-nfctech.md#mifareultralighttag9) | **MifareUltralightTag** object obtained.|
430
431**Error codes**
432
433For details about the error codes, see [NFC Error Codes](../errorcodes/errorcode-nfc.md).
434
435| ID  | Error Message                                    |
436| ------- | ---------------------------------------- |
437| 3100201 | Tag running state is abnormal in service. |
438
439## tag.getNdefFormatable<sup>9+</sup>
440
441getNdefFormatable(tagInfo: [TagInfo](#taginfo)): [NdefFormatableTag](js-apis-nfctech.md#ndefformatabletag9)
442
443Obtains an **NdefFormatableTag** object, which allows access to the tags that are NDEF formattable.
444
445**System capability**: SystemCapability.Communication.NFC.Tag
446
447**Return value**
448
449| **Type**                                  | **Description**                                  |
450| ---------------------------------------- | ---------------------------------------- |
451| [NdefFormatableTag](js-apis-nfctech.md#ndefformatabletag) | **NdefFormatableTag** object obtained.|
452
453**Error codes**
454
455For details about the error codes, see [NFC Error Codes](../errorcodes/errorcode-nfc.md).
456
457| ID  | Error Message                                    |
458| ------- | ---------------------------------------- |
459| 3100201 | Tag running state is abnormal in service. |
460
461## tag.getTagInfo<sup>9+</sup>
462
463getTagInfo(want: [Want](js-apis-app-ability-want.md#Want)): [TagInfo](#taginfo)
464
465Obtains **TagInfo** from **Want**, which is initialized by the NFC service and contains the attributes required by **TagInfo**.
466
467**System capability**: SystemCapability.Communication.NFC.Tag
468
469**Parameters**
470
471| Name | Type                                      | Mandatory  | Description                               |
472| ---- | ---------------------------------------- | ---- | --------------------------------- |
473| want | [Want](js-apis-app-ability-want.md#Want) | Yes   | Data obtained from the parameters of the **onCreate** entry function when an ability is dispatched.|
474
475**Return value**
476
477| **Type**             | **Description**                     |
478| ------------------- | --------------------------- |
479| [TagInfo](#taginfo) | **TagInfo** object obtained.|
480
481
482## tag.ndef.makeUriRecord<sup>9+</sup>
483
484makeUriRecord(uri: string): [NdefRecord](#ndefrecord9);
485
486Creates an NDEF record based on the specified URI.
487
488**System capability**: SystemCapability.Communication.NFC.Tag
489
490**Parameters**
491
492| Name | Type    | Mandatory  | Description                    |
493| ---- | ------ | ---- | ---------------------- |
494| uri  | string | Yes   | Data to write to the NDEF record.|
495
496**Return value**
497
498| **Type**                    | **Description**                                  |
499| -------------------------- | ---------------------------------------- |
500| [NdefRecord](#ndefrecord9) | NDEF record created. For details, see *NFCForum-TS-NDEF_1.0*.|
501
502**Example**
503
504```js
505import tag from '@ohos.nfc.tag';
506
507try {
508    let uri = "https://gitee.com/openharmony"; // change it to be correct.
509    let ndefRecord = tag.ndef.makeUriRecord(uri);
510    if (ndefRecord != undefined) {
511        console.log("ndefMessage makeUriRecord rtdType: " + ndefRecord.rtdType);
512        console.log("ndefMessage makeUriRecord payload: " + ndefRecord.payload);
513    } else {
514        console.log("ndefMessage makeUriRecord ndefRecord: " + ndefRecord);
515    }
516} catch (busiError) {
517    console.log("ndefMessage makeUriRecord caught busiError: " + busiError);
518}
519```
520
521## tag.ndef.makeTextRecord<sup>9+</sup>
522
523makeTextRecord(text: string, locale: string): [NdefRecord](#ndefrecord9);
524
525Creates an NDEF record based on the specified text data and encoding type.
526
527**System capability**: SystemCapability.Communication.NFC.Tag
528
529**Parameters**
530
531| Name   | Type    | Mandatory  | Description                      |
532| ------ | ------ | ---- | ------------------------ |
533| text   | string | Yes   | Text to write to the NDEF record.|
534| locale | string | Yes   | Encoding mode of the text.            |
535
536**Return value**
537
538| **Type**                    | **Description**                                  |
539| -------------------------- | ---------------------------------------- |
540| [NdefRecord](#ndefrecord9) | NDEF record created. For details, see *NFCForum-TS-NDEF_1.0*.|
541
542**Example**
543
544```js
545import tag from '@ohos.nfc.tag';
546
547try {
548    let text = "Hello World";   // change it to be correct.
549    let locale = "en"; // change it to be correct.
550    let ndefRecord = tag.ndef.makeTextRecord(text, locale);
551    if (ndefRecord != undefined) {
552        console.log("ndefMessage makeTextRecord rtdType: " + ndefRecord.rtdType);
553        console.log("ndefMessage makeTextRecord payload: " + ndefRecord.payload);
554    } else {
555        console.log("ndefMessage makeTextRecord ndefRecord: " + ndefRecord);
556    }
557} catch (busiError) {
558    console.log("ndefMessage makeTextRecord caught busiError: " + busiError);
559}
560```
561
562
563## tag.ndef.makeMimeRecord<sup>9+</sup>
564
565makeMimeRecord(mimeType: string, mimeData: number[]): [NdefRecord](#ndefrecord9);
566
567Creates an NDEF record based on the specified MIME data and type.
568
569**System capability**: SystemCapability.Communication.NFC.Tag
570
571**Parameters**
572
573| Name     | Type      | Mandatory  | Description                                      |
574| -------- | -------- | ---- | ---------------------------------------- |
575| mimeType | string   | Yes   | MIME type that complies with RFC rules, for example, **text/plain** or **image/jpeg**.|
576| mimeData | number[] | Yes   | MIME data, which consists of hexadecimal numbers ranging from **0x00** to **0xFF**.   |
577
578**Return value**
579
580| **Type**                    | **Description**                                  |
581| -------------------------- | ---------------------------------------- |
582| [NdefRecord](#ndefrecord9) | NDEF record created. For details, see *NFCForum-TS-NDEF_1.0*.|
583
584**Example**
585
586```js
587import tag from '@ohos.nfc.tag';
588
589try {
590    let mimeType = "text/plain";   // change it to be correct.
591    let mimeData = [0x01, 0x02, 0x03, 0x04]; // change it to be correct.
592    let ndefRecord = tag.ndef.makeMimeRecord(mimeType, mimeData);
593    if (ndefRecord != undefined) {
594        console.log("ndefMessage makeMimeRecord rtdType: " + ndefRecord.rtdType);
595        console.log("ndefMessage makeMimeRecord payload: " + ndefRecord.payload);
596    } else {
597        console.log("ndefMessage makeMimeRecord ndefRecord: " + ndefRecord);
598    }
599} catch (busiError) {
600    console.log("ndefMessage makeMimeRecord caught busiError: " + busiError);
601}
602```
603## tag.ndef.makeExternalRecord<sup>9+</sup>
604
605makeExternalRecord(domainName: string, type: string, externalData: number[]): [NdefRecord](#ndefrecord9);
606
607Creates an NDEF record based on application-specific data.
608
609**System capability**: SystemCapability.Communication.NFC.Tag
610
611**Parameters**
612
613| Name         | Type      | Mandatory  | Description                                 |
614| ------------ | -------- | ---- | ----------------------------------- |
615| domainName   | string   | Yes   | Bundle name of the application or domain name of the organization that releases the applications.            |
616| type         | string   | Yes   | Type of the application data.                         |
617| externalData | number[] | Yes   | Application data, which consists of hexadecimal numbers ranging from **0x00** to **0xFF**.|
618
619**Return value**
620
621| **Type**                    | **Description**                                  |
622| -------------------------- | ---------------------------------------- |
623| [NdefRecord](#ndefrecord9) | NDEF record created. For details, see *NFCForum-TS-NDEF_1.0*.|
624
625**Example**
626
627```js
628import tag from '@ohos.nfc.tag';
629
630try {
631    let domainName = "ohos.nfc.application"; // change it to be correct.
632    let type = "test"; // change it to be correct.
633    let externalData = [0x01, 0x02, 0x03, 0x04]; // change it to be correct.
634    let ndefRecord = tag.ndef.makeExternalRecord(domainName, type, externalData);
635    if (ndefRecord != undefined) {
636        console.log("ndefMessage makeExternalRecord rtdType: " + ndefRecord.rtdType);
637        console.log("ndefMessage makeExternalRecord payload: " + ndefRecord.payload);
638    } else {
639        console.log("ndefMessage makeExternalRecord ndefRecord: " + ndefRecord);
640    }
641} catch (busiError) {
642    console.log("ndefMessage makeExternalRecord caught busiError: " + busiError);
643}
644```
645
646## tag.ndef.messageToBytes<sup>9+</sup>
647
648messageToBytes(ndefMessage: [NdefMessage](js-apis-nfctech.md#ndefmessage9)): number[];
649
650Converts an NDEF message to bytes.
651
652**System capability**: SystemCapability.Communication.NFC.Tag
653
654**Parameters**
655
656| Name        | Type                                      | Mandatory  | Description         |
657| ----------- | ---------------------------------------- | ---- | ----------- |
658| ndefMessage | [NdefMessage](js-apis-nfctech.md#ndefmessage9) | Yes   | NDEF message to convert.|
659
660**Return value**
661
662| **Type**  | **Description**                                  |
663| -------- | ---------------------------------------- |
664| number[] | NDEF message in bytes, which consists of hexadecimal numbers ranging from **0x00** to **0xFF**.|
665
666**Example**
667
668```js
669import tag from '@ohos.nfc.tag';
670
671let rawData = [0xD1, 0x01, 0x03, 0x54, 0x4E, 0x46, 0x43]; // MUST can be parsed as NDEF Record.
672let ndefMessage;
673try {
674    ndefMessage = tag.ndef.createNdefMessage(rawData);
675    console.log("ndef createNdefMessage, ndefMessage: " + ndefMessage);
676} catch (busiError) {
677    console.log("ndef createNdefMessage busiError: " + busiError);
678}
679
680try {
681    let rawData2 = tag.ndef.messageToBytes(ndefMessage);
682    console.log("ndefMessage messageToBytes rawData2: " + rawData2);
683} catch (busiError) {
684    console.log("ndefMessage messageToBytes caught busiError: " + busiError);
685}
686```
687## tag.ndef.createNdefMessage<sup>9+</sup>
688
689createNdefMessage(data: number[]): [NdefMessage](js-apis-nfctech.md#ndefmessage9)
690
691Creates an NDEF message from raw byte data. The data must comply with the NDEF record format. Otherwise, the NDE record list contained in the **NdefMessage** object will be empty.
692
693**System capability**: SystemCapability.Communication.NFC.Tag
694
695**Parameters**
696
697| **Name**| **Type**  | **Mandatory**| **Description**                                  |
698| ------- | -------- | ------ | ---------------------------------------- |
699| data    | number[] | Yes     | Raw byte data, which consists of hexadecimal numbers ranging from **0x00** to **0xFF**. The data must comply with the NDEF record format.|
700
701**Return value**
702
703| **Type**                                  | **Description**                                  |
704| ---------------------------------------- | ---------------------------------------- |
705| [NdefMessage](js-apis-nfctech.md#ndefmessage9) | NDEF message created. For details, see *NFCForum-TS-NDEF_1.0*.|
706
707**Example**
708```js
709import tag from '@ohos.nfc.tag';
710
711let rawData = [0xD1, 0x01, 0x03, 0x54, 0x4E, 0x46, 0x43];  // MUST can be parsed as NDEF Record.
712let ndefMessage;
713try {
714    ndefMessage = tag.ndef.createNdefMessage(rawData);
715    console.log("ndef createNdefMessage, ndefMessage: " + ndefMessage);
716} catch (busiError) {
717    console.log("ndef createNdefMessage busiError: " + busiError);
718}
719```
720
721## tag.ndef.createNdefMessage<sup>9+</sup>
722
723createNdefMessage(ndefRecords: NdefRecord[]): [NdefMessage](js-apis-nfctech.md#ndefmessage9)
724
725Creates an NDEF message from the NDEF records list.
726
727**System capability**: SystemCapability.Communication.NFC.Tag
728
729**Parameters**
730
731| **Name**    | **Type**                                  | **Mandatory**| **Description**                                  |
732| ----------- | ---------------------------------------- | ------ | ---------------------------------------- |
733| ndefRecords | [NdefRecord](js-apis-nfcTag.md#ndefrecord9)[] | Yes     | NDEF record list used to create the NDEF message. For details, see *NFCForum-TS-NDEF_1.0*.|
734
735**Return value**
736
737| **Type**                                  | **Description**                                  |
738| ---------------------------------------- | ---------------------------------------- |
739| [NdefMessage](js-apis-nfctech.md#ndefmessage9) | NDEF message created. For details, see *NFCForum-TS-NDEF_1.0*.|
740
741**Example**
742
743```js
744import tag from '@ohos.nfc.tag';
745
746let uriRecord = tag.ndef.makeUriRecord("https://gitee.com/openharmony");
747let textRecord = tag.ndef.makeTextRecord("Hello World", "en");
748let ndefRecords = [uriRecord, textRecord];
749let ndefMessage;
750try {
751    ndefMessage = tag.ndef.createNdefMessage(ndefRecords);
752    console.log("ndef createNdefMessage ndefMessage: " + ndefMessage);
753} catch (busiError) {
754    console.log("ndef createNdefMessage busiError: " + busiError);
755}
756```
757
758## TagInfo
759
760Defines the **TagInfo** object, which provides information about the tag technologies supported by a card.
761
762**System capability**: SystemCapability.Communication.NFC.Tag
763
764**Required permissions**: ohos.permission.NFC_TAG
765
766| **Name**                       | **Type**                                  | **Readable**| **Writable**| **Description**                                  |
767| ----------------------------- | ---------------------------------------- | ------ | ------ | ---------------------------------------- |
768| uid<sup>9+</sup>              | number[]                                 | Yes     | No     | Tag unique identifier (UID), which consists of hexadecimal numbers ranging from **0x00** to **0xFF**.   |
769| technology<sup>9+</sup>       | number[]                                 | Yes     | No     | Supported technologies. Each number is a constant indicating the supported technology.         |
770| supportedProfiles             | number[]                                 | Yes     | No     | Supported profiles. This parameter is not supported since API version 9. Use [tag.TagInfo#technology](#tagtaginfo) instead.|
771| extrasData<sup>9+</sup>       | [PacMap](js-apis-inner-ability-dataAbilityHelper.md#pacmap)[] | Yes     | No     | Extended attribute value of the tag technology.<br>**System API**: This is a system API.   |
772| tagRfDiscId<sup>9+</sup>      | number                                   | Yes     | No     | ID allocated when the tag is discovered.<br>**System API**: This is a system API.     |
773| remoteTagService<sup>9+</sup> | [rpc.RemoteObject](js-apis-rpc.md#remoteobject) | Yes     | No     | Remote object of the NFC service process used for interface communication between the client and the service.<br>**System API**: This is a system API.|
774## NdefRecord<sup>9+</sup>
775Defines an NDEF record. For details, see *NFCForum-TS-NDEF_1.0*.
776
777**System capability**: SystemCapability.Communication.NFC.Tag
778
779| **Name** | **Type**  | **Readable**| **Writable**| **Description**                                  |
780| ------- | -------- | ------ | ------ | ---------------------------------------- |
781| tnf     | number   | Yes     | No     | Type name field (TNF) of the NDEF record.       |
782| rtdType | number[] | Yes     | No     | Record type definition (RTD) of the NDEF record. It consists of hexadecimal numbers ranging from **0x00** to **0xFF**.|
783| id      | number[] | Yes     | No     | NDEF record ID, which consists of hexadecimal numbers ranging from **0x00** to **0xFF**.|
784| payload | number[] | Yes     | No     | NDEF payload, which consists of hexadecimal numbers ranging from **0x00** to **0xFF**.|
785
786## Technology Type Definition
787Enumerates the tag technology types.
788
789**System capability**: SystemCapability.Communication.NFC.Tag
790
791| **Name**                      | **Value**| **Description**                  |
792| ---------------------------- | ----- | ------------------------ |
793| NFC_A                        | 1     | NFC-A (ISO 14443-3A). |
794| NFC_B  | 2 | NFC-B (ISO 14443-3B).|
795| ISO_DEP                      | 3     | ISO-DEP (ISO 14443-4).|
796| NFC_F                        | 4     | NFC-F (JIS 6319-4).   |
797| NFC_V                        | 5     | NFC-V (ISO 15693).    |
798| NDEF                         | 6     | NDEF.                 |
799| NDEF_FORMATABLE<sup>9+</sup> | 7     | NDEF formattable.           |
800| MIFARE_CLASSIC               | 8     | MIFARE Classic.       |
801| MIFARE_ULTRALIGHT            | 9     | MIFARE Ultralight.     |
802
803## TnfType<sup>9+</sup>
804Enumerates the TNF types. For details, see *NFCForum-TS-NDEF_1.0*.
805
806**System capability**: SystemCapability.Communication.NFC.Tag
807
808| **Name**          | **Value**| **Description**                                  |
809| ---------------- | ----- | ---------------------------------------- |
810| TNF_EMPTY        | 0x0   | Empty.                                  |
811| TNF_WELL_KNOWN   | 0x1   | NFC Forum Well Known Type [NFC RTD].    |
812| TNF_MEDIA        | 0x2   | Media-type as defined in RFC 2046 [RFC 2046].|
813| TNF_ABSOLUTE_URI | 0x3   | Absolute URI as defined in RFC 3986 [RFC 3986].|
814| TNF_EXT_APP      | 0x4   | NFC Forum external type [NFC RTD].      |
815| TNF_UNKNOWN      | 0x5   | Unknown.                                |
816| TNF_UNCHANGED    | 0x6   | Unchanged (see section 2.3.3 in *NFCForum-TS-NDEF_1.0*).          |
817
818## NDEF Record RTD
819Enumerates the NDEF record types. For details about the RTD, see *NFCForum-TS-NDEF_1.0*.
820
821**System capability**: SystemCapability.Communication.NFC.Tag
822
823| **Name**               | **Value** | **Description**            |
824| --------------------- | ------ | ------------------ |
825| RTD_TEXT<sup>9+</sup> | [0x54] | NDEF record of the text type. |
826| RTD_URI<sup>9+</sup>  | [0x55] | NDEF record of the URI type.|
827
828## NfcForumType<sup>9+</sup>
829Enumerates the NFC Forum tag types.
830
831**System capability**: SystemCapability.Communication.NFC.Tag
832
833| **Name**          | **Value**| **Description**           |
834| ---------------- | ----- | ----------------- |
835| NFC_FORUM_TYPE_1 | 1     | NFC Forum tag type 1.        |
836| NFC_FORUM_TYPE_2 | 2     | NFC Forum tag type 2.        |
837| NFC_FORUM_TYPE_3 | 3     | NFC Forum tag type 3.        |
838| NFC_FORUM_TYPE_4 | 4     | NFC Forum tag type 4.        |
839| MIFARE_CLASSIC   | 101   | MIFARE Classic.|
840
841## MifareClassicType<sup>9+</sup>
842Enumerates the MIFARE Classic tag types.
843
844**System capability**: SystemCapability.Communication.NFC.Tag
845
846| **Name**      | **Value**| **Description**           |
847| ------------ | ----- | ----------------- |
848| TYPE_UNKNOWN | 0     | Unknown type.     |
849| TYPE_CLASSIC | 1     | MIFARE Classic.|
850| TYPE_PLUS    | 2     | MIFARE Plus.   |
851| TYPE_PRO     | 3     | MIFARE Pro.    |
852
853## MifareClassicSize<sup>9+</sup>
854Enumerates the sizes of a MIFARE Classic tag.
855
856**System capability**: SystemCapability.Communication.NFC.Tag
857
858| **Name**      | **Value**| **Description**            |
859| ------------ | ----- | ------------------ |
860| MC_SIZE_MINI | 320   | Each tag has 5 sectors, and each sector has 4 blocks. |
861| MC_SIZE_1K   | 1024  | Each tag has 16 sectors, and each sector has 4 blocks.|
862| MC_SIZE_2K   | 2048  | Each tag has 32 sectors, and each sector has 4 blocks.|
863| MC_SIZE_4K   | 4096  | Each tag has 40 sectors, and each sector has 4 blocks.|
864
865## MifareUltralightType<sup>9+</sup>
866Enumerates the MIFARE Ultralight tag types.
867
868**System capability**: SystemCapability.Communication.NFC.Tag
869
870| **Name**           | **Value**| **Description**                |
871| ----------------- | ----- | ---------------------- |
872| TYPE_UNKNOWN      | 0     | Unknown type.        |
873| TYPE_ULTRALIGHT   | 1     | MIFARE Ultralight.  |
874| TYPE_ULTRALIGHT_C | 2     | MIFARE Ultralight C.|
875
876<!--no_check-->