The **cardEmulation** module implements Near-Field Communication (NFC) card emulation.
The **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-based Card Emulation (HCE).
> **NOTE**<br>
> 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.
...
...
@@ -12,6 +12,17 @@ The **cardEmulation** module implements Near-Field Communication (NFC) card emul
import cardEmulation from '@ohos.nfc.cardEmulation';
| feature | number | Yes | Card emulation type. For details, see [FeatureType](#featuretype).|
**Return value**
| **Type**| **Description**|
| -------- | -------- |
| boolean | Returns **true** if the card emulation is supported; returns **false** otherwise.|
| boolean | Returns **true** if the card emulation type is supported; returns **false** otherwise.|
## HceService<sup>8+</sup>
Implements Host-based Card Emulation (HCE). Before calling any API in **HceService**, you must use **new cardEmulation.HceService()** to create an **HceService** instance.
Implements 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.
### startHCE<sup>8+</sup>
startHCE(aidList: string[]): boolean
Starts HCE.
Starts HCE, including setting the application to be foreground preferred and dynamically registering the application identifier (AID) list.
| type | string | Yes | Event type to subscribe to. The value is **hceCmd**. |
| callback | AsyncCallback<number[]> | Yes | Callback invoked to return the subscribed event. The input parameter is a data array that complies with the Application Protocol Data Unit (APDU).|
| callback | AsyncCallback<number[]> | Yes | Callback invoked to return the APDU. Each number in the callback is a hexadecimal number ranging from **0x00** to **0xFF**.|
| responseApdu | number[] | Yes | Data to send, which is an array that complies with the APDU.|
| responseApdu | number[] | Yes | Response APDU sent to the peer card reader. Each number of the APDU is a hexadecimal number ranging from **0x00** to **0xFF**.|
The **nfcController** module implements Near-Field Communication (NFC).
The **nfcController** module provides APIs for opening and closing Near-Field Communication (NFC) and reading the NFC state.
> **NOTE**<br>
> 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.
...
...
@@ -12,12 +12,24 @@ The **nfcController** module implements Near-Field Communication (NFC).
| type | string | Yes| Event type to unsubscribe from. The value is **nfcStateChange**.|
| callback | Callback<NfcState> | No| Callback used to return the NFC state changes. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.|
| callback | Callback<[NfcState](#nfcstate)> | No| Callback for the NFC state changes. This parameter can be left blank.|
**Example**
```js
importnfcControllerfrom'@ohos.nfcController';
varNFC_STATE_NOTIFY="nfcStateChange";
varrecvNfcStateNotifyFunc=result=>{
console.info("nfc state receive state: "+result);
importcontrollerfrom'@ohos.nfc.controller';
// Define a callback key.
varNFC_STATE_CALLBACK_KEY="nfcStateChange";
// Register the callback to receive NFC state change notifications.