未验证 提交 6f0a4e74 编写于 作者: O openharmony_ci 提交者: Gitee

!5335 [翻译完成】#I59W3T

Merge pull request !5335 from Annie_wang/PR4631
......@@ -141,6 +141,9 @@
- [@ohos.bluetooth](js-apis-bluetooth.md)
- [@ohos.connectedTag](js-apis-connectedTag.md)
- [@ohos.nfc.cardEmulation](js-apis-cardEmulation.md)
- [@ohos.nfc.controller](js-apis-nfcController.md)
- [@ohos.nfc.tag](js-apis-nfcTag.md)
- [@ohos.rpc](js-apis-rpc.md)
- [@ohos.wifi](js-apis-wifi.md)
- [@ohos.wifiext](js-apis-wifiext.md)
......
# Standard NFC Card Emulation
Implements Near-Field Communication (NFC) card emulation.
> **NOTE**<br>
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## **Modules to Import**
```
import cardEmulation from '@ohos.nfc.cardEmulation';
```
## cardEmulation.isSupported
isSupported(feature: number): boolean
Checks whether a certain type of card emulation is supported.
**System capability**: SystemCapability.Communication.NFC
**Return value**
| **Type**| **Description**|
| -------- | -------- |
| boolean | Returns **true** if the card emulation is supported; returns **false** otherwise.|
## HceService
Implements Host-based Card Emulation (HCE). Before calling any API in **HceService**, you must use **new cardEmulation.HceService()** to create an **HceService** instance.
### startHCE
startHCE(aidList: string[]): boolean
Starts HCE.
**Required permissions**: ohos.permission.NFC_CARD_EMULATION
**System capability**: SystemCapability.Communication.NFC
**Parameters**
| Name | Type | Mandatory| Description |
| ------- | -------- | ---- | ----------------------- |
| aidList | string[] | Yes | Application ID (AID) list to be registered for card emulation.|
### stopHCE
stopHCE(): boolean
Stops HCE.
**Required permissions**: ohos.permission.NFC_CARD_EMULATION
**System capability**: SystemCapability.Communication.NFC
### on
on(type: "hceCmd", callback: AsyncCallback<number[]>): void;
Subscribes to messages from the peer device after **startHCE()**.
**Required permissions**: ohos.permission.NFC_CARD_EMULATION
**System capability**: SystemCapability.Communication.NFC
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------- | ---- | -------------------------------------------- |
| 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).|
### sendResponse
sendResponse(responseApdu: number[]): void;
Sends a response to the peer device.
**Required permissions**: ohos.permission.NFC_CARD_EMULATION
**System capability**: SystemCapability.Communication.NFC
**Parameters**
| Name | Type | Mandatory| Description |
| ------------ | -------- | ---- | -------------------------------------------------- |
| responseApdu | number[] | Yes | Data to send, which is an array that complies with the APDU.|
**Example**
```js
var hceService = new cardEmulation.HceService();
hceService.startHCE([
"F0010203040506", "A0000000041010"
])
hceService.stopHCE();
hceService.on("hceCmd", (err, res) => {
if(err.data === 0) {
console.log('callback => Operation hceCmd succeeded. Data: ' + JSON.stringify(res));
hceService.sendResponse([0x00,0xa4,0x04,0x00,
0x0e,0x32,0x50,0x41,0x59,0x2e,0x53,0x59,0x53,0x2e,0x44,0x44,
0x46,0x30,0x31,0x00]);
} else {
console.log('callback => Operation hceCmd failed. Cause: ' + err.data);
}
})
```
# Standard NFC
Implements Near-Field Communication (NFC).
> **NOTE**<br>
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## **Modules to Import**
```
import controller from '@ohos.nfc.controller';
```
## controller.isNfcAvailable
isNfcAvailable(): boolean
Checks whether NFC is available.
**Return value**
| **Type**| **Description**|
| -------- | -------- |
| boolean | Returns **true** if NFC is available; returns **false** otherwise.|
## controller.openNfc
openNfc(): boolean
Opens NFC.
**Required permissions**: ohos.permission.MANAGE_SECURE_SETTINGS
**System capability**: SystemCapability.Communication.NFC
**Return value**
| **Type**| **Description**|
| -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise. |
## controller.closeNfc
closeNfc(): boolean
Closes NFC.
**Required permissions**: ohos.permission.MANAGE_SECURE_SETTINGS
**System capability**: SystemCapability.Communication.NFC
**Return value**
| **Type**| **Description** |
| -------- | ------------------------------------------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
## controller.isNfcOpen
isNfcOpen(): boolean
Checks whether NFC is open.
**System capability**: SystemCapability.Communication.NFC
**Return value**
| **Type**| **Description** |
| -------- | ----------------------------------- |
| boolean | Returns **true** if NFC is open; returns **false** otherwise.|
## controller.getNfcState
getNfcState(): NfcState
Obtains the NFC state.
**System capability**: SystemCapability.Communication.NFC
**Return value**
| **Type**| **Description** |
| -------- | ---------------------- |
| NfcState | NFC state obtained. For details, see [NfcState](#nfcstate).|
## controller.on('nfcStateChange')
on(type: "nfcStateChange", callback: Callback&lt;NfcState&gt;): void
Subscribes to NFC state changes.
**System capability**: SystemCapability.Communication.NFC
**Parameter**
| **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- |
| type | string | Yes| Event type to subscribe to. The value is **nfcStateChange**.|
| callback | Callback&lt;NfcState&gt; | Yes| Callback invoked to return the NFC state changes.|
## controller.off('nfcStateChange')
off(type: "nfcStateChange", callback?: Callback&lt;NfcState&gt;): void
Unsubscribes from the NFC state changes.
**System capability**: SystemCapability.Communication.NFC
**Parameter**
| **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- |
| type | string | Yes| Event type to unsubscribe from. The value is **nfcStateChange**.|
| callback | Callback&lt;NfcState&gt; | 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.|
**Example**
```js
import nfcController from '@ohos.nfcController';
var NFC_STATE_NOTIFY = "nfcStateChange";
var recvNfcStateNotifyFunc = result => {
console.info("nfc state receive state: " + result);
}
// Subscribe to the NFC state changes.
nfcController.on(NFC_STATE_NOTIFY, recvNfcStateNotifyFunc);
// Unsubscribe from the NFC state changes.
nfcController.off(NFC_STATE_NOTIFY, recvNfcStateNotifyFunc);
```
## NfcState
Enumerates the NFC states.
| Name| Default Value| Description|
| -------- | -------- | -------- |
| STATE_OFF | 1 | Off|
| STATE_TURNING_ON | 2 | Turning on|
| STATE_ON | 3 | On|
| STATE_TURNING_OFF | 4 | Turning off|
# Standard NFC Tag
Manages Near-Field Communication (NFC) tags.
> **NOTE**<br>
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## **Modules to Import**
```
import tag from '@ohos.nfc.tag';
```
## tag.getNfcATag
getNfcATag(tagInfo: TagInfo): NfcATag
Obtains an **NfcATag** object, which allows access to the tags that use the NFC-A technology.
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC
**Return value**
| **Type**| **Description**|
| -------- | -------- |
| NfcATag | **NfcATag** object obtained.|
## tag.getNfcBTag
getNfcBTag(tagInfo: TagInfo): NfcBTag
Obtains an **NfcBTag** object, which allows access to the tags that use the NFC-B technology.
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC
**Return value**
| **Type**| **Description** |
| -------- | ---------------- |
| NfcBTag | **NfcBTag** object obtained.|
## tag.getNfcFTag
getNfcFTag(tagInfo: TagInfo): NfcFTag
Obtains an **NfcFTag** object, which allows access to the tags that use the NFC-F technology.
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC
**Return value**
| **Type**| **Description** |
| -------- | ---------------- |
| NfcFTag | **NfcFTag** object obtained.|
## tag.getNfcVTag
getNfcVTag(tagInfo: TagInfo): NfcVTag
Obtains an **NfcVTag** object, which allows access to the tags that use the NFC-V technology.
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC
**Return value**
| **Type**| **Description** |
| -------- | ---------------- |
| NfcVTag | **NfcVTag** object obtained.|
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册