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-based Card Emulation (HCE). 4 5> **NOTE** 6> 7> 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. 8 9## Modules to Import 10 11``` 12import cardEmulation from '@ohos.nfc.cardEmulation'; 13``` 14 15## FeatureType 16 17Enumerates the NFC card emulation types. 18 19> **NOTE** 20> This parameter is supported since API version 6 and deprecated since API version 9. You are advised to use [hasHceCapability](#hashcecapability9). 21 22**System capability**: SystemCapability.Communication.NFC.CardEmulation 23 24| Name | Value | Description | 25| ---- | ---- | -------- | 26| HCE | 0 | HCE.| 27| UICC | 1 | Subscriber identity module (SIM) card emulation.| 28| ESE | 2 | embedded Secure Element (eSE) emulation. | 29 30## CardType<sup>9+</sup> 31 32Enumerates the types of services used by the card emulation application. 33 34**System capability**: SystemCapability.Communication.NFC.CardEmulation 35 36| Name | Value | Description | 37| ------- | --------- | ----------------- | 38| PAYMENT | "payment" | Payment type.| 39| OTHER | "other" | Other types.| 40 41## isSupported 42 43isSupported(feature: number): boolean 44 45Checks whether a certain type of card emulation is supported. 46 47> **NOTE** 48> This parameter is supported since API version 6 and deprecated since API version 9. You are advised to use [hasHceCapability](#hashcecapability9). 49 50**System capability**: SystemCapability.Communication.NFC.CardEmulation 51 52**Parameters** 53 54| Name | Type | Mandatory | Description | 55| ------- | ------ | ---- | ---------------------------------------- | 56| feature | number | Yes | Card emulation type. For details, see [FeatureType](#featuretype).| 57 58**Return value** 59 60| **Type** | **Description** | 61| ------- | -------------------------------------- | 62| boolean | Returns **true** if the card emulation type is supported; returns **false** otherwise.| 63 64## hasHceCapability<sup>9+</sup> 65 66hasHceCapability(): boolean 67 68Checks whether HCE is supported. 69 70**System capability**: SystemCapability.Communication.NFC.CardEmulation 71 72**Required permissions**: ohos.permission.NFC_CARD_EMULATION 73 74**Return value** 75 76| **Type** | **Description** | 77| ------- | -------------------------------- | 78| boolean | Returns **true** if HCE is supported; returns **false** otherwise.| 79 80## isDefaultService<sup>9+</sup> 81 82isDefaultService(elementName: ElementName, type: CardType): boolean 83 84Checks whether an application is the default application of the specified service type. 85 86**System capability**: SystemCapability.Communication.NFC.CardEmulation 87 88**Required permissions**: ohos.permission.NFC_CARD_EMULATION 89 90**Parameters** 91 92| Name | Type | Mandatory | Description | 93| ----------- | ---------------------------------------- | ---- | ----------------------- | 94| elementName | [ElementName](js-apis-bundleManager-elementName.md#elementname) | Yes | Application description, which consists of the bundle name and component name.| 95| type | [CardType](#cardtype9) | Yes | Card emulation service type. | 96 97**Return value** 98 99| **Type** | **Description** | 100| ------- | ------------------------------------ | 101| boolean | Returns **true** if the application is the default payment application; returns **false** otherwise.| 102 103**Example** 104 105```js 106import cardEmulation from '@ohos.nfc.cardEmulation'; 107 108var isHceSupported = cardEmulation.isSupported(cardEmulation.FeatureType.HCE); 109if (!isHceSupported) { 110 console.log('this device is not supported for HCE, ignore it.'); 111} 112 113var hasHceCap = cardEmulation.hasHceCapability(); 114if (!hasHceCap) { 115 console.log('this device hasHceCapability false, ignore it.'); 116} 117 118var elementName = { 119 "bundleName": "com.example.myapplication", 120 "abilityName": "EntryAbility", 121}; 122var isDefaultService = cardEmulation.isDefaultService(elementName, cardEmulation.CardType.PAYMENT); 123console.log('is the app is default service for this card type: ' + isDefaultService); 124``` 125