1# @ohos.nfc.tag (Standard NFC Tags)
2
3The **tag** module provides APIs for operating and managing NFC tags. The following tag read modes are available:
4<br>Background mode: The device reads the tag by using NFC without starting any application, and then searches for applications based on the tag type. If only one application is matched, the card reading page of that application will be started. If multiple applications are matched, an application selector will be started, asking the user to select an application.
5<br>Foreground mode: A foreground application has priority to read the NFC tag discovered.
6
7> **NOTE**
8>
9> 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.
10
11## Declaring the NFC Tag Background Mode
12
13To enable NFC tags to be read without starting an application, declare NFC-related attributes in the **module.json5** file.
14```json
15{
16    "module": {
17        // Attributes to declare.
18
19        "abilities": [
20            {
21                "skills": [
22                    {
23                        "actions": [
24                            // Actions to declare.
25
26                            // Add the nfc tag action.
27                            "ohos.nfc.tag.action.TAG_FOUND"
28                        ],
29                        "uris": [
30                            {
31                                "type":"tag-tech/NfcA"
32                            },
33                            {
34                                "type":"tag-tech/IsoDep"
35                            }
36                            // Add other technology if neccessary,
37                            // such as NfcB, NfcF, NfcV, Ndef, MifareClassic, MifareUL, and NdefFormatable.
38                        ]
39                    }
40                ]
41            }
42        ],
43        "requestPermissions": [
44            {
45                "name": "ohos.permission.NFC_TAG",
46                "reason": "$string:app_name",
47            }
48        ]
49    }
50}
51```
52> **NOTE**<br>
53>
54>1. The **actions** field must contain **ohos.nfc.tag.action.TAG_FOUND** and cannot be changed.
55>2. The **type** field under **uris** must start with **tag-tech/**, followed by NfcA, NfcB, NfcF, NfcV, IsoDep, Ndef, MifareClassic, MifareUL, or NdefFormatable. If there are multiple types, enter them in different lines. Incorrect settings of this field will cause a parsing failure.
56>3. The **name** field under **requestPermissions** is mandatory. It must be **ohos.permission.NFC_TAG** and cannot be changed.
57>4. When calling the APIs and constants of this module, use **canIUse("SystemCapability.Communication.NFC.Tag")** to check whether the device supports NFC. If the device does not support NFC, the application stability may be affected. For details, see [NFC Tag Read/Write Development](../../connectivity/nfc/nfc-tag-access-guide.md).
58
59## **Modules to Import**
60
61```js
62import { tag } from '@kit.ConnectivityKit';
63```
64
65## **tag.TagInfo**
66
67Before a card with tags is read or written, **[TagInfo](#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.
68```js
69import { tag } from '@kit.ConnectivityKit';
70import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
71
72export default class EntryAbility extends UIAbility {
73    onCreate(want : Want, launchParam: AbilityConstant.LaunchParam) {
74        // add other code here...
75
76        // want is initialized by the NFC service and contains tagInfo.
77        let tagInfo : tag.TagInfo | null = null;
78        try {
79            tagInfo = tag.getTagInfo(want);
80        } catch (error) {
81            console.error("tag.getTagInfo catch error: " + error);
82        }
83        if (tagInfo == null || tagInfo == undefined) {
84            console.log("no TagInfo to be created, ignore it.");
85            return;
86        }
87
88        // get the supported technologies for this found tag.
89        let isNfcATag =  false;
90        let isIsoDepTag =  false;
91        for (let i = 0; i < tagInfo.technology.length; i++) {
92            if (tagInfo.technology[i] == tag.NFC_A) {
93                isNfcATag = true;
94            }
95            if (tagInfo.technology[i] == tag.ISO_DEP) {
96                isIsoDepTag = true;
97            }
98        // also check for technology: tag.NFC_B/NFC_F/NFC_V/NDEF/MIFARE_CLASSIC/MIFARE_ULTRALIGHT/NDEF_FORMATABLE
99        }
100
101        // use NfcA APIs to access the found tag.
102        if (isNfcATag) {
103            let nfcA : tag.NfcATag | null = null;
104            try {
105                nfcA = tag.getNfcA(tagInfo);
106            } catch (error) {
107                console.error("tag.getNfcA catch error: " + error);
108            }
109            // Other code to read or write this tag.
110        }
111
112        // use getIsoDep APIs to access the found tag.
113        if (isIsoDepTag) {
114            let isoDep : tag.IsoDepTag | null = null;
115            try {
116                isoDep = tag.getIsoDep(tagInfo);
117            } catch (error) {
118                console.error("tag.getIsoDep catch error: " + error);
119            }
120            // Other code to read or write this tag.
121        }
122        // use the same code to handle for "NfcA/NfcB/NfcF/NfcV/Ndef/MifareClassic/MifareUL/NdefFormatable".
123    }
124}
125```
126
127## tag.getNfcATag<sup>(deprecated)</sup>
128
129getNfcATag(tagInfo: [TagInfo](#taginfo)): [NfcATag](js-apis-nfctech.md#nfcatag)
130
131Obtains an **NfcATag** object, which allows access to the tags that use the NFC-A technology.
132
133> **NOTE**
134>
135> This API is supported since API version 7 and deprecated since API version 9. Use [tag.getNfcA](#taggetnfca9) instead.
136
137**System capability**: SystemCapability.Communication.NFC.Tag
138
139**Parameters**
140
141| Name | Type               | Mandatory| Description                                                         |
142| ------- | ------------------- | ---- | ------------------------------------------------------------- |
143| tagInfo | [TagInfo](#taginfo) | Yes  | Tag information, including the tag technology type and related parameters, obtained from [tag.getTagInfo(want: Want)](#taggettaginfo9).|
144
145**Return value**
146
147| **Type**                             | **Description**          |
148| ------------------------------------- | ------------------ |
149| [NfcATag](js-apis-nfctech.md#nfcatag) | **NfcATag** object obtained.|
150
151## tag.getNfcA<sup>9+</sup>
152
153getNfcA(tagInfo: [TagInfo](#taginfo)): [NfcATag](js-apis-nfctech.md#nfcatag)
154
155Obtains an **NfcATag** object, which allows access to the tags that use the NFC-A technology.
156
157**System capability**: SystemCapability.Communication.NFC.Tag
158
159**Atomic service API**: This API can be used in atomic services since API version 12.
160
161**Parameters**
162
163| Name | Type               | Mandatory| Description                                                         |
164| ------- | ------------------- | ---- | ------------------------------------------------------------- |
165| tagInfo | [TagInfo](#taginfo) | Yes  | Tag information, including the tag technology type and related parameters, obtained from [tag.getTagInfo(want: Want)](#taggettaginfo9).|
166
167**Return value**
168
169| **Type**                             | **Description**          |
170| ------------------------------------- | ------------------ |
171| [NfcATag](js-apis-nfctech.md#nfcatag) | **NfcATag** object obtained.|
172
173**Error codes**
174
175For details about the error codes, see [NFC Error Codes](errorcode-nfc.md).
176
177| ID| Error Message                                 |
178| -------- | ----------------------------------------- |
179| 401  | The parameter check failed. Possible causes: <br>1. Mandatory parameters are left unspecified.<br>2. Incorrect parameters types.<br>3. Parameter verification failed. |
180| 801  | Capability not supported. |
181| 3100201  | Tag running state is abnormal in service. |
182
183## tag.getNfcBTag<sup>(deprecated)</sup>
184
185getNfcBTag(tagInfo: [TagInfo](#taginfo)): [NfcBTag](js-apis-nfctech.md#nfcbtag)
186
187Obtains an **NfcBTag** object, which allows access to the tags that use the NFC-B technology.
188
189> **NOTE**
190>
191> This API is supported since API version 7 and deprecated since API version 9. Use [tag.getNfcB](#taggetnfcb9) instead.
192
193**System capability**: SystemCapability.Communication.NFC.Tag
194
195**Parameters**
196
197| Name | Type               | Mandatory| Description                                                         |
198| ------- | ------------------- | ---- | ------------------------------------------------------------- |
199| tagInfo | [TagInfo](#taginfo) | Yes  | Tag information, including the tag technology type and related parameters, obtained from [tag.getTagInfo(want: Want)](#taggettaginfo9).|
200
201**Return value**
202
203| **Type**                             | **Description**          |
204| ------------------------------------- | ------------------ |
205| [NfcBTag](js-apis-nfctech.md#nfcbtag) | **NfcBTag** object obtained.|
206
207## tag.getNfcB<sup>9+</sup>
208
209getNfcB(tagInfo: [TagInfo](#taginfo)): [NfcBTag](js-apis-nfctech.md#nfcbtag)
210
211Obtains an **NfcBTag** object, which allows access to the tags that use the NFC-B technology.
212
213**System capability**: SystemCapability.Communication.NFC.Tag
214
215**Atomic service API**: This API can be used in atomic services since API version 12.
216
217**Parameters**
218
219| Name | Type               | Mandatory| Description                                                         |
220| ------- | ------------------- | ---- | ------------------------------------------------------------- |
221| tagInfo | [TagInfo](#taginfo) | Yes  | Tag information, including the tag technology type and related parameters, obtained from [tag.getTagInfo(want: Want)](#taggettaginfo9).|
222
223**Return value**
224
225| **Type**                             | **Description**          |
226| ------------------------------------- | ------------------ |
227| [NfcBTag](js-apis-nfctech.md#nfcbtag) | **NfcBTag** object obtained.|
228
229**Error codes**
230
231For details about the error codes, see [NFC Error Codes](errorcode-nfc.md).
232
233| ID| Error Message                                 |
234| -------- | ----------------------------------------- |
235| 401  | The parameter check failed. Possible causes: <br>1. Mandatory parameters are left unspecified.<br>2. Incorrect parameters types.<br>3. Parameter verification failed. |
236| 801  | Capability not supported. |
237| 3100201  | Tag running state is abnormal in service. |
238
239## tag.getNfcFTag<sup>(deprecated)</sup>
240
241getNfcFTag(tagInfo: [TagInfo](#taginfo)): [NfcFTag](js-apis-nfctech.md#nfcftag)
242
243Obtains an **NfcFTag** object, which allows access to the tags that use the NFC-F technology.
244
245> **NOTE**
246>
247> This API is supported since API version 7 and deprecated since API version 9. Use [tag.getNfcF](#taggetnfcf9) instead.
248
249**System capability**: SystemCapability.Communication.NFC.Tag
250
251**Parameters**
252
253| Name | Type               | Mandatory| Description                                                         |
254| ------- | ------------------- | ---- | ------------------------------------------------------------- |
255| tagInfo | [TagInfo](#taginfo) | Yes  | Tag information, including the tag technology type and related parameters, obtained from [tag.getTagInfo(want: Want)](#taggettaginfo9).|
256
257**Return value**
258
259| **Type**                             | **Description**          |
260| ------------------------------------- | ------------------ |
261| [NfcFTag](js-apis-nfctech.md#nfcftag) | **NfcFTag** object obtained.|
262
263## tag.getNfcF<sup>9+</sup>
264
265getNfcF(tagInfo: [TagInfo](#taginfo)): [NfcFTag](js-apis-nfctech.md#nfcftag)
266
267Obtains an **NfcFTag** object, which allows access to the tags that use the NFC-F technology.
268
269**System capability**: SystemCapability.Communication.NFC.Tag
270
271**Atomic service API**: This API can be used in atomic services since API version 12.
272
273**Parameters**
274
275| Name | Type               | Mandatory| Description                                                         |
276| ------- | ------------------- | ---- | ------------------------------------------------------------- |
277| tagInfo | [TagInfo](#taginfo) | Yes  | Tag information, including the tag technology type and related parameters, obtained from [tag.getTagInfo(want: Want)](#taggettaginfo9).|
278
279**Return value**
280
281| **Type**                             | **Description**          |
282| ------------------------------------- | ------------------ |
283| [NfcFTag](js-apis-nfctech.md#nfcftag) | **NfcFTag** object obtained.|
284
285**Error codes**
286
287For details about the error codes, see [NFC Error Codes](errorcode-nfc.md).
288
289| ID| Error Message                                 |
290| -------- | ----------------------------------------- |
291| 401  | The parameter check failed. Possible causes: <br>1. Mandatory parameters are left unspecified.<br>2. Incorrect parameters types.<br>3. Parameter verification failed. |
292| 801  | Capability not supported. |
293| 3100201  | Tag running state is abnormal in service. |
294
295## tag.getNfcVTag<sup>(deprecated)</sup>
296
297getNfcVTag(tagInfo: [TagInfo](#taginfo)): [NfcVTag](js-apis-nfctech.md#nfcvtag)
298
299Obtains an **NfcVTag** object, which allows access to the tags that use the NFC-V technology.
300
301> **NOTE**
302>
303> This API is supported since API version 7 and deprecated since API version 9. Use [tag.getNfcV](#taggetnfcv9) instead.
304
305**System capability**: SystemCapability.Communication.NFC.Tag
306
307**Parameters**
308
309| Name | Type               | Mandatory| Description                                                         |
310| ------- | ------------------- | ---- | ------------------------------------------------------------- |
311| tagInfo | [TagInfo](#taginfo) | Yes  | Tag information, including the tag technology type and related parameters, obtained from [tag.getTagInfo(want: Want)](#taggettaginfo9).|
312
313**Return value**
314
315| **Type**                             | **Description**          |
316| ------------------------------------- | ------------------ |
317| [NfcVTag](js-apis-nfctech.md#nfcvtag) | **NfcVTag** object obtained.|
318
319## tag.getNfcV<sup>9+</sup>
320
321getNfcV(tagInfo: [TagInfo](#taginfo)): [NfcVTag](js-apis-nfctech.md#nfcvtag)
322
323Obtains an **NfcVTag** object, which allows access to the tags that use the NFC-V technology.
324
325**System capability**: SystemCapability.Communication.NFC.Tag
326
327**Atomic service API**: This API can be used in atomic services since API version 12.
328
329**Parameters**
330
331| Name | Type               | Mandatory| Description                                                         |
332| ------- | ------------------- | ---- | ------------------------------------------------------------- |
333| tagInfo | [TagInfo](#taginfo) | Yes  | Tag information, including the tag technology type and related parameters, obtained from [tag.getTagInfo(want: Want)](#taggettaginfo9).|
334
335**Return value**
336
337| **Type**                             | **Description**          |
338| ------------------------------------- | ------------------ |
339| [NfcVTag](js-apis-nfctech.md#nfcvtag) | **NfcVTag** object obtained.|
340
341**Error codes**
342
343For details about the error codes, see [NFC Error Codes](errorcode-nfc.md).
344
345| ID| Error Message                                 |
346| -------- | ----------------------------------------- |
347| 401  | The parameter check failed. Possible causes: <br>1. Mandatory parameters are left unspecified.<br>2. Incorrect parameters types.<br>3. Parameter verification failed. |
348| 801  | Capability not supported. |
349| 3100201  | Tag running state is abnormal in service. |
350
351## tag.getIsoDep<sup>9+</sup>
352
353getIsoDep(tagInfo: [TagInfo](#taginfo)): [IsoDepTag](js-apis-nfctech.md#isoDepTag9 )
354
355Obtains an **IsoDepTag** object, which allows access to the tags that use the IsoDep technology.
356
357**System capability**: SystemCapability.Communication.NFC.Tag
358
359**Atomic service API**: This API can be used in atomic services since API version 12.
360
361**Parameters**
362
363| Name | Type               | Mandatory| Description                                                         |
364| ------- | ------------------- | ---- | ------------------------------------------------------------- |
365| tagInfo | [TagInfo](#taginfo) | Yes  | Tag information, including the tag technology type and related parameters, obtained from [tag.getTagInfo(want: Want)](#taggettaginfo9).|
366
367**Return value**
368
369| **Type**                                  | **Description**                                               |
370| ------------------------------------------ | ------------------------------------------------------- |
371| [IsoDepTag](js-apis-nfctech.md#isodeptag9) | **IsoDepTag** object obtained.|
372
373**Error codes**
374
375For details about the error codes, see [NFC Error Codes](errorcode-nfc.md).
376
377| ID| Error Message                                 |
378| -------- | ----------------------------------------- |
379| 401  | The parameter check failed. Possible causes: <br>1. Mandatory parameters are left unspecified.<br>2. Incorrect parameters types.<br>3. Parameter verification failed. |
380| 801  | Capability not supported. |
381| 3100201  | Tag running state is abnormal in service. |
382
383## tag.getNdef<sup>9+</sup>
384
385getNdef(tagInfo: [TagInfo](#taginfo)): [NdefTag](js-apis-nfctech.md#ndeftag9)
386
387Obtains an **NdefTag** object, which allows access to the tags in the NFC Data Exchange Format (NDEF).
388
389**System capability**: SystemCapability.Communication.NFC.Tag
390
391**Atomic service API**: This API can be used in atomic services since API version 12.
392
393**Parameters**
394
395| Name | Type               | Mandatory| Description                                                         |
396| ------- | ------------------- | ---- | ------------------------------------------------------------- |
397| tagInfo | [TagInfo](#taginfo) | Yes  | Tag information, including the tag technology type and related parameters, obtained from [tag.getTagInfo(want: Want)](#taggettaginfo9).|
398
399**Return value**
400
401| **Type**                              | **Description**                                           |
402| -------------------------------------- | --------------------------------------------------- |
403| [NdefTag](js-apis-nfctech.md#ndeftag9) | **NdefTag** object obtained.|
404
405**Error codes**
406
407For details about the error codes, see [NFC Error Codes](errorcode-nfc.md).
408
409| ID| Error Message                                 |
410| -------- | ----------------------------------------- |
411| 401  | The parameter check failed. Possible causes: <br>1. Mandatory parameters are left unspecified.<br>2. Incorrect parameters types.<br>3. Parameter verification failed. |
412| 801  | Capability not supported. |
413| 3100201  | Tag running state is abnormal in service. |
414
415## tag.getMifareClassic<sup>9+</sup>
416
417getMifareClassic(tagInfo: [TagInfo](#taginfo)): [MifareClassicTag](js-apis-nfctech.md#mifareclassictag9)
418
419Obtains a **MifareClassicTag** object, which allows access to the tags that use MIFARE Classic.
420
421**System capability**: SystemCapability.Communication.NFC.Tag
422
423**Atomic service API**: This API can be used in atomic services since API version 12.
424
425**Parameters**
426
427| Name | Type               | Mandatory| Description                                                         |
428| ------- | ------------------- | ---- | ------------------------------------------------------------- |
429| tagInfo | [TagInfo](#taginfo) | Yes  | Tag information, including the tag technology type and related parameters, obtained from [tag.getTagInfo(want: Want)](#taggettaginfo9).|
430
431**Return value**
432
433| **Type**                                                 | **Description**                                                               |
434| --------------------------------------------------------- | ----------------------------------------------------------------------- |
435| [MifareClassicTag](js-apis-nfctech.md#mifareclassictag-9) | **MifareClassicTag** object obtained.|
436
437**Error codes**
438
439For details about the error codes, see [NFC Error Codes](errorcode-nfc.md).
440
441| ID| Error Message                                 |
442| -------- | ----------------------------------------- |
443| 401  | The parameter check failed. Possible causes: <br>1. Mandatory parameters are left unspecified.<br>2. Incorrect parameters types.<br>3. Parameter verification failed. |
444| 801  | Capability not supported. |
445| 3100201  | Tag running state is abnormal in service. |
446
447## tag.getMifareUltralight<sup>9+</sup>
448
449getMifareUltralight(tagInfo: [TagInfo](#taginfo)): [MifareUltralightTag](js-apis-nfctech.md#mifareultralighttag9)
450
451Obtains a **MifareUltralightTag** object, which allows access to the tags that use MIFARE Ultralight.
452
453**System capability**: SystemCapability.Communication.NFC.Tag
454
455**Atomic service API**: This API can be used in atomic services since API version 12.
456
457**Parameters**
458| Name | Type               | Mandatory| Description                                                         |
459| ------- | ------------------- | ---- | ------------------------------------------------------------- |
460| tagInfo | [TagInfo](#taginfo) | Yes  | Tag information, including the tag technology type and related parameters, obtained from [tag.getTagInfo(want: Want)](#taggettaginfo9).|
461
462**Return value**
463
464| **Type**                                                      | **Description**                                                                     |
465| -------------------------------------------------------------- | ----------------------------------------------------------------------------- |
466| [MifareUltralightTag](js-apis-nfctech.md#mifareultralighttag9) | **MifareUltralightTag** object obtained.|
467
468**Error codes**
469
470For details about the error codes, see [NFC Error Codes](errorcode-nfc.md).
471
472| ID| Error Message                                 |
473| -------- | ----------------------------------------- |
474| 401  | The parameter check failed. Possible causes: <br>1. Mandatory parameters are left unspecified.<br>2. Incorrect parameters types.<br>3. Parameter verification failed. |
475| 801  | Capability not supported. |
476| 3100201  | Tag running state is abnormal in service. |
477
478## tag.getNdefFormatable<sup>9+</sup>
479
480getNdefFormatable(tagInfo: [TagInfo](#taginfo)): [NdefFormatableTag](js-apis-nfctech.md#ndefformatabletag9)
481
482Obtains an **NdefFormatableTag** object, which allows access to the tags that are NDEF formattable.
483
484**System capability**: SystemCapability.Communication.NFC.Tag
485
486**Atomic service API**: This API can be used in atomic services since API version 12.
487
488**Parameters**
489| Name | Type               | Mandatory| Description                                                         |
490| ------- | ------------------- | ---- | ------------------------------------------------------------- |
491| tagInfo | [TagInfo](#taginfo) | Yes  | Tag information, including the tag technology type and related parameters, obtained from [tag.getTagInfo(want: Want)](#taggettaginfo9).|
492
493**Return value**
494
495| **Type**                                                 | **Description**                                                                 |
496| --------------------------------------------------------- | ------------------------------------------------------------------------- |
497| [NdefFormatableTag](js-apis-nfctech.md#ndefformatabletag) | **NdefFormatableTag** object obtained.|
498
499**Error codes**
500
501For details about the error codes, see [NFC Error Codes](errorcode-nfc.md).
502
503| ID| Error Message                                 |
504| -------- | ----------------------------------------- |
505| 401  | The parameter check failed. Possible causes: <br>1. Mandatory parameters are left unspecified.<br>2. Incorrect parameters types.<br>3. Parameter verification failed. |
506| 801  | Capability not supported. |
507| 3100201  | Tag running state is abnormal in service. |
508
509## tag.getTagInfo<sup>9+</sup>
510
511getTagInfo(want: [Want](../apis-ability-kit/js-apis-app-ability-want.md#want)): [TagInfo](#taginfo)
512
513Obtains **TagInfo** from **Want**, which is initialized by the NFC service and contains the attributes required by **TagInfo**.
514
515**System capability**: SystemCapability.Communication.NFC.Tag
516
517**Atomic service API**: This API can be used in atomic services since API version 12.
518
519**Parameters**
520
521| Name| Type                                    | Mandatory| Description                                               |
522| ------ | ---------------------------------------- | ---- | --------------------------------------------------- |
523| want   | [Want](../apis-ability-kit/js-apis-app-ability-want.md#want) | Yes  | Data obtained from the parameters of the **onCreate** entry function when an ability is dispatched.|
524
525**Return value**
526
527| **Type**           | **Description**                                    |
528| ------------------- | -------------------------------------------- |
529| [TagInfo](#taginfo) | **TagInfo** object obtained.|
530
531**Error codes**
532
533For details about the error codes, see [NFC Error Codes](errorcode-nfc.md).
534
535| ID| Error Message                                 |
536| -------- | ----------------------------------------- |
537| 401  | The parameter check failed. Possible causes: <br>1. Mandatory parameters are left unspecified.<br>2. Incorrect parameters types.<br>3. Parameter verification failed. |
538| 801  | Capability not supported. |
539
540## tag.registerForegroundDispatch<sup>10+</sup>
541
542registerForegroundDispatch(elementName: [ElementName](../apis-ability-kit/js-apis-bundleManager-elementName.md), discTech: number[], callback: AsyncCallback&lt;[TagInfo](#taginfo)&gt;): void
543
544Registers a listener for the NFC tag read event so that the tag can be preferentially dispatched to a foreground application. You can set the supported NFC tag technologies in **discTech**. The callback returns [TagInfo](#taginfo) read. This API can be called only by an application running in the foreground. and must be used with [tag.unregisterForegroundDispatch](#tagunregisterforegrounddispatch10) in pairs. The registered callback must be unregistered before the tag reading page exits the foreground or is destroyed.
545
546**Required permissions**: ohos.permission.NFC_TAG
547
548**System capability**: SystemCapability.Communication.NFC.Tag
549
550**Atomic service API**: This API can be used in atomic services since API version 12.
551
552**Parameters**
553
554| Name      | Type    | Mandatory| Description                                                   |
555| ------------ | -------- | ---- | ------------------------------------------------------- |
556| elementName   |  [ElementName](../apis-ability-kit/js-apis-bundleManager-elementName.md)   | Yes  | Information about the tag reading page of the application. It cannot be empty and must contain at least **bundleName** and **abilityName**.         |
557| discTech         |  number[]   | Yes  | NFC tag technologies supported by the foreground application. It cannot be empty. At least one NFC tag technology must be specified. Each number indicates the constant value of an NFC tag technology. The tag technologies are polled based on the specified value, which contains one or more of [NFC_A](#constants), [NFC_B](#constants), [NFC_F](#constants), and [NFC_V](#constants) only.|
558| callback | AsyncCallback&lt;[TagInfo](#taginfo)&gt; | Yes  | Callback used to return the tag information read. It cannot be empty.|
559
560**Error codes**
561
562For details about the error codes, see [NFC Error Codes](errorcode-nfc.md).
563
564| ID| Error Message                                 |
565| -------- | ----------------------------------------- |
566| 201  | Permission denied. |
567| 401  | The parameter check failed. Possible causes: <br>1. Mandatory parameters are left unspecified.<br>2. Incorrect parameters types.<br>3. Parameter verification failed. |
568| 801  | Capability not supported. |
569| 3100201 | The tag running state is abnormal in the service. |
570| 3100202  | The element state is invalid. |
571
572**Example**
573
574See the example of [tag.unregisterForegroundDispatch](#tagunregisterforegrounddispatch10).
575
576## tag.unregisterForegroundDispatch<sup>10+</sup>
577
578unregisterForegroundDispatch(elementName: [ElementName](../apis-ability-kit/js-apis-bundleManager-elementName.md)): void
579
580Unregisters the listener for the NFC tag read event. If the listener is unregistered, the NFC tag discovered will not be dispatched to foreground applications. The registered callback must be unregistered before the tag reading page exits the foreground or is destroyed.
581
582**Required permissions**: ohos.permission.NFC_TAG
583
584**System capability**: SystemCapability.Communication.NFC.Tag
585
586**Atomic service API**: This API can be used in atomic services since API version 12.
587
588**Parameters**
589
590| Name      | Type    | Mandatory| Description                                                   |
591| ------------ | -------- | ---- | ------------------------------------------------------- |
592| elementName   |  [ElementName](../apis-ability-kit/js-apis-bundleManager-elementName.md)   | Yes  | Information about the tag reading page of the application. It cannot be empty and must contain at least **bundleName** and **abilityName**.          |
593
594**Error codes**
595
596For details about the error codes, see [NFC Error Codes](errorcode-nfc.md).
597
598| ID| Error Message                                 |
599| -------- | ----------------------------------------- |
600| 201  | Permission denied. |
601| 401  | The parameter check failed. Possible causes: <br>1. Mandatory parameters are left unspecified.<br>2. Incorrect parameters types.<br>3. Parameter verification failed. |
602| 801  | Capability not supported. |
603| 3100201 | The tag running state is abnormal in the service. |
604
605**Example**
606
607```js
608
609import { tag } from '@kit.ConnectivityKit';
610import { BusinessError } from '@kit.BasicServicesKit';
611import { AbilityConstant, UIAbility, Want, bundleManager } from '@kit.AbilityKit';
612
613let discTech : number[] = [tag.NFC_A, tag.NFC_B]; // replace with the tech(s) that is needed by foreground ability
614let elementName : bundleManager.ElementName;
615function foregroundCb(err : BusinessError, tagInfo : tag.TagInfo) {
616    if (!err) {
617        console.log("foreground callback: tag found tagInfo = ", JSON.stringify(tagInfo));
618    } else {
619        console.log("foreground callback err: " + err.message);
620        return;
621    }
622  // other Operations of taginfo
623}
624
625export default class MainAbility extends UIAbility {
626    OnCreate(want : Want, launchParam : AbilityConstant.LaunchParam) {
627        console.log("OnCreate");
628        elementName = {
629            bundleName: want.bundleName as string,
630            abilityName: want.abilityName as string,
631            moduleName: want.moduleName as string
632        }
633    }
634
635    onForeground() {
636        console.log("onForeground");
637        try {
638            tag.registerForegroundDispatch(elementName, discTech, foregroundCb);
639        } catch (e) {
640            console.error("registerForegroundDispatch error: " + (e as BusinessError).message);
641        }
642    }
643
644    onBackground() {
645        console.log("onBackground");
646        try {
647            tag.unregisterForegroundDispatch(elementName);
648        } catch (e) {
649            console.error("registerForegroundDispatch error: " + (e as BusinessError).message);
650        }
651    }
652
653    onWindowStageDestroy() {
654        console.log("onWindowStageDestroy");
655        try {
656            tag.unregisterForegroundDispatch(elementName);
657        } catch (e) {
658            console.error("registerForegroundDispatch error: " + (e as BusinessError).message);
659        }
660    }
661
662  // override other lifecycle functions
663}
664```
665
666## tag.on<sup>11+</sup>
667
668on(type: 'readerMode', elementName: [ElementName](../apis-ability-kit/js-apis-bundleManager-elementName.md), discTech: number[], callback: AsyncCallback&lt;[TagInfo](#taginfo)&gt;): void
669
670Subscribes to the NFC tag read event to implement dispatch of the tag to a foreground application preferentially. The device enters the reader mode and disables card simulation. You can set the supported NFC tag technologies in **discTech**. The callback returns [TagInfo](#taginfo) read. This API must be used with [tag.off](#tagoff11) in pairs. If the NFC reader mode is enabled by [tag.on](#tagon11), **tag.off** must be called when the application page exits the foreground or is destroyed.
671
672**Required permissions**: ohos.permission.NFC_TAG
673
674**System capability**: SystemCapability.Communication.NFC.Tag
675
676**Atomic service API**: This API can be used in atomic services since API version 12.
677
678**Parameters**
679
680| Name      | Type    | Mandatory| Description                                                   |
681| ------------ | -------- | ---- | ------------------------------------------------------- |
682| type    | string  | Yes  | Event type, which has a fixed value of **readerMode**.|
683| elementName   |  [ElementName](../apis-ability-kit/js-apis-bundleManager-elementName.md)   | Yes  | Information about the tag reading page of the application. It cannot be empty and must contain at least **bundleName** and **abilityName**.         |
684| discTech         |  number[]   | Yes  | NFC tag technologies supported by the foreground application. It cannot be empty. At least one NFC tag technology must be specified. Each number indicates the constant value of an NFC tag technology. The tag technologies are polled based on the specified value, which contains one or more of [NFC_A](#constants), [NFC_B](#constants), [NFC_F](#constants), and [NFC_V](#constants) only.|
685| callback | AsyncCallback&lt;[TagInfo](#taginfo)&gt; | Yes  | Callback used to return the tag information read. It cannot be empty.|
686
687**Error codes**
688
689For details about the error codes, see [NFC Error Codes](errorcode-nfc.md).
690
691| ID| Error Message                                 |
692| -------- | ----------------------------------------- |
693| 201  | Permission denied. |
694| 401  | The parameter check failed. Possible causes: <br>1. Mandatory parameters are left unspecified.<br>2. Incorrect parameters types.<br>3. Parameter verification failed. |
695| 801  | Capability not supported. |
696| 3100201 | The tag running state is abnormal in the service. |
697| 3100202  | The element state is invalid. |
698
699**Example**
700
701See the example of [tag.off](#tagoff11).
702
703## tag.off<sup>11+</sup>
704
705off(type: 'readerMode', elementName: [ElementName](../apis-ability-kit/js-apis-bundleManager-elementName.md), callback?: AsyncCallback&lt;[TagInfo](#taginfo)&gt;): void
706
707Unsubscribes from the NFC tag card read event. The device exits the reader mode and resumes card simulation. If the NFC reader mode is enabled by [tag.on](#tagon11), this API must be used when the application page exits the foreground or is destroyed.
708
709**Required permissions**: ohos.permission.NFC_TAG
710
711**System capability**: SystemCapability.Communication.NFC.Tag
712
713**Atomic service API**: This API can be used in atomic services since API version 12.
714
715**Parameters**
716
717| Name      | Type    | Mandatory| Description                                                   |
718| ------------ | -------- | ---- | ------------------------------------------------------- |
719| type    | string  | Yes  | Event type, which has a fixed value of **readerMode**.|
720| elementName   |  [ElementName](../apis-ability-kit/js-apis-bundleManager-elementName.md)   | Yes  | Information about the tag reading page of the application. It cannot be empty and must contain at least **bundleName** and **abilityName**.         |
721| callback | AsyncCallback&lt;[TagInfo](#taginfo)&gt; | No  | Callback to unregister.|
722
723**Error codes**
724
725For details about the error codes, see [NFC Error Codes](errorcode-nfc.md).
726
727| ID| Error Message                                 |
728| -------- | ----------------------------------------- |
729| 201  | Permission denied. |
730| 401  | The parameter check failed. Possible causes: <br>1. Mandatory parameters are left unspecified.<br>2. Incorrect parameters types.<br>3. Parameter verification failed. |
731| 801  | Capability not supported. |
732| 3100201 | The tag running state is abnormal in the service. |
733| 3100203  | The off() can be called only when the on() has been called. |
734
735**Example**
736
737```js
738import { tag } from '@kit.ConnectivityKit';
739import { BusinessError } from '@kit.BasicServicesKit';
740import { AbilityConstant, UIAbility, Want, bundleManager } from '@kit.AbilityKit';
741
742let discTech : number[] = [tag.NFC_A, tag.NFC_B]; // replace with the tech(s) that is needed by foreground ability
743let elementName : bundleManager.ElementName;
744
745function readerModeCb(err : BusinessError, tagInfo : tag.TagInfo) {
746    if (!err) {
747        console.log("offCallback: tag found tagInfo = ", JSON.stringify(tagInfo));
748    } else {
749        console.error("offCallback err: " + err.message);
750        return;
751    }
752  // other Operations of taginfo
753}
754
755export default class MainAbility extends UIAbility {
756    OnCreate(want : Want, launchParam : AbilityConstant.LaunchParam) {
757        console.log("OnCreate");
758        elementName = {
759            bundleName: want.bundleName as string,
760            abilityName: want.abilityName as string,
761            moduleName: want.moduleName as string
762        }
763    }
764
765    onForeground() {
766        console.log("on start");
767        try {
768            tag.on('readerMode', elementName, discTech, readerModeCb);
769        } catch (e) {
770            console.error("tag.on error: " + (e as BusinessError).message);
771        }
772    }
773
774    onBackground() {
775        console.log("onBackground");
776        try {
777            tag.off('readerMode', elementName, readerModeCb);
778        } catch (e) {
779            console.error("tag.off error: " + (e as BusinessError).message);
780        }
781    }
782
783    onWindowStageDestroy() {
784        console.log("onWindowStageDestroy");
785        try {
786            tag.off('readerMode', elementName, readerModeCb);
787        } catch (e) {
788            console.error("tag.off error: " + (e as BusinessError).message);
789        }
790    }
791
792  // override other lifecycle functions
793}
794```
795
796## tag.ndef.makeUriRecord<sup>9+</sup>
797
798makeUriRecord(uri: string): [NdefRecord](#ndefrecord9)
799
800Creates an NDEF record based on the specified URI.
801
802**System capability**: SystemCapability.Communication.NFC.Tag
803
804**Atomic service API**: This API can be used in atomic services since API version 12.
805
806**Parameters**
807
808| Name| Type  | Mandatory| Description                             |
809| ------ | ------ | ---- | --------------------------------- |
810| uri    | string | Yes  | Data to write to the NDEF record.|
811
812**Return value**
813
814| **Type**                  | **Description**                                                    |
815| -------------------------- | ------------------------------------------------------------ |
816| [NdefRecord](#ndefrecord9) | NDEF record created. For details, see *NFCForum-TS-NDEF_1.0*.|
817
818**Error codes**
819
820For details about the error codes, see [NFC Error Codes](errorcode-nfc.md).
821
822| ID| Error Message                                 |
823| -------- | ----------------------------------------- |
824| 401  | The parameter check failed. Possible causes: <br>1. Mandatory parameters are left unspecified.<br>2. Incorrect parameters types.<br>3. Parameter verification failed. |
825
826**Example**
827
828```js
829import { tag } from '@kit.ConnectivityKit';
830
831try {
832    let uri = "https://www.example.com"; // change it to be correct.
833    let ndefRecord : tag.NdefRecord = tag.ndef.makeUriRecord(uri);
834    if (ndefRecord != undefined) {
835        console.log("ndefMessage makeUriRecord rtdType: " + ndefRecord.rtdType);
836        console.log("ndefMessage makeUriRecord payload: " + ndefRecord.payload);
837    } else {
838        console.log("ndefMessage makeUriRecord ndefRecord: " + ndefRecord);
839    }
840} catch (businessError) {
841    console.error("ndefMessage makeUriRecord catch businessError: " + businessError);
842}
843```
844
845## tag.ndef.makeTextRecord<sup>9+</sup>
846
847makeTextRecord(text: string, locale: string): [NdefRecord](#ndefrecord9)
848
849Creates an NDEF record based on the specified text data and encoding type.
850
851**System capability**: SystemCapability.Communication.NFC.Tag
852
853**Atomic service API**: This API can be used in atomic services since API version 12.
854
855**Parameters**
856
857| Name| Type  | Mandatory| Description                                 |
858| ------ | ------ | ---- | ------------------------------------- |
859| text   | string | Yes  | Text to write to the NDEF record.|
860| locale | string | Yes  | Encoding mode of the text.             |
861
862**Return value**
863
864| **Type**                  | **Description**                                                    |
865| -------------------------- | ------------------------------------------------------------ |
866| [NdefRecord](#ndefrecord9) | NDEF record created. For details, see *NFCForum-TS-NDEF_1.0*.|
867
868**Error codes**
869
870For details about the error codes, see [NFC Error Codes](errorcode-nfc.md).
871
872| ID| Error Message                                 |
873| -------- | ----------------------------------------- |
874| 401  | The parameter check failed. Possible causes: <br>1. Mandatory parameters are left unspecified.<br>2. Incorrect parameters types.<br>3. Parameter verification failed. |
875
876**Example**
877
878```js
879import { tag } from '@kit.ConnectivityKit';
880
881try {
882    let text = "Hello World";   // change it to be correct.
883    let locale = "en"; // change it to be correct.
884    let ndefRecord : tag.NdefRecord = tag.ndef.makeTextRecord(text, locale);
885    if (ndefRecord != undefined) {
886        console.log("ndefMessage makeTextRecord rtdType: " + ndefRecord.rtdType);
887        console.log("ndefMessage makeTextRecord payload: " + ndefRecord.payload);
888    } else {
889        console.log("ndefMessage makeTextRecord ndefRecord: " + ndefRecord);
890    }
891} catch (businessError) {
892    console.error("ndefMessage makeTextRecord catch businessError: " + businessError);
893}
894```
895
896
897## tag.ndef.makeMimeRecord<sup>9+</sup>
898
899makeMimeRecord(mimeType: string, mimeData: number[]): [NdefRecord](#ndefrecord9)
900
901Creates an NDEF record based on the specified MIME data and type.
902
903**System capability**: SystemCapability.Communication.NFC.Tag
904
905**Atomic service API**: This API can be used in atomic services since API version 12.
906
907**Parameters**
908
909| Name  | Type    | Mandatory| Description                                                   |
910| -------- | -------- | ---- | ------------------------------------------------------- |
911| mimeType | string   | Yes  | MIME type that complies with RFC rules, for example, **text/plain** or **image/jpeg**.|
912| mimeData | number[] | Yes  | MIME data, which consists of hexadecimal numbers ranging from **0x00** to **0xFF**.|
913
914**Return value**
915
916| **Type**                  | **Description**                                                    |
917| -------------------------- | ------------------------------------------------------------ |
918| [NdefRecord](#ndefrecord9) | NDEF record created. For details, see *NFCForum-TS-NDEF_1.0*.|
919
920**Error codes**
921
922For details about the error codes, see [NFC Error Codes](errorcode-nfc.md).
923
924| ID| Error Message                                 |
925| -------- | ----------------------------------------- |
926| 401  | The parameter check failed. Possible causes: <br>1. Mandatory parameters are left unspecified.<br>2. Incorrect parameters types.<br>3. Parameter verification failed. |
927
928**Example**
929
930```js
931import { tag } from '@kit.ConnectivityKit';
932
933try {
934    let mimeType = "text/plain";   // change it to be correct.
935    let mimeData = [0x01, 0x02, 0x03, 0x04]; // change it to be correct.
936    let ndefRecord : tag.NdefRecord = tag.ndef.makeMimeRecord(mimeType, mimeData);
937    if (ndefRecord != undefined) {
938        console.log("ndefMessage makeMimeRecord rtdType: " + ndefRecord.rtdType);
939        console.log("ndefMessage makeMimeRecord payload: " + ndefRecord.payload);
940    } else {
941        console.log("ndefMessage makeMimeRecord ndefRecord: " + ndefRecord);
942    }
943} catch (businessError) {
944    console.error("ndefMessage makeMimeRecord catch businessError: " + businessError);
945}
946```
947## tag.ndef.makeExternalRecord<sup>9+</sup>
948
949makeExternalRecord(domainName: string, type: string, externalData: number[]): [NdefRecord](#ndefrecord9)
950
951Creates an NDEF record based on application-specific data.
952
953**System capability**: SystemCapability.Communication.NFC.Tag
954
955**Atomic service API**: This API can be used in atomic services since API version 12.
956
957**Parameters**
958
959| Name      | Type    | Mandatory| Description                                                   |
960| ------------ | -------- | ---- | ------------------------------------------------------- |
961| domainName   | string   | Yes  | Bundle name of the application or domain name of the organization that releases the applications.         |
962| type         | string   | Yes  | Type of the application data.                                   |
963| externalData | number[] | Yes  | Application data, which consists of hexadecimal numbers ranging from **0x00** to **0xFF**.|
964
965**Return value**
966
967| **Type**                  | **Description**                                                    |
968| -------------------------- | ------------------------------------------------------------ |
969| [NdefRecord](#ndefrecord9) | NDEF record created. For details, see *NFCForum-TS-NDEF_1.0*.|
970
971**Error codes**
972
973For details about the error codes, see [NFC Error Codes](errorcode-nfc.md).
974
975| ID| Error Message                                 |
976| -------- | ----------------------------------------- |
977| 401  | The parameter check failed. Possible causes: <br>1. Mandatory parameters are left unspecified.<br>2. Incorrect parameters types.<br>3. Parameter verification failed. |
978
979**Example**
980
981```js
982import { tag } from '@kit.ConnectivityKit';
983
984try {
985    let domainName = "ohos.nfc.application"; // change it to be correct.
986    let type = "test"; // change it to be correct.
987    let externalData = [0x01, 0x02, 0x03, 0x04]; // change it to be correct.
988    let ndefRecord : tag.NdefRecord = tag.ndef.makeExternalRecord(domainName, type, externalData);
989    if (ndefRecord != undefined) {
990        console.log("ndefMessage makeExternalRecord rtdType: " + ndefRecord.rtdType);
991        console.log("ndefMessage makeExternalRecord payload: " + ndefRecord.payload);
992    } else {
993        console.log("ndefMessage makeExternalRecord ndefRecord: " + ndefRecord);
994    }
995} catch (businessError) {
996    console.error("ndefMessage makeExternalRecord catch businessError: " + businessError);
997}
998```
999
1000## tag.ndef.messageToBytes<sup>9+</sup>
1001
1002messageToBytes(ndefMessage: [NdefMessage](js-apis-nfctech.md#ndefmessage9)): number[]
1003
1004Converts an NDEF message to bytes.
1005
1006**System capability**: SystemCapability.Communication.NFC.Tag
1007
1008**Atomic service API**: This API can be used in atomic services since API version 12.
1009
1010**Parameters**
1011
1012| Name     | Type                                          | Mandatory| Description              |
1013| ----------- | ---------------------------------------------- | ---- | ------------------ |
1014| ndefMessage | [NdefMessage](js-apis-nfctech.md#ndefmessage9) | Yes  | NDEF message to convert.|
1015
1016**Return value**
1017
1018| **Type**| **Description**                                                                             |
1019| -------- | ------------------------------------------------------------------------------------- |
1020| number[] | NDEF message in bytes, which consists of hexadecimal numbers ranging from **0x00** to **0xFF**.|
1021
1022**Error codes**
1023
1024For details about the error codes, see [NFC Error Codes](errorcode-nfc.md).
1025
1026| ID| Error Message                                 |
1027| -------- | ----------------------------------------- |
1028| 401  | The parameter check failed. Possible causes: <br>1. Mandatory parameters are left unspecified.<br>2. Incorrect parameters types.<br>3. Parameter verification failed. |
1029
1030**Example**
1031
1032```js
1033import { tag } from '@kit.ConnectivityKit';
1034
1035let rawData = [0xD1, 0x01, 0x03, 0x54, 0x4E, 0x46, 0x43]; // MUST can be parsed as NDEF Record.
1036try {
1037    let ndefMessage : tag.NdefMessage = tag.ndef.createNdefMessage(rawData);
1038    console.log("ndef createNdefMessage, ndefMessage: " + ndefMessage);
1039    let rawData2 = tag.ndef.messageToBytes(ndefMessage);
1040    console.log("ndefMessage messageToBytes rawData2: " + rawData2);
1041} catch (businessError) {
1042    console.error("ndef createNdefMessage businessError: " + businessError);
1043}
1044```
1045## tag.ndef.createNdefMessage<sup>9+</sup>
1046
1047createNdefMessage(data: number[]): [NdefMessage](js-apis-nfctech.md#ndefmessage9)
1048
1049Creates 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.
1050
1051**System capability**: SystemCapability.Communication.NFC.Tag
1052
1053**Atomic service API**: This API can be used in atomic services since API version 12.
1054
1055**Parameters**
1056
1057| **Name**| **Type**| **Mandatory**| **Description**                                                                          |
1058| ---------- | -------- | -------- | ---------------------------------------------------------------------------------- |
1059| 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.|
1060
1061**Return value**
1062
1063| **Type**                                      | **Description**                                                     |
1064| ---------------------------------------------- | ------------------------------------------------------------- |
1065| [NdefMessage](js-apis-nfctech.md#ndefmessage9) | NDEF message created. For details, see *NFCForum-TS-NDEF_1.0*.|
1066
1067**Error codes**
1068
1069For details about the error codes, see [NFC Error Codes](errorcode-nfc.md).
1070
1071| ID| Error Message                                 |
1072| -------- | ----------------------------------------- |
1073| 401  | The parameter check failed. Possible causes: <br>1. Mandatory parameters are left unspecified.<br>2. Incorrect parameters types.<br>3. Parameter verification failed. |
1074
1075**Example**
1076```js
1077import { tag } from '@kit.ConnectivityKit';
1078
1079let rawData = [0xD1, 0x01, 0x03, 0x54, 0x4E, 0x46, 0x43];  // MUST can be parsed as NDEF Record.
1080try {
1081    let ndefMessage : tag.NdefMessage = tag.ndef.createNdefMessage(rawData);
1082    console.log("ndef createNdefMessage, ndefMessage: " + ndefMessage);
1083} catch (businessError) {
1084    console.error("ndef createNdefMessage businessError: " + businessError);
1085}
1086```
1087
1088## tag.ndef.createNdefMessage<sup>9+</sup>
1089
1090createNdefMessage(ndefRecords: NdefRecord[]): [NdefMessage](js-apis-nfctech.md#ndefmessage9)
1091
1092Creates an NDEF message from the NDEF records list.
1093
1094**System capability**: SystemCapability.Communication.NFC.Tag
1095
1096**Atomic service API**: This API can be used in atomic services since API version 12.
1097
1098**Parameters**
1099
1100| **Name** | **Type**                                     | **Mandatory**| **Description**                                                        |
1101| ----------- | --------------------------------------------- | -------- | ---------------------------------------------------------------- |
1102| 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*.|
1103
1104**Return value**
1105
1106| **Type**                                      | **Description**                                                     |
1107| ---------------------------------------------- | ------------------------------------------------------------- |
1108| [NdefMessage](js-apis-nfctech.md#ndefmessage9) | NDEF message created. For details, see *NFCForum-TS-NDEF_1.0*.|
1109
1110**Error codes**
1111
1112For details about the error codes, see [NFC Error Codes](errorcode-nfc.md).
1113
1114| ID| Error Message                                 |
1115| -------- | ----------------------------------------- |
1116| 401  | The parameter check failed. Possible causes: <br>1. Mandatory parameters are left unspecified.<br>2. Incorrect parameters types.<br>3. Parameter verification failed. |
1117
1118**Example**
1119
1120```js
1121import { tag } from '@kit.ConnectivityKit';
1122
1123let uriRecord : tag.NdefRecord = tag.ndef.makeUriRecord("https://www.example.com");
1124let textRecord : tag.NdefRecord = tag.ndef.makeTextRecord("Hello World", "en");
1125let ndefRecords : tag.NdefRecord[] = [uriRecord, textRecord];
1126try {
1127    let ndefMessage : tag.NdefMessage = tag.ndef.createNdefMessage(ndefRecords);
1128    console.log("ndef createNdefMessage ndefMessage: " + ndefMessage);
1129} catch (businessError) {
1130    console.error("ndef createNdefMessage businessError: " + businessError);
1131}
1132```
1133
1134## TagInfo
1135
1136Defines the **TagInfo** object, which provides information about the tag technologies supported by a card.
1137
1138**System capability**: SystemCapability.Communication.NFC.Tag
1139
1140**Required permissions**: ohos.permission.NFC_TAG
1141
1142| **Name**                     | **Type**                                                     | **Readable**| **Writable**| **Description**                                                                                    |
1143| ----------------------------- | ------------------------------------------------------------- | -------- | -------- | -------------------------------------------------------------------------------------------- |
1144| uid<sup>9+</sup>              | number[]                                                      | Yes      | No      | Tag unique identifier (UID), which consists of hexadecimal numbers ranging from **0x00** to **0xFF**.<br>**Atomic service API**: This API can be used in atomic services since API version 12.                                    |
1145| technology<sup>9+</sup>       | number[]                                                      | Yes      | No      | Supported tag technologies. Each number is a constant indicating the supported technology.<br>**Atomic service API**: This API can be used in atomic services since API version 12.                                    |
1146| supportedProfiles             | number[]                                                      | Yes      | No      | Supported profiles. This parameter is not supported since API version 9. Use [tag.TagInfo#technology](#taginfo) instead.           |
1147
1148## NdefRecord<sup>9+</sup>
1149Defines an NDEF record. For details, see *NFCForum-TS-NDEF_1.0*.
1150
1151**System capability**: SystemCapability.Communication.NFC.Tag
1152
1153**Atomic service API**: This API can be used in atomic services since API version 12.
1154
1155| **Name**| **Type**| **Readable**| **Writable**| **Description**                                                                                 |
1156| -------- | -------- | -------- | -------- | ----------------------------------------------------------------------------------------- |
1157| tnf      | number   | Yes      | No      | Type name field (TNF) of the NDEF record.                                                      |
1158| rtdType  | number[] | Yes      | No      | Record type definition (RTD) of the NDEF record. It consists of hexadecimal numbers ranging from **0x00** to **0xFF**.|
1159| id       | number[] | Yes      | No      | NDEF record ID, which consists of hexadecimal numbers ranging from **0x00** to **0xFF**.                               |
1160| payload  | number[] | Yes      | No      | NDEF payload, which consists of hexadecimal numbers ranging from **0x00** to **0xFF**.                          |
1161
1162## Constants
1163Enumerates the tag technology types.
1164
1165**System capability**: SystemCapability.Communication.NFC.Tag
1166
1167**Atomic service API**: This API can be used in atomic services since API version 12.
1168
1169| **Name**                    |**Type**| **Value**| **Description**                   |
1170| ---------------------------- | ------ | ------ | --------------------------- |
1171| NFC_A                        |  number | 1      | NFC-A (ISO 14443-3A). |
1172| NFC_B                        |  number | 2      | NFC-B (ISO 14443-3B). |
1173| ISO_DEP                      |  number | 3      | ISO-DEP (ISO 14443-4).|
1174| NFC_F                        |  number | 4      | NFC-F (JIS 6319-4).   |
1175| NFC_V                        |  number | 5      | NFC-V (ISO 15693).    |
1176| NDEF                         |  number | 6      | NDEF.                 |
1177| NDEF_FORMATABLE<sup>9+</sup> |  number | 7      | NDEF formattable.     |
1178| MIFARE_CLASSIC               |  number | 8      | MIFARE Classic.       |
1179| MIFARE_ULTRALIGHT            |  number | 9      | MIFARE Ultralight.     |
1180
1181## TnfType<sup>9+</sup>
1182Enumerates the TNF types. For details, see *NFCForum-TS-NDEF_1.0*.
1183
1184**System capability**: SystemCapability.Communication.NFC.Tag
1185
1186**Atomic service API**: This API can be used in atomic services since API version 12.
1187
1188| **Name**        | **Value**| **Description**                                        |
1189| ---------------- | ------ | ------------------------------------------------ |
1190| TNF_EMPTY        | 0x0    | Empty.                                         |
1191| TNF_WELL_KNOWN   | 0x1    | NFC Forum Well Known Type [NFC RTD].           |
1192| TNF_MEDIA        | 0x2    | Media-type as defined in RFC 2046 [RFC 2046].  |
1193| TNF_ABSOLUTE_URI | 0x3    | Absolute URI as defined in RFC 3986 [RFC 3986].|
1194| TNF_EXT_APP      | 0x4    | NFC Forum external type [NFC RTD].             |
1195| TNF_UNKNOWN      | 0x5    | Unknown.                                       |
1196| TNF_UNCHANGED    | 0x6    | Unchanged (see section 2.3.3 in *NFCForum-TS-NDEF_1.0*).                 |
1197
1198## NDEF Record RTD
1199Enumerates the NDEF record types. For details about the RTD, see *NFCForum-TS-NDEF_1.0*.
1200
1201**System capability**: SystemCapability.Communication.NFC.Tag
1202
1203**Atomic service API**: This API can be used in atomic services since API version 12.
1204
1205| **Name**             |**Type**| **Value**| **Description**               |
1206| --------------------- | ------ | ------ | ----------------------- |
1207| RTD_TEXT<sup>9+</sup> |number[]| [0x54] | NDEF record of the text type.|
1208| RTD_URI<sup>9+</sup>  |number[]| [0x55] | NDEF record of the URI type. |
1209
1210## NfcForumType<sup>9+</sup>
1211Enumerates the NFC Forum tag types.
1212
1213**System capability**: SystemCapability.Communication.NFC.Tag
1214
1215**Atomic service API**: This API can be used in atomic services since API version 12.
1216
1217| **Name**        | **Value**| **Description**            |
1218| ---------------- | ------ | -------------------- |
1219| NFC_FORUM_TYPE_1 | 1      | NFC Forum tag type 1.      |
1220| NFC_FORUM_TYPE_2 | 2      | NFC Forum tag type 2.      |
1221| NFC_FORUM_TYPE_3 | 3      | NFC Forum tag type 3.      |
1222| NFC_FORUM_TYPE_4 | 4      | NFC Forum tag type 4.      |
1223| MIFARE_CLASSIC   | 101    | MIFARE Classic.|
1224
1225## MifareClassicType<sup>9+</sup>
1226Enumerates the MIFARE Classic tag types.
1227
1228**System capability**: SystemCapability.Communication.NFC.Tag
1229
1230**Atomic service API**: This API can be used in atomic services since API version 12.
1231
1232| **Name**    | **Value**| **Description**            |
1233| ------------ | ------ | -------------------- |
1234| TYPE_UNKNOWN | 0      | Unknown type.  |
1235| TYPE_CLASSIC | 1      | MIFARE Classic.|
1236| TYPE_PLUS    | 2      | MIFARE Plus.   |
1237| TYPE_PRO     | 3      | MIFARE Pro.    |
1238
1239## MifareClassicSize<sup>9+</sup>
1240Enumerates the sizes of a MIFARE Classic tag.
1241
1242**System capability**: SystemCapability.Communication.NFC.Tag
1243
1244**Atomic service API**: This API can be used in atomic services since API version 12.
1245
1246| **Name**    | **Value**| **Description**                         |
1247| ------------ | ------ | --------------------------------- |
1248| MC_SIZE_MINI | 320    | Each tag has 5 sectors, and each sector has 4 blocks. |
1249| MC_SIZE_1K   | 1024   | Each tag has 16 sectors, and each sector has 4 blocks.|
1250| MC_SIZE_2K   | 2048   | Each tag has 32 sectors, and each sector has 4 blocks.|
1251| MC_SIZE_4K   | 4096   | Each tag has 40 sectors, and each sector has 4 blocks.|
1252
1253## MifareUltralightType<sup>9+</sup>
1254Enumerates the MIFARE Ultralight tag types.
1255
1256**System capability**: SystemCapability.Communication.NFC.Tag
1257
1258**Atomic service API**: This API can be used in atomic services since API version 12.
1259
1260| **Name**         | **Value**| **Description**                 |
1261| ----------------- | ------ | ------------------------- |
1262| TYPE_UNKNOWN      | 0      | Unknown type.     |
1263| TYPE_ULTRALIGHT   | 1      | MIFARE Ultralight.  |
1264| TYPE_ULTRALIGHT_C | 2      | MIFARE Ultralight C.|
1265
1266## NfcATag
1267
1268type NfcATag = _NfcATag
1269
1270Defines an **NfcATag** object.
1271
1272**System capability**: SystemCapability.Communication.NFC.Tag
1273
1274| Type  | Description                                                        |
1275| ------ | ------------------------------------------------------------ |
1276| [_NfcATag](./js-apis-nfctech.md#nfcatag) | Object that implements access to NFC-A (ISO 15693) properties and I/O operations on a tag. |
1277
1278## NfcBTag
1279
1280type NfcBTag = _NfcBTag
1281
1282Obtains an **NfcBTag** object.
1283
1284**System capability**: SystemCapability.Communication.NFC.Tag
1285
1286| Type  | Description                                                        |
1287| ------ | ------------------------------------------------------------ |
1288| [_NfcBTag](./js-apis-nfctech.md#nfcbtag) | Object that implements access to NFC-B (ISO 14443-3B) properties and I/O operations on a tag. |
1289
1290## NfcFTag
1291
1292type NfcFTag = _NfcFTag
1293
1294Obtains an **NfcFTag** object.
1295
1296**System capability**: SystemCapability.Communication.NFC.Tag
1297
1298| Type  | Description                                                        |
1299| ------ | ------------------------------------------------------------ |
1300| [_NfcFTag](./js-apis-nfctech.md#nfcftag) | Object that implements access to NFC-F (ISO 6319-4) properties and I/O operations on a tag. |
1301
1302## NfcVTag
1303
1304type NfcVTag = _NfcVTag
1305
1306Obtains an **NfcVTag** object.
1307
1308**System capability**: SystemCapability.Communication.NFC.Tag
1309
1310| Type  | Description                                                        |
1311| ------ | ------------------------------------------------------------ |
1312| [_NfcATag](./js-apis-nfctech.md#nfcvtag) | Object that implements access to NFC-V (ISO 15693) properties and I/O operations on a tag. |
1313
1314## IsoDepTag
1315
1316type IsoDepTag = _IsoDepTag
1317
1318Obtains an **IsoDepTag** object.
1319
1320**System capability**: SystemCapability.Communication.NFC.Tag
1321
1322| Type  | Description                                                        |
1323| ------ | ------------------------------------------------------------ |
1324| [_IsoDepTag](./js-apis-nfctech.md#isodeptag9) | Object that implements access to ISO-DEP (ISO 14443-4) properties and I/O operations on a tag. |
1325
1326## NdefTag
1327
1328type NdefTag = _NdefTag
1329
1330Obtains an **NdefTag** object.
1331
1332**System capability**: SystemCapability.Communication.NFC.Tag
1333
1334| Type  | Description                                                        |
1335| ------ | ------------------------------------------------------------ |
1336| [_NdefTag](./js-apis-nfctech.md#ndeftag9) | Object that implements access to the tags in the NFC Data Exchange Format (NDEF). |
1337
1338## MifareClassicTag
1339
1340type MifareClassicTag = _MifareClassicTag
1341
1342Obtains a **MifareClassicTag** object.
1343
1344**System capability**: SystemCapability.Communication.NFC.Tag
1345
1346| Type  | Description                                                        |
1347| ------ | ------------------------------------------------------------ |
1348| [_MifareClassicTag](./js-apis-nfctech.md#mifareclassictag9) | Object that implements access to MIFARE Classic properties and I/O operations on a tag.|
1349
1350## MifareUltralightTag
1351
1352type MifareUltralightTag = _MifareUltralightTag;
1353
1354Obtains a **MifareUltralightTag** object.
1355
1356**System capability**: SystemCapability.Communication.NFC.Tag
1357
1358| Type  | Description                                                        |
1359| ------ | ------------------------------------------------------------ |
1360| [_MifareUltralightTag](./js-apis-nfctech.md#mifareultralighttag9) | Object that implements access to MIFARE Ultralight properties and I/O operations on a tag.|
1361
1362## NdefFormatableTag
1363
1364type NdefFormatableTag = _NdefFormatableTag
1365
1366Obtains a **NdefFormatableTag** object.
1367
1368**System capability**: SystemCapability.Communication.NFC.Tag
1369
1370| Type  | Description                                                        |
1371| ------ | ------------------------------------------------------------ |
1372| [_NdefFormatableTag](./js-apis-nfctech.md#ndefformatabletag9) | Object that implements formatting of NDEF formattable tags. |
1373
1374## NdefMessage
1375
1376type NdefMessage = _NdefMessage
1377
1378Obtains an **NdefMessage** object.
1379
1380**System capability**: SystemCapability.Communication.NFC.Tag
1381
1382| Type  | Description                                                        |
1383| ------ | ------------------------------------------------------------ |
1384| [_NdefMessage](./js-apis-nfctech.md#ndefmessage9) | Obtains all NDEF records.|
1385
1386## TagSession
1387
1388type TagSession = _TagSession
1389
1390Obtains a **TagSession** object.
1391
1392**System capability**: SystemCapability.Communication.NFC.Tag
1393
1394| Type  | Description                                                        |
1395| ------ | ------------------------------------------------------------ |
1396| [_TagSession](./js-apis-tagSession.md#tagsession) | Base class of all [NFC tag technologies](js-apis-nfctech.md). It provides common APIs for establishing connections and transferring data.|
1397<!--no_check-->
1398