• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.nfc.cardEmulation (Standard NFC Card Emulation)
2
3The **cardEmulation** module implements Near-Field Communication (NFC) card emulation. You can use the APIs provided by this module to determine the card emulation type supported and implement Host Card Emulation (HCE).<br>
4HCE provides card emulation that does not depend on a secure element. It allows an application to emulate a card and communicate with an NFC card reader through the NFC service.
5
6> **NOTE**
7>
8> The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version.
9
10## HCE and AID Declaration
11
12Before developing an application related to HCE, you must declare NFC-related attributes in the **module.json5** file.
13```json
14// Applicable to devices other than lite wearables
15{
16  "module": {
17    // Other declared attributes
18    "abilities": [
19      {
20        // Other declared attributes
21        "skills": [
22          {
23            "actions": [
24              "ohos.nfc.cardemulation.action.HOST_APDU_SERVICE"
25            ]
26          }
27        ],
28        "metadata": [
29          {
30            "name": "payment-aid",
31            "value": "your payment aid"
32          },
33          {
34            "name": "other-aid",
35            "value": "your other aid"
36          }
37        ]
38      }
39    ],
40    "requestPermissions": [
41      {
42        "name": "ohos.permission.NFC_CARD_EMULATION",
43        // Set reason to card_emulation_reason.
44        "reason": "$string:card_emulation_reason",
45      }
46    ]
47  }
48}
49```
50```json
51// Applicable to lite wearables
52{
53  "module": {
54    // Other declared attributes
55    "abilities": [
56      {
57        // Other declared attributes
58        "metadata": {
59          "customizeData": [
60            {
61              "name": "paymentAid",
62              "value": "A0000000041012"
63            },
64            {
65              "name": "otherAid",
66              "value": "A0000000041010"
67            }
68          ]
69        },
70        "skills": [
71          {
72            "entities": [
73              "ohos.nfc.cardemulation.action.HOST_APDU_SERVICE"
74            ],
75            "actions": [
76              "ohos.nfc.cardemulation.action.HOST_APDU_SERVICE"
77            ]
78          }
79        ]
80      }
81    ],
82    "reqPermissions": [
83      {
84        "name": "ohos.permission.NFC_CARD_EMULATION",
85        // Set reason to card_emulation_reason.
86        "reason": "$string:card_emulation_reason",
87        "usedScene":{
88          "ability":[
89            "FormAbility"
90          ],
91          "when":"always"
92        }
93      },
94      {
95        "name": "ohos.permission.NFC_TAG",
96        // Set reason to card_emulation_reason.
97        "reason": "$string:card_emulation_reason",
98        "usedScene":{
99          "ability":[
100            "FormAbility"
101          ],
102          "when":"always"
103        }
104      }
105    ]
106  }
107}
108```
109> **NOTE**
110>1. The **actions** field must contain **ohos.nfc.cardemulation.action.HOST_APDU_SERVICE** and cannot be changed.
111>2. The **name** fields under **metadata** must be **payment-aid** or **other-aid** when application IDs (AIDs) are declared. Incorrect setting will cause a parsing failure.
112>3. The **name** field of **requestPermissions** must be **ohos.permission.NFC_CARD_EMULATION** and cannot be changed.
113>4. Lite wearables support only the FA model, with attribute configurations and API invocation methods differing from those of other device types. Refer to the example code for detailed implementations.
114
115## Modules to Import
116
117```
118// Applicable to devices other than lite wearables
119import { cardEmulation } from '@kit.ConnectivityKit';
120
121// Applicable to lite wearables
122import cardEmulation from '@ohos.nfc.cardEmulation';
123```
124
125## FeatureType<sup>(deprecated)</sup>
126
127Enumerates the NFC card emulation types.
128
129> **NOTE**
130>
131> This API is supported since API version 6 and deprecated since API version 9. Use [hasHceCapability](#cardemulationhashcecapability9) instead.
132
133**System capability**: SystemCapability.Communication.NFC.CardEmulation
134
135| Name  | Value   | Description      |
136| ---- | ---- | -------- |
137| HCE  | 0    | HCE.|
138| UICC | 1    | Subscriber identity module (SIM) card emulation.|
139| ESE  | 2    | Embedded Secure Element (eSE) emulation. |
140
141## CardType<sup>9+</sup>
142
143Enumerates the types of services used by the card emulation application.
144
145**System capability**: SystemCapability.Communication.NFC.CardEmulation
146
147**Atomic service API**: This API can be used in atomic services since API version 12.
148
149| Name     | Value        | Description               |
150| ------- | --------- | ----------------- |
151| PAYMENT | "payment" | Payment service.|
152| OTHER   | "other"   | Other services.|
153
154## cardEmulation.isSupported<sup>(deprecated)</sup>
155
156isSupported(feature: number): boolean
157
158Checks whether a certain type of card emulation is supported.
159
160> **NOTE**
161>
162> This API is supported since API version 6 and deprecated since API version 9. Use [hasHceCapability](#cardemulationhashcecapability9) instead.
163
164**System capability**: SystemCapability.Communication.NFC.CardEmulation
165
166**Parameters**
167
168| Name    | Type    | Mandatory  | Description                                      |
169| ------- | ------ | ---- | ---------------------------------------- |
170| feature | number | Yes   | Card emulation type to check. For details, see [FeatureType](#featuretypedeprecated).|
171
172**Return value**
173
174| **Type** | **Description**                                |
175| ------- | -------------------------------------- |
176| boolean | Returns **true** if the card emulation type is supported; returns **false** otherwise.|
177
178**Example**
179
180```js
181// Applicable to devices other than lite wearables
182import { cardEmulation } from '@kit.ConnectivityKit';
183
184let isHceSupported: boolean = cardEmulation.isSupported(cardEmulation.FeatureType.HCE);
185if (!isHceSupported) {
186    console.log('this device is not supported for HCE, ignore it.');
187}
188```
189```js
190// Applicable to lite wearables
191import cardEmulation from '@ohos.nfc.cardEmulation';
192
193let isHceSupported = cardEmulation.isSupported(cardEmulation.FeatureType.HCE);
194if (!isHceSupported) {
195    console.log('this device is not supported for HCE, ignore it.');
196}
197```
198
199## cardEmulation.hasHceCapability<sup>9+</sup>
200
201hasHceCapability(): boolean
202
203Checks whether the device supports HCE.
204
205**System capability**: SystemCapability.Communication.NFC.CardEmulation
206
207**Required permissions**: ohos.permission.NFC_CARD_EMULATION
208
209**Atomic service API**: This API can be used in atomic services since API version 12.
210
211**Return value**
212
213| **Type** | **Description**                          |
214| ------- | -------------------------------- |
215| boolean | Returns **true** if HCE is supported; returns **false** otherwise.|
216
217**Error codes**
218
219For details about the error codes, see [NFC Error Codes](errorcode-nfc.md).
220
221| ID| Error Message |
222| -------- | ---------------------------- |
223|201 | Permission denied.                 |
224|801 | Capability not supported.          |
225
226**Example**
227
228```js
229// Applicable to devices other than lite wearables
230import { cardEmulation } from '@kit.ConnectivityKit';
231
232let hasHceCap: boolean = cardEmulation.hasHceCapability();
233if (!hasHceCap) {
234    console.log('this device hasHceCapability false, ignore it.');
235}
236```
237
238```js
239// Applicable to lite wearables
240import cardEmulation from '@ohos.nfc.cardEmulation';
241
242let hasHceCap = cardEmulation.hasHceCapability();
243if (!hasHceCap) {
244    console.log('this device hasHceCapability false, ignore it.');
245}
246```
247
248## cardEmulation.isDefaultService<sup>9+</sup>
249
250isDefaultService(elementName: ElementName, type: CardType): boolean
251
252Checks whether an application is the default application of the specified service type.
253
254**System capability**: SystemCapability.Communication.NFC.CardEmulation
255
256**Required permissions**: ohos.permission.NFC_CARD_EMULATION
257
258**Atomic service API**: This API can be used in atomic services since API version 12.
259
260**Parameters**
261
262| Name        | Type                                      | Mandatory  | Description                     |
263| ----------- | ---------------------------------------- | ---- |-------------------------|
264| elementName | [ElementName](../apis-ability-kit/js-apis-bundleManager-elementName.md#elementname-1) | Yes   | Information about the page, on which the application declares the NFC card emulation capability. It must contain at least **bundleName** and **abilityName** and cannot be empty.|
265| type        | [CardType](#cardtype9)                   | Yes   | Card emulation service type. Currently, only the default payment application can be queried.  |
266
267**Error codes**
268
269For details about the error codes, see [NFC Error Codes](errorcode-nfc.md).
270
271| ID| Error Message |
272| -------- | ---------------------------- |
273|201 | Permission denied.                 |
274|401 | The parameter check failed. Possible causes: <br>1. Mandatory parameters are left unspecified.<br>2. Incorrect parameters types.<br>3. Parameter verification failed. |
275|801 | Capability not supported.          |
276
277**Return value**
278
279| **Type** | **Description**                              |
280| ------- | ------------------------------------ |
281| boolean | Returns **true** if the application is the default payment application; returns **false** otherwise.|
282
283
284**Example**
285```js
286// Applicable to devices other than lite wearables
287import { cardEmulation } from '@kit.ConnectivityKit';
288import { bundleManager, Want } from '@kit.AbilityKit';
289
290// Initialize elementName, bundleName, and abilityName and set their values correctly based on the actual application information.
291let elementName: bundleManager.ElementName = {
292  bundleName: "com.example.myapplication",
293  moduleName: "entry",
294  abilityName: "EntryAbility"
295};
296
297let isDefaultService: boolean = cardEmulation.isDefaultService(elementName, cardEmulation.CardType.PAYMENT);
298```
299
300```js
301// Applicable to lite wearables
302import cardEmulation from '@ohos.nfc.cardEmulation';
303
304let appName = "com.example.testquestionlite";
305let isDefaultService = cardEmulation.isDefaultService(appName, cardEmulation.CardType.PAYMENT);
306```
307
308## HceService<sup>8+</sup>
309
310Provides APIs for implementing HCE, including receiving Application Protocol Data Units (APDUs) from the peer card reader and sending a response. Before using HCE-related APIs, check whether the device supports HCE.
311
312### startHCE<sup>(deprecated)</sup>
313
314startHCE(aidList: string[]): boolean
315
316Starts HCE, including enabling this application to run in the foreground preferentially and dynamically registering the AID list.
317
318> **NOTE**
319> This API is supported since API version 8 and deprecated since API version 9. Use [start](#start9) instead.
320
321**Required permissions**: ohos.permission.NFC_CARD_EMULATION
322
323**System capability**: SystemCapability.Communication.NFC.CardEmulation
324
325**Parameters**
326
327| Name | Type    | Mandatory| Description                   |
328| ------- | -------- | ---- | ----------------------- |
329| aidList | string[] | Yes  | List of AIDs to register.|
330
331**Return value**
332
333| **Type** | **Description**                                |
334| ------- | -------------------------------------- |
335| boolean | Returns **true** if HCE is started or has been started; returns **false** otherwise.|
336
337### start<sup>9+</sup>
338
339start(elementName: [ElementName](../apis-ability-kit/js-apis-bundleManager-elementName.md#elementname-1), aidList: string[]): void
340
341Starts HCE, including enabling this application to run in the foreground preferentially and dynamically registering the AID list.
342
343**Required permissions**: ohos.permission.NFC_CARD_EMULATION
344
345**System capability**: SystemCapability.Communication.NFC.CardEmulation
346
347**Atomic service API**: This API can be used in atomic services since API version 12.
348
349**Parameters**
350
351| Name | Type    | Mandatory| Description                   |
352| ------- | -------- | ---- | ----------------------- |
353| elementName | [ElementName](../apis-ability-kit/js-apis-bundleManager-elementName.md#elementname-1) | Yes  | Information about the page, on which the application declares the NFC card emulation capability. It must contain at least **bundleName** and **abilityName** and cannot be empty.|
354| aidList | string[] | Yes  | List of AIDs to register. This parameter can be left empty.|
355
356**Error codes**
357
358For details about the error codes, see [NFC Error Codes](errorcode-nfc.md).
359
360| ID| Error Message |
361| ------- | -------|
362|201 | Permission denied.                 |
363|401 | The parameter check failed. Possible causes: <br>1. Mandatory parameters are left unspecified.<br>2. Incorrect parameters types.<br>3. Parameter verification failed. |
364|801 | Capability not supported.          |
365| 3100301 | Card emulation running state is abnormal in service. |
366
367### stopHCE<sup>(deprecated)</sup>
368
369stopHCE(): boolean
370
371Stops HCE, including exiting the current application from the foreground, releasing the dynamically registered AID list, and canceling the subscription of **hceCmd**.
372
373> **NOTE**
374> This API is supported since API version 8 and deprecated since API version 9. Use [stop](#stop9) instead.
375
376**Required permissions**: ohos.permission.NFC_CARD_EMULATION
377
378**System capability**: SystemCapability.Communication.NFC.CardEmulation
379
380**Return value**
381
382| **Type** | **Description**                                |
383| ------- | -------------------------------------- |
384| boolean | **true** if HCE is stopped or disabled; **false** otherwise.|
385
386**Example**
387
388For details, see the example of [on](#on8).
389
390### stop<sup>9+</sup>
391
392stop(elementName: [ElementName](../apis-ability-kit/js-apis-bundleManager-elementName.md#elementname-1)): void
393
394Stops HCE, including canceling the subscription of APDU data, exiting this application from the foreground, and releasing the dynamically registered AID list. The application needs to call this API in **onDestroy** of the HCE page.
395
396**Required permissions**: ohos.permission.NFC_CARD_EMULATION
397
398**System capability**: SystemCapability.Communication.NFC.CardEmulation
399
400**Atomic service API**: This API can be used in atomic services since API version 12.
401
402**Parameters**
403
404| Name | Type    | Mandatory| Description                   |
405| ------- | -------- | ---- | ----------------------- |
406| elementName | [ElementName](../apis-ability-kit/js-apis-bundleManager-elementName.md#elementname-1) | Yes  | Information about the page, on which the application declares the NFC card emulation capability. It must contain at least **bundleName** and **abilityName** and cannot be empty.|
407
408**Error codes**
409
410For details about the error codes, see [NFC Error Codes](errorcode-nfc.md).
411
412| ID| Error Message |
413| ------- | -------|
414|201 | Permission denied.                 |
415|401 | The parameter check failed. Possible causes: <br>1. Mandatory parameters are left unspecified.<br>2. Incorrect parameters types.<br>3. Parameter verification failed. |
416|801 | Capability not supported.          |
417| 3100301 | Card emulation running state is abnormal in service. |
418
419### on<sup>8+</sup>
420
421on(type: 'hceCmd', callback: AsyncCallback\<number[]>): void
422
423Subscribes to events indicating receiving of APDUs from the peer card reader. The application needs to call this API in **onCreate()** of the HCE page.
424
425**Required permissions**: ohos.permission.NFC_CARD_EMULATION
426
427**System capability**: SystemCapability.Communication.NFC.CardEmulation
428
429**Atomic service API**: This API can be used in atomic services since API version 12.
430
431**Parameters**
432
433| Name  | Type                   | Mandatory| Description                                        |
434| -------- | ----------------------- | ---- | -------------------------------------------- |
435| type     | string                  | Yes  | Event type. It has a fixed value of **hceCmd**.                        |
436| callback | AsyncCallback\<number[]> | Yes  | Event callback. Each number is represented in hexadecimal notation, with values ranging from **0x00** to **0xFF**.|
437
438**Error codes**
439
440For details about the error codes, see [NFC Error Codes](errorcode-nfc.md).
441
442| ID| Error Message |
443| ------- | -------|
444|201 | Permission denied.                 |
445|401 | Invalid parameter.                 |
446|801 | Capability not supported.          |
447
448**Example**
449```js
450// Applicable to devices other than lite wearables
451import { hilog } from '@kit.PerformanceAnalysisKit';
452import { cardEmulation } from '@kit.ConnectivityKit';
453import { AsyncCallback } from '@kit.BasicServicesKit';
454import { ElementName } from './bundleManager/ElementName'
455import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
456
457let hceService: cardEmulation.HceService = new cardEmulation.HceService();
458let element: ElementName;
459
460export default class EntryAbility extends UIAbility {
461  onCreate(want: Want, param: AbilityConstant.LaunchParam) {
462    hilog.info(0x0000, 'testHce', '%{public}s', 'Ability onCreate');
463    element = {
464      bundleName: want.bundleName ?? '',
465      abilityName: want.abilityName ?? '',
466      moduleName: want.moduleName
467    }
468    const apduCallback: AsyncCallback<number[]> = (err, data) => {
469      // Implement data processing and handle exceptions.
470      console.log("got apdu data");
471    };
472    hceService.on('hceCmd', apduCallback);
473  }
474  onDestroy() {
475    hilog.info(0x0000, 'testHce', '%{public}s', 'Ability onDestroy');
476    hceService.stop(element);
477  }
478  // Implement other lifecycle functions as demanded.
479}
480```
481
482**Example**
483```js
484// Applicable to lite wearables
485import cardEmulation from '@ohos.nfc.cardEmulation';
486
487let appName = "com.example.testquestionlite";
488
489export default {
490  data:{
491    fontSize: '30px',
492    fontClolor: '#50609f',
493    hide: 'show',
494    headCon: appName,
495    paymentAid: ["A0000000041010", "A0000000041012"]
496  },
497  onCreate() {
498    console.info('onCreate');
499  },
500  onReady() {
501    cardEmulation.hasHceCapability();
502    cardEmulation.isDefaultService(appName, cardEmulation.CardType.PAYMENT);
503    cardEmulation.isDefaultService(appName, cardEmulation.CardType.OTHER);
504    let hcesrv = new cardEmulation.HceService();
505
506    hcesrv.start(appName, this.paymentAid);
507    hcesrv.on("hceCmd", (data) => {
508      console.log('data:' + data);
509      // Data to be sent by the application. The following data is for reference only.
510      let responseData = [0x1, 0x2];
511      hcesrv.transmit(responseData, () => {
512        console.log('sendResponse start');
513      });
514      console.log('sendResponse end');
515    });
516  },
517  onDestroy() {
518  }
519  // Implement other lifecycle functions as demanded.
520}
521```
522
523### off<sup>18+</sup>
524
525off(type: 'hceCmd', callback?: AsyncCallback\<number[]>): void
526
527Unsubscribes from events indicating receiving of APDUs from the peer card reader.
528
529**Required permissions**: ohos.permission.NFC_CARD_EMULATION
530
531**System capability**: SystemCapability.Communication.NFC.CardEmulation
532
533**Atomic service API**: This API can be used in atomic services since API version 18.
534
535**Parameters**
536
537| Name  | Type                   | Mandatory| Description                                        |
538| -------- | ----------------------- | ---- | -------------------------------------------- |
539| type     | string                  | Yes  | Event type. It has a fixed value of **hceCmd**.                        |
540| callback | AsyncCallback\<number[]> | No  | Event callback. Each number is represented in hexadecimal notation, with values ranging from **0x00** to **0xFF**.|
541
542**Error codes**
543
544For details about the error codes, see [NFC Error Codes](errorcode-nfc.md).
545
546| ID| Error Message |
547| ------- | -------|
548|201 | Permission denied.                 |
549|801 | Capability not supported.          |
550
551**Example**
552```js
553// Applicable to devices other than lite wearables
554import { hilog } from '@kit.PerformanceAnalysisKit';
555import { cardEmulation } from '@kit.ConnectivityKit';
556import { AsyncCallback } from '@kit.BasicServicesKit';
557import { ElementName } from './bundleManager/ElementName'
558import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
559
560let hceService: cardEmulation.HceService = new cardEmulation.HceService();
561let element: ElementName;
562const apduCallback: AsyncCallback<number[]> = (err, data) => {
563  // Implement data processing and handle exceptions.
564  console.log("AsyncCallback got apdu data");
565};
566
567export default class EntryAbility extends UIAbility {
568  onCreate(want: Want, param: AbilityConstant.LaunchParam) {
569    hilog.info(0x0000, 'testHce', '%{public}s', 'Ability onCreate');
570    element = {
571      bundleName: want.bundleName ?? '',
572      abilityName: want.abilityName ?? '',
573      moduleName: want.moduleName
574    }
575    const apduCallback: AsyncCallback<number[]> = (err, data) => {
576      // Implement data processing and handle exceptions.
577      console.log("got apdu data");
578    };
579    hceService.on('hceCmd', apduCallback);
580  }
581  onDestroy() {
582    hilog.info(0x0000, 'testHce', '%{public}s', 'Ability onDestroy');
583    hceService.off('hceCmd', apduCallback);
584    hceService.stop(element);
585  }
586  // Implement other lifecycle functions as demanded.
587}
588```
589
590### sendResponse<sup>(deprecated)</sup>
591
592sendResponse(responseApdu: number[]): void
593
594Sends a response to the peer card reader.
595
596> **NOTE**
597> This API is supported since API version 8 and deprecated since API version 9. Use [transmit](#transmit9) instead.
598
599**Required permissions**: ohos.permission.NFC_CARD_EMULATION
600
601**System capability**: SystemCapability.Communication.NFC.CardEmulation
602
603**Parameters**
604
605| Name      | Type    | Mandatory| Description                                              |
606| ------------ | -------- | ---- | -------------------------------------------------- |
607| responseApdu | number[] | Yes  | Response APDU sent to the peer card reader. The value consists of hexadecimal numbers ranging from **0x00** to **0xFF**.|
608
609### transmit<sup>9+</sup>
610
611transmit(response: number[]): Promise\<void>
612
613Transmits an APDU to the peer card reader. This API uses a promise to return the result. The application calls this API only after receiving an APDU sent by the card reader via [on](#on8).
614
615**Required permissions**: ohos.permission.NFC_CARD_EMULATION
616
617**System capability**: SystemCapability.Communication.NFC.CardEmulation
618
619**Atomic service API**: This API can be used in atomic services since API version 12.
620
621**Parameters**
622
623| Name      | Type    | Mandatory| Description                                              |
624| ------------ | -------- | ---- | -------------------------------------------------- |
625| response | number[] | Yes  | Response APDU sent to the peer card reader. The value consists of hexadecimal numbers ranging from **0x00** to **0xFF**.|
626
627**Return value**
628
629| **Type** | **Description**                                |
630| ------- | -------------------------------------- |
631| Promise\<void> | Promise used to return the result.|
632
633**Error codes**
634
635For details about the error codes, see [NFC Error Codes](errorcode-nfc.md).
636
637| ID| Error Message |
638| ------- | -------|
639|201 | Permission denied.                 |
640|401 | The parameter check failed. Possible causes: <br>1. Mandatory parameters are left unspecified.<br>2. Incorrect parameters types.<br>3. Parameter verification failed. |
641|801 | Capability not supported.          |
642| 3100301 | Card emulation running state is abnormal in service. |
643
644**Example**
645```js
646// Applicable to devices other than lite wearables
647import { cardEmulation } from '@kit.ConnectivityKit';
648import { BusinessError } from '@kit.BasicServicesKit';
649
650let hceService: cardEmulation.HceService = new cardEmulation.HceService();
651
652// Data to be sent by the application. The following data is for reference only.
653const responseData = [0x1, 0x2];
654hceService.transmit(responseData).then(() => {
655  // Process the promise.
656  console.log("transmit Promise success.");
657}).catch((err: BusinessError) => {
658  console.error("transmit Promise error:", err);
659});
660```
661
662```js
663// Applicable to lite wearables
664import cardEmulation from '@ohos.nfc.cardEmulation';
665
666let hceService = new cardEmulation.HceService();
667
668// Data to be sent by the application. The following data is for reference only.
669let responseData = [0x1, 0x2];
670hceService.transmit(responseData).then(() => {
671  // Process the promise.
672  console.log("transmit Promise success.");
673});
674console.log("transmit Promise end.");
675```
676
677### transmit<sup>9+</sup>
678
679transmit(response: number[], callback: AsyncCallback\<void>): void
680
681Transmits an APDU to the peer card reader. This API uses an asynchronous callback to return the result. The application calls this API only after receiving an APDU sent by the card reader via [on](#on8).
682
683**Required permissions**: ohos.permission.NFC_CARD_EMULATION
684
685**System capability**: SystemCapability.Communication.NFC.CardEmulation
686
687**Atomic service API**: This API can be used in atomic services since API version 12.
688
689**Parameters**
690
691| Name | Type    | Mandatory| Description                   |
692| ------- | -------- | ---- | ----------------------- |
693| response | number[] | Yes  | Response APDU sent to the peer card reader. The value consists of hexadecimal numbers ranging from **0x00** to **0xFF**.|
694| callback | AsyncCallback\<void> | Yes  | Callback used to return the operation result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.|
695
696**Error codes**
697
698For details about the error codes, see [NFC Error Codes](errorcode-nfc.md).
699
700| ID| Error Message |
701| ------- | -------|
702|201 | Permission denied.                 |
703|401 | The parameter check failed. Possible causes: <br>1. Mandatory parameters are left unspecified.<br>2. Incorrect parameters types.<br>3. Parameter verification failed. |
704|801 | Capability not supported.          |
705| 3100301 | Card emulation running state is abnormal in service. |
706
707**Example**
708```js
709// Applicable to devices other than lite wearables
710import { cardEmulation } from '@kit.ConnectivityKit';
711import { BusinessError } from '@kit.BasicServicesKit';
712
713let hceService: cardEmulation.HceService = new cardEmulation.HceService();
714
715// Data to be sent by the application. The following data is for reference only.
716try {
717  const responseData = [0x1, 0x2];
718
719  hceService.transmit(responseData, (err : BusinessError)=> {
720    if (err) {
721      console.error(`transmit AsyncCallback err Code: ${err.code}, message: ${err.message}`);
722    } else {
723      console.log("transmit AsyncCallback success.");
724    }
725  });
726} catch (error) {
727  console.error(`transmit AsyncCallback catch Code: ${(error as BusinessError).code}, ` +
728    `message: ${(error as BusinessError).message}`);
729}
730```
731```js
732// Applicable to lite wearables
733import cardEmulation from '@ohos.nfc.cardEmulation';
734
735let hceService = new cardEmulation.HceService();
736
737// Data to be sent by the application. The following data is for reference only.
738let responseData = [0x1, 0x2];
739hceService.transmit(responseData, () => {
740  console.log("transmit Promise success.");
741});
742console.log("transmit Promise end.");
743```
744