未验证 提交 29db2810 编写于 作者: O openharmony_ci 提交者: Gitee

!13878 [翻译完成】#I6661B

Merge pull request !13878 from Annie_wang/PR12492
...@@ -108,7 +108,7 @@ ...@@ -108,7 +108,7 @@
- [MissionListener](js-apis-inner-application-missionListener.md) - [MissionListener](js-apis-inner-application-missionListener.md)
- [MissionParameter](js-apis-inner-application-missionParameter.md) - [MissionParameter](js-apis-inner-application-missionParameter.md)
- [MissionSnapshot](js-apis-inner-application-missionSnapshot.md) - [MissionSnapshot](js-apis-inner-application-missionSnapshot.md)
- [PermissionRequestResult](js-apis-inner-application-permissionRequestResult.md) - [PermissionRequestResult](js-apis-permissionrequestresult.md)
- [ProcessData](js-apis-inner-application-processData.md) - [ProcessData](js-apis-inner-application-processData.md)
- [ProcessRunningInfo](js-apis-inner-application-processRunningInfo.md) - [ProcessRunningInfo](js-apis-inner-application-processRunningInfo.md)
- [ProcessRunningInformation](js-apis-inner-application-processRunningInformation.md) - [ProcessRunningInformation](js-apis-inner-application-processRunningInformation.md)
...@@ -242,19 +242,19 @@ ...@@ -242,19 +242,19 @@
- [@ohos.net.webSocket](js-apis-webSocket.md) - [@ohos.net.webSocket](js-apis-webSocket.md)
- [@ohos.request](js-apis-request.md) - [@ohos.request](js-apis-request.md)
- Connectivity - Connectivity
- [@ohos.bluetooth](js-apis-bluetooth.md) - [@ohos.bluetooth (Bluetooth)](js-apis-bluetooth.md)
- [@ohos.connectedTag](js-apis-connectedTag.md) - [@ohos.connectedTag (Active Tags)](js-apis-connectedTag.md)
- [@ohos.nfc.cardEmulation](js-apis-cardEmulation.md) - [@ohos.nfc.cardEmulation (Standard NFC Card Emulation)](js-apis-cardEmulation.md)
- [@ohos.nfc.controller](js-apis-nfcController.md) - [@ohos.nfc.controller (Standard NFC)](js-apis-nfcController.md)
- [@ohos.nfc.tag](js-apis-nfcTag.md) - [@ohos.nfc.tag (Standard NFC Tags)](js-apis-nfcTag.md)
- [@ohos.rpc](js-apis-rpc.md) - [@ohos.rpc (RPC)](js-apis-rpc.md)
- [@ohos.wifiManager (WLAN)](js-apis-wifiManager.md) - [@ohos.wifiManager (WLAN)](js-apis-wifiManager.md)
- [@ohos.wifiManagerExt](js-apis-wifiManagerExt.md) - [@ohos.wifiManagerExt (WLAN Extension)](js-apis-wifiManagerExt.md)
- [@ohos.wifi](js-apis-wifi.md) - [@ohos.wifi (To Be Deprecated)](js-apis-wifi.md)
- [@ohos.wifiext](js-apis-wifiext.md) - [@ohos.wifiext (To Be Deprecated)](js-apis-wifiext.md)
- tag - tag
- [nfctech](js-apis-nfctech.md) - [nfctech (Standard NFC Technologies)](js-apis-nfctech.md)
- [tagSession](js-apis-tagSession.md) - [tagSession (Standard NFC Tag Session)](js-apis-tagSession.md)
- Basic Features - Basic Features
- [@ohos.accessibility](js-apis-accessibility.md) - [@ohos.accessibility](js-apis-accessibility.md)
- [@ohos.accessibility.config](js-apis-accessibility-config.md) - [@ohos.accessibility.config](js-apis-accessibility-config.md)
...@@ -314,9 +314,9 @@ ...@@ -314,9 +314,9 @@
- [@ohos.usb](js-apis-usb.md) - [@ohos.usb](js-apis-usb.md)
- [@ohos.vibrator](js-apis-vibrator.md) - [@ohos.vibrator](js-apis-vibrator.md)
- Account Management - Account Management
- [@ohos.account.appAccount](js-apis-appAccount.md) - [@ohos.account.appAccount (App Account Management)](js-apis-appAccount.md)
- [@ohos.account.distributedAccount](js-apis-distributed-account.md) - [@ohos.account.distributedAccount (Distributed Account Management)](js-apis-distributed-account.md)
- [@ohos.account.osAccount](js-apis-osAccount.md) - [@ohos.account.osAccount (OS Account Management)](js-apis-osAccount.md)
- Custom Management - Custom Management
- [@ohos.configPolicy](js-apis-configPolicy.md) - [@ohos.configPolicy](js-apis-configPolicy.md)
- [@ohos.enterprise.deviceInfo](js-apis-enterprise-deviceInfo.md) - [@ohos.enterprise.deviceInfo](js-apis-enterprise-deviceInfo.md)
......
# @ohos.account.appAccount # @ohos.account.appAccount (App Account Management)
The **appAccount** module provides APIs for adding, deleting, modifying, and querying app account information, and supports inter-app authentication and distributed data synchronization. The **appAccount** module provides APIs for adding, deleting, modifying, and querying app account information, and supports inter-app authentication and distributed data synchronization.
...@@ -4883,7 +4883,7 @@ Creates an app account implicitly based on the specified account owner. This API ...@@ -4883,7 +4883,7 @@ Creates an app account implicitly based on the specified account owner. This API
| options | [CreateAccountImplicitlyOptions](#createaccountimplicitlyoptions9) | Yes | Options for implicitly creating the account. | | options | [CreateAccountImplicitlyOptions](#createaccountimplicitlyoptions9) | Yes | Options for implicitly creating the account. |
| callback | [AuthCallback](#authcallback9) | Yes | Authenticator callback invoked to return the result.| | callback | [AuthCallback](#authcallback9) | Yes | Authenticator callback invoked to return the result.|
### addAccountImplicitly<sup>deprecated</sup> ### addAccountImplicitly<sup>(deprecated)</sup>
addAccountImplicitly(authType: string, callerBundleName: string, options: {[key: string]: any}, callback: AuthenticatorCallback): void addAccountImplicitly(authType: string, callerBundleName: string, options: {[key: string]: any}, callback: AuthenticatorCallback): void
...@@ -4922,7 +4922,7 @@ Authenticates an app account to obtain the authorization token. This API uses an ...@@ -4922,7 +4922,7 @@ Authenticates an app account to obtain the authorization token. This API uses an
| options | {[key: string]: Object} | Yes | Options for the authentication. | | options | {[key: string]: Object} | Yes | Options for the authentication. |
| callback | [AuthCallback](#authcallback9) | Yes | Callback invoked to return the result.| | callback | [AuthCallback](#authcallback9) | Yes | Callback invoked to return the result.|
### authenticate<sup>deprecated</sup> ### authenticate<sup>(deprecated)</sup>
authenticate(name: string, authType: string, callerBundleName: string, options: {[key: string]: any}, callback: AuthenticatorCallback): void authenticate(name: string, authType: string, callerBundleName: string, options: {[key: string]: any}, callback: AuthenticatorCallback): void
......
# @ohos.bluetooth # @ohos.bluetooth (Bluetooth)
The **Bluetooth** module provides classic Bluetooth capabilities and Bluetooth Low Energy (BLE) scan and advertising. The **Bluetooth** module provides classic Bluetooth capabilities and Bluetooth Low Energy (BLE) scan and advertising.
......
# @ohos.nfc.cardEmulation # @ohos.nfc.cardEmulation (Standard 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). 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).
...@@ -16,21 +16,40 @@ import cardEmulation from '@ohos.nfc.cardEmulation'; ...@@ -16,21 +16,40 @@ import cardEmulation from '@ohos.nfc.cardEmulation';
Enumerates the NFC card emulation types. Enumerates the NFC card emulation types.
**System capability**: SystemCapability.Communication.NFC.Core > **NOTE**
>
> This parameter is supported since API version 6 and deprecated since API version 9. You are advised to use [hasHceCapability](#hashcecapability9).
**System capability**: SystemCapability.Communication.NFC.CardEmulation
| Name| Value| Description| | Name| Value| Description|
| -------- | -------- | -------- | | -------- | -------- | -------- |
| HCE | 0 | HCE.| | HCE | 0 | HCE.|
| UICC | 1 | Subscriber identity module (SIM) card emulation.| | UICC | 1 | Subscriber identity module (SIM) card emulation.|
| ESE | 2 | embedded Secure Element (eSE) emulation.| | ESE | 2 | embedded Secure Element (eSE) emulation.|
## CardType<sup>9+</sup>
Enumerates the types of services used by the card emulation application.
## cardEmulation.isSupported **System capability**: SystemCapability.Communication.NFC.CardEmulation
| Name| Value| Description|
| -------- | -------- | -------- |
| PAYMENT | "payment" | Payment type.|
| OTHER | "other" | Other types.|
## isSupported
isSupported(feature: number): boolean isSupported(feature: number): boolean
Checks whether a certain type of card emulation is supported. Checks whether a certain type of card emulation is supported.
**System capability**: SystemCapability.Communication.NFC.Core > **NOTE**
>
> This parameter is supported since API version 6 and deprecated since API version 9. You are advised to use [hasHceCapability](#hashcecapability9).
**System capability**: SystemCapability.Communication.NFC.CardEmulation
**Parameters** **Parameters**
...@@ -44,68 +63,44 @@ Checks whether a certain type of card emulation is supported. ...@@ -44,68 +63,44 @@ Checks whether a certain type of card emulation is supported.
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the card emulation type is supported; returns **false** otherwise.| | boolean | Returns **true** if the card emulation type is supported; returns **false** otherwise.|
## HceService<sup>8+</sup> ## hasHceCapability<sup>9+</sup>
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> hasHceCapability(): boolean
startHCE(aidList: string[]): boolean Checks whether HCE is supported.
Starts HCE, including setting the application to be foreground preferred and dynamically registering the application identifier (AID) list. **System capability**: SystemCapability.Communication.NFC.CardEmulation
**Required permissions**: ohos.permission.NFC_CARD_EMULATION **Required permissions**: ohos.permission.NFC_CARD_EMULATION
**System capability**: SystemCapability.Communication.NFC.Core **Return value**
**Parameters**
| Name | Type | Mandatory| Description |
| ------- | -------- | ---- | ----------------------- |
| aidList | string[] | Yes | AID list to register.|
### stopHCE<sup>8+</sup>
stopHCE(): boolean
Stops HCE, including removing the foreground preferred attribute and releasing the dynamically registered AID list.
**Required permissions**: ohos.permission.NFC_CARD_EMULATION | **Type**| **Description**|
| -------- | -------- |
| boolean | Returns **true** if HCE is supported; returns **false** otherwise.|
**System capability**: SystemCapability.Communication.NFC.Core ## isDefaultService<sup>9+</sup>
### on<sup>8+</sup> isDefaultService(elementName: ElementName, type: CardType): boolean
on(type: "hceCmd", callback: AsyncCallback<number[]>): void; Checks whether an application is the default application of the specified service type.
Registers a callback to receive APDUs from the peer card reader. **System capability**: SystemCapability.Communication.NFC.CardEmulation
**Required permissions**: ohos.permission.NFC_CARD_EMULATION **Required permissions**: ohos.permission.NFC_CARD_EMULATION
**System capability**: SystemCapability.Communication.NFC.Core
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ----------------------- | ---- | -------------------------------------------- | | ------- | -------- | ---- | ----------------------- |
| type | string | Yes | Event type to subscribe to. The value is **hceCmd**. | | elementName | [ElementName](js-apis-bundleManager-elementName.md#elementname) | Yes| Application description, which consists of the bundle name and component name.|
| callback | AsyncCallback<number[]> | Yes | Callback invoked to return the APDU. Each number in the callback is a hexadecimal number ranging from **0x00** to **0xFF**.| | type | [CardType](#cardtype9) | Yes| Card emulation service type.|
### sendResponse<sup>8+</sup>
sendResponse(responseApdu: number[]): void;
Sends a response to the peer card reader.
**Required permissions**: ohos.permission.NFC_CARD_EMULATION
**System capability**: SystemCapability.Communication.NFC.Core
**Parameters** **Return value**
| Name | Type | Mandatory| Description | | **Type**| **Description**|
| ------------ | -------- | ---- | -------------------------------------------------- | | -------- | -------- |
| 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**.| | boolean | Returns **true** if the application is the default payment application; returns **false** otherwise.|
**Example** **Example**
...@@ -118,23 +113,16 @@ if (!isHceSupported) { ...@@ -118,23 +113,16 @@ if (!isHceSupported) {
return; return;
} }
// The device supports HCE and transimits APDUs with the remote NFC reader. var hasHceCap = cardEmulation.hasHceCapability();
var hceService = new cardEmulation.HceService(); if (!hasHceCap) {
hceService.startHCE([ console.log('this device hasHceCapability false, ignore it.');
"F0010203040506", "A0000000041010" return;
]); }
hceService.on("hceCmd", (err, res) => { var elementName = {
if(err.data === 0) { "bundleName": "com.example.myapplication",
console.log('callback => Operation hceCmd succeeded. Data: ' + JSON.stringify(res)); "abilityName": "EntryAbility",
hceService.sendResponse([0x00,0xa4,0x04,0x00, };
0x0e,0x32,0x50,0x41,0x59,0x2e,0x53,0x59,0x53,0x2e,0x44,0x44, var isDefaultService = cardEmulation.isDefaultService(elementName, cardEmulation.CardType.PAYMENT);
0x46,0x30,0x31,0x00]); console.log('is the app is default service for this card type: ' + isDefaultService);
} else {
console.log('callback => Operation hceCmd failed. Cause: ' + err.data);
}
})
// Stop HCE when the application exits the NFC card emulation.
hceService.stopHCE();
``` ```
# @ohos.connectedTag # @ohos.connectedTag (Active Tags)
The **connectedTag** module provides APIs for using active tags. You can use the APIs to initialize the active tag chip and read and write active tags. The **connectedTag** module provides APIs for using active tags. You can use the APIs to initialize the active tag chip and read and write active tags.
...@@ -129,7 +129,7 @@ Writes data to this active tag. This API uses a promise to return the result. ...@@ -129,7 +129,7 @@ Writes data to this active tag. This API uses a promise to return the result.
```js ```js
import connectedTag from '@ohos.connectedTag'; import connectedTag from '@ohos.connectedTag';
var rawData = "010203"; // change it tobe correct. var rawData = "010203"; // Set it as required.
connectedTag.writeNdefTag(rawData).then(() => { connectedTag.writeNdefTag(rawData).then(() => {
console.log("connectedTag writeNdefTag Promise success."); console.log("connectedTag writeNdefTag Promise success.");
}).catch((err)=> { }).catch((err)=> {
...@@ -159,7 +159,7 @@ Writes data to this active tag. This API uses an asynchronous callback to return ...@@ -159,7 +159,7 @@ Writes data to this active tag. This API uses an asynchronous callback to return
```js ```js
import connectedTag from '@ohos.connectedTag'; import connectedTag from '@ohos.connectedTag';
var rawData = "010203"; // change it tobe correct. var rawData = "010203"; // Set it as required.
connectedTag.writeNdefTag(rawData, (err)=> { connectedTag.writeNdefTag(rawData, (err)=> {
if (err) { if (err) {
console.log("connectedTag writeNdefTag AsyncCallback err: " + err); console.log("connectedTag writeNdefTag AsyncCallback err: " + err);
...@@ -220,7 +220,7 @@ connectedTag.on("notify", (err, rfState)=> { ...@@ -220,7 +220,7 @@ connectedTag.on("notify", (err, rfState)=> {
var initStatus = connectedTag.init(); var initStatus = connectedTag.init();
console.log("connectedTag init status: " + initStatus); console.log("connectedTag init status: " + initStatus);
// Add nfc connecected tag business oprations here... // Add NFC connected tag business operations here.
// connectedTag.writeNdefTag(rawData) // connectedTag.writeNdefTag(rawData)
// connectedTag.readNdefTag() // connectedTag.readNdefTag()
......
# @ohos.account.distributedAccount # @ohos.account.distributedAccount (Distributed Account Management)
The **distributedAccount** module provides APIs for managing distributed accounts, including querying and updating account login states. The **distributedAccount** module provides APIs for managing distributed accounts, including querying and updating account login states.
...@@ -252,7 +252,7 @@ Sets the distributed account information. This API uses a promise to return the ...@@ -252,7 +252,7 @@ Sets the distributed account information. This API uses a promise to return the
updateOsAccountDistributedInfo(accountInfo: DistributedInfo, callback: AsyncCallback&lt;void&gt;): void updateOsAccountDistributedInfo(accountInfo: DistributedInfo, callback: AsyncCallback&lt;void&gt;): void
Updates distributed account information. This API uses an asynchronous callback to return the result. Updates the distributed account information. This API uses an asynchronous callback to return the result.
> **NOTE** > **NOTE**
> >
......
# Standard NFC # @ohos.nfc.controller (Standard NFC)
The **nfcController** module provides APIs for opening and closing Near-Field Communication (NFC) and reading the NFC state. The **nfcController** module provides APIs for opening and closing Near-Field Communication (NFC) and reading the NFC state.
> **NOTE**<br> > **NOTE**
>
> 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. > 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.
## **Modules to Import** ## **Modules to Import**
``` ```js
import controller from '@ohos.nfc.controller'; import controller from '@ohos.nfc.controller';
``` ```
...@@ -18,7 +18,7 @@ Enumerates the NFC states. ...@@ -18,7 +18,7 @@ Enumerates the NFC states.
**System capability**: SystemCapability.Communication.NFC.Core **System capability**: SystemCapability.Communication.NFC.Core
| Name| Default Value| Description| | Name| Value| Description|
| -------- | -------- | -------- | | -------- | -------- | -------- |
| STATE_OFF | 1 | NFC is closed (OFF).| | STATE_OFF | 1 | NFC is closed (OFF).|
| STATE_TURNING_ON | 2 | NFC is turning on.| | STATE_TURNING_ON | 2 | NFC is turning on.|
...@@ -31,6 +31,10 @@ isNfcAvailable(): boolean ...@@ -31,6 +31,10 @@ isNfcAvailable(): boolean
Checks whether the device supports NFC. Checks whether the device supports NFC.
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use canIUse("SystemCapability.Communication.NFC.Core").
**System capability**: SystemCapability.Communication.NFC.Core **System capability**: SystemCapability.Communication.NFC.Core
**Return value** **Return value**
...@@ -46,6 +50,10 @@ openNfc(): boolean ...@@ -46,6 +50,10 @@ openNfc(): boolean
Opens NFC. Opens NFC.
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [enableNfc](#controllerenablenfc9).
**Required permissions**: ohos.permission.MANAGE_SECURE_SETTINGS **Required permissions**: ohos.permission.MANAGE_SECURE_SETTINGS
**System capability**: SystemCapability.Communication.NFC.Core **System capability**: SystemCapability.Communication.NFC.Core
...@@ -56,12 +64,34 @@ Opens NFC. ...@@ -56,12 +64,34 @@ Opens NFC.
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
## controller.enableNfc<sup>9+</sup>
enableNfc(): boolean
Enables NFC.
**Required permissions**: ohos.permission.MANAGE_SECURE_SETTINGS
**System capability**: SystemCapability.Communication.NFC.Core
**Error codes**
For details about the error codes, see [NFC Error Codes](../errorcodes/errorcode-nfc.md).
| ID| Error Message|
| ------- | -------|
| 3100101 | NFC state is abnormal in service. |
## controller.closeNfc ## controller.closeNfc
closeNfc(): boolean closeNfc(): boolean
Closes NFC. Closes NFC.
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [disableNfc](#controllerdisablenfc9).
**Required permissions**: ohos.permission.MANAGE_SECURE_SETTINGS **Required permissions**: ohos.permission.MANAGE_SECURE_SETTINGS
**System capability**: SystemCapability.Communication.NFC.Core **System capability**: SystemCapability.Communication.NFC.Core
...@@ -72,6 +102,24 @@ Closes NFC. ...@@ -72,6 +102,24 @@ Closes NFC.
| -------- | ------------------------------------------- | | -------- | ------------------------------------------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
## controller.disableNfc<sup>9+</sup>
disableNfc(): boolean
Disables NFC.
**Required permissions**: ohos.permission.MANAGE_SECURE_SETTINGS
**System capability**: SystemCapability.Communication.NFC.Core
**Error codes**
For details about the error codes, see [NFC Error Codes](../errorcodes/errorcode-nfc.md).
| ID| Error Message|
| ------- | -------|
| 3100101 | NFC state is abnormal in service. |
## controller.isNfcOpen ## controller.isNfcOpen
isNfcOpen(): boolean isNfcOpen(): boolean
...@@ -108,14 +156,12 @@ Subscribes to NFC state changes. A callback will be invoked to return the NFC st ...@@ -108,14 +156,12 @@ Subscribes to NFC state changes. A callback will be invoked to return the NFC st
**System capability**: SystemCapability.Communication.NFC.Core **System capability**: SystemCapability.Communication.NFC.Core
**Parameter** **Parameters**
| **Name**| **Type**| **Mandatory**| **Description**| | **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| type | string | Yes| Event type to subscribe to. The value is **nfcStateChange**.| | type | string | Yes| Event type to subscribe to. The value is **nfcStateChange**.|
| callback | Callback&lt;[NfcState](#nfcstate)&gt; | Yes| Callback invoked to return the NFC state.| | callback | Callback&lt;[NfcState](#nfcstate)&gt; | Yes| Callback invoked to return the NFC state.|
## controller.off('nfcStateChange') ## controller.off('nfcStateChange')
...@@ -125,42 +171,55 @@ Unsubscribes from the NFC state changes. The subscriber will not receive NFC sta ...@@ -125,42 +171,55 @@ Unsubscribes from the NFC state changes. The subscriber will not receive NFC sta
**System capability**: SystemCapability.Communication.NFC.Core **System capability**: SystemCapability.Communication.NFC.Core
**Parameter** **Parameters**
| **Name**| **Type**| **Mandatory**| **Description**| | **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| type | string | Yes| Event type to unsubscribe from. The value is **nfcStateChange**.| | type | string | Yes| Event type to unsubscribe from. The value is **nfcStateChange**.|
| callback | Callback&lt;[NfcState](#nfcstate)&gt; | No| Callback for the NFC state changes. This parameter can be left blank.| | callback | Callback&lt;[NfcState](#nfcstate)&gt; | No| Callback for the NFC state changes. This parameter can be left blank.|
**Example** **Example**
```js ```js
import controller from '@ohos.nfc.controller'; import controller from '@ohos.nfc.controller';
// Define a callback key.
var NFC_STATE_CALLBACK_KEY = "nfcStateChange";
// Register the callback to receive NFC state change notifications.
controller.on(NFC_STATE_CALLBACK_KEY, (err, nfcState)=> {
if (err) {
console.log("controller on callback err: " + err);
} else {
console.log("controller on callback nfcState: " + nfcState);
}
});
// Open NFC. Require permission: ohos.permission.MANAGE_SECURE_SETTINGS.
if (!controller.isNfcOpen()) {
var ret = controller.openNfc();
console.log("controller openNfc ret: " + ret);
}
// Close NFC. Require permission: ohos.permission.MANAGE_SECURE_SETTINGS. // Register a callback to receive the NFC state change notification.
if (controller.isNfcOpen()) { controller.on("nfcStateChange", (err, nfcState)=> {
var ret = controller.closeNfc(); if (err) {
console.log("controller closeNfc ret: " + ret); console.log("controller on callback err: " + err);
} else {
console.log("controller on callback nfcState: " + nfcState);
} }
});
// Unregister the callback.
controller.off(NFC_STATE_CALLBACK_KEY); // Open NFC. The ohos.permission.MANAGE_SECURE_SETTINGS permission is required.
``` if (!controller.isNfcOpen()) {
var ret = controller.openNfc();
console.log("controller openNfc ret: " + ret);
}
// Use 'enableNfc' to enable NFC from API version 9.
try {
controller.enableNfc();
console.log("controller enableNfc success");
} catch (busiError) {
console.log("controller enableNfc busiError: " + busiError);
}
// Close NFC. The ohos.permission.MANAGE_SECURE_SETTINGS permission is required.
if (controller.isNfcOpen()) {
var ret = controller.closeNfc();
console.log("controller closeNfc ret: " + ret);
}
// Use 'disableNfc' to disable NFC from API version 9.
try {
controller.disableNfc();
console.log("controller disableNfc success");
} catch (busiError) {
console.log("controller disableNfc busiError: " + busiError);
}
// Unregister the callback.
controller.off("nfcStateChange");
```
# nfctech # nfctech (Standard NFC Technologies)
The **nfctech** module provides APIs for reading and writing tags that use different Near-Field Communication (NFC) technologies. The **nfctech** module provides APIs for reading and writing tags that use different Near-Field Communication (NFC) technologies.
...@@ -26,9 +26,7 @@ getSak(): number ...@@ -26,9 +26,7 @@ getSak(): number
Obtains the SAK value of this NFC-A tag. Obtains the SAK value of this NFC-A tag.
**Required permissions**: ohos.permission.NFC_TAG **System capability**: SystemCapability.Communication.NFC.Tag
**System capability**: SystemCapability.Communication.NFC.Core
**Return value** **Return value**
...@@ -52,9 +50,7 @@ getAtqa(): number[] ...@@ -52,9 +50,7 @@ getAtqa(): number[]
Obtains the ATQA value of this NFC-A tag. Obtains the ATQA value of this NFC-A tag.
**Required permissions**: ohos.permission.NFC_TAG **System capability**: SystemCapability.Communication.NFC.Tag
**System capability**: SystemCapability.Communication.NFC.Core
**Return value** **Return value**
...@@ -86,9 +82,7 @@ getRespAppData(): number[] ...@@ -86,9 +82,7 @@ getRespAppData(): number[]
Obtains the application data of this NFC-B tag. Obtains the application data of this NFC-B tag.
**Required permissions**: ohos.permission.NFC_TAG **System capability**: SystemCapability.Communication.NFC.Tag
**System capability**: SystemCapability.Communication.NFC.Core
**Return value** **Return value**
...@@ -112,9 +106,7 @@ getRespProtocol(): number[] ...@@ -112,9 +106,7 @@ getRespProtocol(): number[]
Obtains the protocol information of this NFC-B tag. Obtains the protocol information of this NFC-B tag.
**Required permissions**: ohos.permission.NFC_TAG **System capability**: SystemCapability.Communication.NFC.Tag
**System capability**: SystemCapability.Communication.NFC.Core
**Return value** **Return value**
...@@ -146,9 +138,7 @@ getSystemCode(): number[] ...@@ -146,9 +138,7 @@ getSystemCode(): number[]
Obtains the system code from this NFC-F tag. Obtains the system code from this NFC-F tag.
**Required permissions**: ohos.permission.NFC_TAG **System capability**: SystemCapability.Communication.NFC.Tag
**System capability**: SystemCapability.Communication.NFC.Core
**Return value** **Return value**
...@@ -172,9 +162,7 @@ getPmm(): number[] ...@@ -172,9 +162,7 @@ getPmm(): number[]
Obtains the PMm (consisting of the IC code and manufacturer parameters) information from this NFC-F tag. Obtains the PMm (consisting of the IC code and manufacturer parameters) information from this NFC-F tag.
**Required permissions**: ohos.permission.NFC_TAG **System capability**: SystemCapability.Communication.NFC.Tag
**System capability**: SystemCapability.Communication.NFC.Core
**Return value** **Return value**
...@@ -206,9 +194,7 @@ getResponseFlags(): number ...@@ -206,9 +194,7 @@ getResponseFlags(): number
Obtains the response flags from this NFC-V tag. Obtains the response flags from this NFC-V tag.
**Required permissions**: ohos.permission.NFC_TAG **System capability**: SystemCapability.Communication.NFC.Tag
**System capability**: SystemCapability.Communication.NFC.Core
**Return value** **Return value**
...@@ -232,9 +218,7 @@ getDsfId(): number ...@@ -232,9 +218,7 @@ getDsfId(): number
Obtains the data storage format identifier (DSFID) from this NFC-V tag. Obtains the data storage format identifier (DSFID) from this NFC-V tag.
**Required permissions**: ohos.permission.NFC_TAG **System capability**: SystemCapability.Communication.NFC.Tag
**System capability**: SystemCapability.Communication.NFC.Core
**Return value** **Return value**
...@@ -266,7 +250,7 @@ getHistoricalBytes(): number[] ...@@ -266,7 +250,7 @@ getHistoricalBytes(): number[]
Obtains the historical bytes for the given tag. This API applies only to the IsoDep cards that use the NFC-A technology. Obtains the historical bytes for the given tag. This API applies only to the IsoDep cards that use the NFC-A technology.
**System capability**: SystemCapability.Communication.NFC.Core **System capability**: SystemCapability.Communication.NFC.Tag
**Return value** **Return value**
...@@ -290,7 +274,7 @@ getHiLayerResponse(): number[] ...@@ -290,7 +274,7 @@ getHiLayerResponse(): number[]
Obtains the higher-layer response bytes for the given tag. This API applies only to the IsoDep cards that use the NFC-B technology. Obtains the higher-layer response bytes for the given tag. This API applies only to the IsoDep cards that use the NFC-B technology.
**System capability**: SystemCapability.Communication.NFC.Core **System capability**: SystemCapability.Communication.NFC.Tag
**Return value** **Return value**
...@@ -316,7 +300,7 @@ Checks whether an extended application protocol data unit (APDU) is supported. T ...@@ -316,7 +300,7 @@ Checks whether an extended application protocol data unit (APDU) is supported. T
**Required permissions**: ohos.permission.NFC_TAG **Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC.Core **System capability**: SystemCapability.Communication.NFC.Tag
**Return value** **Return value**
...@@ -367,7 +351,7 @@ Checks whether an extended APDU is supported. This API uses an asynchronous call ...@@ -367,7 +351,7 @@ Checks whether an extended APDU is supported. This API uses an asynchronous call
**Required permissions**: ohos.permission.NFC_TAG **Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC.Core **System capability**: SystemCapability.Communication.NFC.Tag
**Parameters** **Parameters**
...@@ -419,7 +403,7 @@ getNdefRecords(): [tag.NdefRecord](js-apis-nfcTag.md#ndefrecord9)[] ...@@ -419,7 +403,7 @@ getNdefRecords(): [tag.NdefRecord](js-apis-nfcTag.md#ndefrecord9)[]
Obtains all NDEF records. Obtains all NDEF records.
**System capability**: SystemCapability.Communication.NFC.Core **System capability**: SystemCapability.Communication.NFC.Tag
**Return value** **Return value**
...@@ -454,7 +438,7 @@ getNdefTagType(): [tag.NfcForumType](js-apis-nfcTag.md#nfcforumtype9) ...@@ -454,7 +438,7 @@ getNdefTagType(): [tag.NfcForumType](js-apis-nfcTag.md#nfcforumtype9)
Obtains the NDEF tag type. Obtains the NDEF tag type.
**System capability**: SystemCapability.Communication.NFC.Core **System capability**: SystemCapability.Communication.NFC.Tag
**Return value** **Return value**
...@@ -478,7 +462,7 @@ getNdefMessage(): [NdefMessage](#ndefmessage9) ...@@ -478,7 +462,7 @@ getNdefMessage(): [NdefMessage](#ndefmessage9)
Obtains the NDEF message from this NDEF tag. Obtains the NDEF message from this NDEF tag.
**System capability**: SystemCapability.Communication.NFC.Core **System capability**: SystemCapability.Communication.NFC.Tag
**Return value** **Return value**
...@@ -501,7 +485,7 @@ isNdefWritable(): boolean; ...@@ -501,7 +485,7 @@ isNdefWritable(): boolean;
Check whether this NDEF tag is writable. Before calling the data write API, check whether the write operation is supported. Check whether this NDEF tag is writable. Before calling the data write API, check whether the write operation is supported.
**System capability**: SystemCapability.Communication.NFC.Core **System capability**: SystemCapability.Communication.NFC.Tag
**Return value** **Return value**
...@@ -527,7 +511,7 @@ Reads the NDEF message from this tag. This API uses a promise to return the resu ...@@ -527,7 +511,7 @@ Reads the NDEF message from this tag. This API uses a promise to return the resu
**Required permissions**: ohos.permission.NFC_TAG **Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC.Core **System capability**: SystemCapability.Communication.NFC.Tag
**Return value** **Return value**
...@@ -577,7 +561,7 @@ Reads the NDEF message from this tag. This API uses an asynchronous callback to ...@@ -577,7 +561,7 @@ Reads the NDEF message from this tag. This API uses an asynchronous callback to
**Required permissions**: ohos.permission.NFC_TAG **Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC.Core **System capability**: SystemCapability.Communication.NFC.Tag
**Parameters** **Parameters**
...@@ -629,7 +613,7 @@ Writes an NDEF message to this tag. This API uses a promise to return the result ...@@ -629,7 +613,7 @@ Writes an NDEF message to this tag. This API uses a promise to return the result
**Required permissions**: ohos.permission.NFC_TAG **Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC.Core **System capability**: SystemCapability.Communication.NFC.Tag
**Parameters** **Parameters**
...@@ -682,7 +666,7 @@ Writes an NDEF message to this tag. This API uses an asynchronous callback to re ...@@ -682,7 +666,7 @@ Writes an NDEF message to this tag. This API uses an asynchronous callback to re
**Required permissions**: ohos.permission.NFC_TAG **Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC.Core **System capability**: SystemCapability.Communication.NFC.Tag
**Parameters** **Parameters**
...@@ -738,7 +722,7 @@ Checks whether this NDEF tag can be set to read-only. ...@@ -738,7 +722,7 @@ Checks whether this NDEF tag can be set to read-only.
**Required permissions**: ohos.permission.NFC_TAG **Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC.Core **System capability**: SystemCapability.Communication.NFC.Tag
**Return value** **Return value**
...@@ -772,7 +756,7 @@ Sets this NDEF tag to read-only. This API uses a promise to return the result. ...@@ -772,7 +756,7 @@ Sets this NDEF tag to read-only. This API uses a promise to return the result.
**Required permissions**: ohos.permission.NFC_TAG **Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC.Core **System capability**: SystemCapability.Communication.NFC.Tag
**Error codes** **Error codes**
...@@ -816,7 +800,7 @@ Sets this NDEF tag to read-only. This API uses an asynchronous callback to retur ...@@ -816,7 +800,7 @@ Sets this NDEF tag to read-only. This API uses an asynchronous callback to retur
**Required permissions**: ohos.permission.NFC_TAG **Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC.Core **System capability**: SystemCapability.Communication.NFC.Tag
**Parameters** **Parameters**
...@@ -866,7 +850,7 @@ getNdefTagTypeString(type: [tag.NfcForumType](js-apis-nfcTag.md#nfcforumtype9)): ...@@ -866,7 +850,7 @@ getNdefTagTypeString(type: [tag.NfcForumType](js-apis-nfcTag.md#nfcforumtype9)):
Converts an NFC Forum Type tag to a string defined in the NFC Forum. Converts an NFC Forum Type tag to a string defined in the NFC Forum.
**System capability**: SystemCapability.Communication.NFC.Core **System capability**: SystemCapability.Communication.NFC.Tag
**Parameters** **Parameters**
...@@ -911,7 +895,7 @@ Authenticates a sector using a key. The sector can be accessed only after the au ...@@ -911,7 +895,7 @@ Authenticates a sector using a key. The sector can be accessed only after the au
**Required permissions**: ohos.permission.NFC_TAG **Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC.Core **System capability**: SystemCapability.Communication.NFC.Tag
**Parameters** **Parameters**
...@@ -965,7 +949,7 @@ Authenticates a sector using a key. The sector can be accessed only after the au ...@@ -965,7 +949,7 @@ Authenticates a sector using a key. The sector can be accessed only after the au
**Required permissions**: ohos.permission.NFC_TAG **Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC.Core **System capability**: SystemCapability.Communication.NFC.Tag
**Parameters** **Parameters**
...@@ -1021,7 +1005,7 @@ Reads a block (16 bytes) on this tag. This API uses a promise to return the resu ...@@ -1021,7 +1005,7 @@ Reads a block (16 bytes) on this tag. This API uses a promise to return the resu
**Required permissions**: ohos.permission.NFC_TAG **Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC.Core **System capability**: SystemCapability.Communication.NFC.Tag
**Parameters** **Parameters**
...@@ -1078,14 +1062,14 @@ Reads a block (16 bytes) on this tag. This API uses an asynchronous callback to ...@@ -1078,14 +1062,14 @@ Reads a block (16 bytes) on this tag. This API uses an asynchronous callback to
**Required permissions**: ohos.permission.NFC_TAG **Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC.Core **System capability**: SystemCapability.Communication.NFC.Tag
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ----------------------- | ---- | -------------------------------------- | | -------- | ----------------------- | ---- | -------------------------------------- |
| blockIndex | number | Yes | Index of the block to read. The block indexes start from **0**.| | blockIndex | number | Yes | Index of the block to read. The block indexes start from **0**.|
| callback | AsyncCallback\<number[]> | Yes | Callback invoked to return the block read.| | callback | AsyncCallback\<number[]> | Yes | Callback invoked to return the data read.|
**Error codes** **Error codes**
...@@ -1132,7 +1116,7 @@ Writes data to a block on this tag. This API uses a promise to return the result ...@@ -1132,7 +1116,7 @@ Writes data to a block on this tag. This API uses a promise to return the result
**Required permissions**: ohos.permission.NFC_TAG **Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC.Core **System capability**: SystemCapability.Communication.NFC.Tag
**Parameters** **Parameters**
...@@ -1186,7 +1170,7 @@ Writes data to a block on this tag. This API uses an asynchronous callback to re ...@@ -1186,7 +1170,7 @@ Writes data to a block on this tag. This API uses an asynchronous callback to re
**Required permissions**: ohos.permission.NFC_TAG **Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC.Core **System capability**: SystemCapability.Communication.NFC.Tag
**Parameters** **Parameters**
...@@ -1243,7 +1227,7 @@ Increments a block with data. This API uses a promise to return the result. ...@@ -1243,7 +1227,7 @@ Increments a block with data. This API uses a promise to return the result.
**Required permissions**: ohos.permission.NFC_TAG **Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC.Core **System capability**: SystemCapability.Communication.NFC.Tag
**Parameters** **Parameters**
...@@ -1296,7 +1280,7 @@ Increments a block with data. This API uses an asynchronous callback to return t ...@@ -1296,7 +1280,7 @@ Increments a block with data. This API uses an asynchronous callback to return t
**Required permissions**: ohos.permission.NFC_TAG **Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC.Core **System capability**: SystemCapability.Communication.NFC.Tag
**Parameters** **Parameters**
...@@ -1352,7 +1336,7 @@ Decrements a block. This API uses a promise to return the result. ...@@ -1352,7 +1336,7 @@ Decrements a block. This API uses a promise to return the result.
**Required permissions**: ohos.permission.NFC_TAG **Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC.Core **System capability**: SystemCapability.Communication.NFC.Tag
**Parameters** **Parameters**
...@@ -1405,7 +1389,7 @@ Decrements a block. This API uses an asynchronous callback to return the result. ...@@ -1405,7 +1389,7 @@ Decrements a block. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.NFC_TAG **Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC.Core **System capability**: SystemCapability.Communication.NFC.Tag
**Parameters** **Parameters**
...@@ -1461,7 +1445,7 @@ Transfers data from the temporary register to a block. This API uses a promise t ...@@ -1461,7 +1445,7 @@ Transfers data from the temporary register to a block. This API uses a promise t
**Required permissions**: ohos.permission.NFC_TAG **Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC.Core **System capability**: SystemCapability.Communication.NFC.Tag
**Parameters** **Parameters**
...@@ -1512,7 +1496,7 @@ Transfers data from the temporary register to a block. This API uses an asynchro ...@@ -1512,7 +1496,7 @@ Transfers data from the temporary register to a block. This API uses an asynchro
**Required permissions**: ohos.permission.NFC_TAG **Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC.Core **System capability**: SystemCapability.Communication.NFC.Tag
**Parameters** **Parameters**
...@@ -1566,7 +1550,7 @@ Restores data in the temporary register from a block. This API uses a promise to ...@@ -1566,7 +1550,7 @@ Restores data in the temporary register from a block. This API uses a promise to
**Required permissions**: ohos.permission.NFC_TAG **Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC.Core **System capability**: SystemCapability.Communication.NFC.Tag
**Parameters** **Parameters**
...@@ -1617,7 +1601,7 @@ Restores data in the temporary register from a block. This API uses an asynchron ...@@ -1617,7 +1601,7 @@ Restores data in the temporary register from a block. This API uses an asynchron
**Required permissions**: ohos.permission.NFC_TAG **Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC.Core **System capability**: SystemCapability.Communication.NFC.Tag
**Parameters** **Parameters**
...@@ -1669,7 +1653,7 @@ getSectorCount(): number ...@@ -1669,7 +1653,7 @@ getSectorCount(): number
Obtains the number of sectors in this MIFARE Classic tag. Obtains the number of sectors in this MIFARE Classic tag.
**System capability**: SystemCapability.Communication.NFC.Core **System capability**: SystemCapability.Communication.NFC.Tag
**Return value** **Return value**
...@@ -1693,7 +1677,7 @@ getBlockCountInSector(sectorIndex: number): number ...@@ -1693,7 +1677,7 @@ getBlockCountInSector(sectorIndex: number): number
Obtains the number of blocks in a sector. Obtains the number of blocks in a sector.
**System capability**: SystemCapability.Communication.NFC.Core **System capability**: SystemCapability.Communication.NFC.Tag
**Parameters** **Parameters**
...@@ -1729,7 +1713,7 @@ getType(): [tag.MifareClassicType](js-apis-nfcTag.md#mifareclassictype9) ...@@ -1729,7 +1713,7 @@ getType(): [tag.MifareClassicType](js-apis-nfcTag.md#mifareclassictype9)
Obtains the type of this MIFARE Classic tag. Obtains the type of this MIFARE Classic tag.
**System capability**: SystemCapability.Communication.NFC.Core **System capability**: SystemCapability.Communication.NFC.Tag
**Return value** **Return value**
...@@ -1753,7 +1737,7 @@ getTagSize(): number ...@@ -1753,7 +1737,7 @@ getTagSize(): number
Obtains the size of this tag. For details, see [MifareClassicSize](js-apis-nfcTag.md#mifareclassicsize9). Obtains the size of this tag. For details, see [MifareClassicSize](js-apis-nfcTag.md#mifareclassicsize9).
**System capability**: SystemCapability.Communication.NFC.Core **System capability**: SystemCapability.Communication.NFC.Tag
**Return value** **Return value**
...@@ -1777,7 +1761,7 @@ isEmulatedTag(): boolean ...@@ -1777,7 +1761,7 @@ isEmulatedTag(): boolean
Checks whether it is an emulated tag. Checks whether it is an emulated tag.
**System capability**: SystemCapability.Communication.NFC.Core **System capability**: SystemCapability.Communication.NFC.Tag
**Return value** **Return value**
...@@ -1801,7 +1785,7 @@ getBlockIndex(sectorIndex: number): number ...@@ -1801,7 +1785,7 @@ getBlockIndex(sectorIndex: number): number
Obtains the index of the first block in a sector. Obtains the index of the first block in a sector.
**System capability**: SystemCapability.Communication.NFC.Core **System capability**: SystemCapability.Communication.NFC.Tag
**Parameters** **Parameters**
...@@ -1835,9 +1819,9 @@ try { ...@@ -1835,9 +1819,9 @@ try {
getSectorIndex(blockIndex: number): number getSectorIndex(blockIndex: number): number
Obtains the index of a sector that holds the specified block. Obtains the index of the sector that holds the specified block.
**System capability**: SystemCapability.Communication.NFC.Core **System capability**: SystemCapability.Communication.NFC.Tag
**Parameters** **Parameters**
...@@ -1883,7 +1867,7 @@ Reads four pages (4 bytes per page) from this tag. This API uses a promise to re ...@@ -1883,7 +1867,7 @@ Reads four pages (4 bytes per page) from this tag. This API uses a promise to re
**Required permissions**: ohos.permission.NFC_TAG **Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC.Core **System capability**: SystemCapability.Communication.NFC.Tag
**Parameters** **Parameters**
...@@ -1941,7 +1925,7 @@ Reads four pages (4 bytes per page) from this tag. This API uses an asynchronous ...@@ -1941,7 +1925,7 @@ Reads four pages (4 bytes per page) from this tag. This API uses an asynchronous
**Required permissions**: ohos.permission.NFC_TAG **Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC.Core **System capability**: SystemCapability.Communication.NFC.Tag
**Parameters** **Parameters**
...@@ -1995,7 +1979,7 @@ Writes one page (4 bytes) of data to this tag. This API uses a promise to return ...@@ -1995,7 +1979,7 @@ Writes one page (4 bytes) of data to this tag. This API uses a promise to return
**Required permissions**: ohos.permission.NFC_TAG **Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC.Core **System capability**: SystemCapability.Communication.NFC.Tag
**Parameters** **Parameters**
...@@ -2048,7 +2032,7 @@ Writes one page (4 bytes) of data to this tag. This API uses an asynchronous cal ...@@ -2048,7 +2032,7 @@ Writes one page (4 bytes) of data to this tag. This API uses an asynchronous cal
**Required permissions**: ohos.permission.NFC_TAG **Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC.Core **System capability**: SystemCapability.Communication.NFC.Tag
**Parameters** **Parameters**
...@@ -2102,7 +2086,7 @@ getType(): [tag.MifareUltralightType](js-apis-nfcTag.md#mifareultralighttype9) ...@@ -2102,7 +2086,7 @@ getType(): [tag.MifareUltralightType](js-apis-nfcTag.md#mifareultralighttype9)
Obtains the type of this MIFARE Ultralight tag. Obtains the type of this MIFARE Ultralight tag.
**System capability**: SystemCapability.Communication.NFC.Core **System capability**: SystemCapability.Communication.NFC.Tag
**Return value** **Return value**
...@@ -2136,7 +2120,7 @@ Formats this tag as an NDEF tag, and writes an NDEF message to it. This API uses ...@@ -2136,7 +2120,7 @@ Formats this tag as an NDEF tag, and writes an NDEF message to it. This API uses
**Required permissions**: ohos.permission.NFC_TAG **Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC.Core **System capability**: SystemCapability.Communication.NFC.Tag
**Parameters** **Parameters**
...@@ -2190,7 +2174,7 @@ Formats this tag as an NDEF tag, and writes an NDEF message to it. This API uses ...@@ -2190,7 +2174,7 @@ Formats this tag as an NDEF tag, and writes an NDEF message to it. This API uses
**Required permissions**: ohos.permission.NFC_TAG **Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC.Core **System capability**: SystemCapability.Communication.NFC.Tag
**Parameters** **Parameters**
...@@ -2245,7 +2229,7 @@ Formats this tag as an NDEF tag, writes an NDEF message to it, and then sets the ...@@ -2245,7 +2229,7 @@ Formats this tag as an NDEF tag, writes an NDEF message to it, and then sets the
**Required permissions**: ohos.permission.NFC_TAG **Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC.Core **System capability**: SystemCapability.Communication.NFC.Tag
**Parameters** **Parameters**
...@@ -2299,7 +2283,7 @@ Formats this tag as an NDEF tag, writes an NDEF message to the NDEF tag, and the ...@@ -2299,7 +2283,7 @@ Formats this tag as an NDEF tag, writes an NDEF message to the NDEF tag, and the
**Required permissions**: ohos.permission.NFC_TAG **Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC.Core **System capability**: SystemCapability.Communication.NFC.Tag
**Parameters** **Parameters**
......
# @ohos.account.osAccount # @ohos.account.osAccount (OS Account Management)
The **osAccount** module provides basic capabilities for managing OS accounts, including adding, deleting, querying, setting, subscribing to, and enabling an OS account. The **osAccount** module provides basic capabilities for managing OS accounts, including adding, deleting, querying, setting, subscribing to, and enabling an OS account.
...@@ -155,7 +155,7 @@ Checks whether multiple OS accounts are supported. This API uses an asynchronous ...@@ -155,7 +155,7 @@ Checks whether multiple OS accounts are supported. This API uses an asynchronous
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ---------------------------- | ---- | ------------------------------------------------------ | | -------- | ---------------------------- | ---- | ------------------------------------------------------ |
| callback | AsyncCallback&lt;boolean&gt; | Yes | Callback invoked to return the result. The value **true** means multiple OS accounts are supported; the value false means the opposite.| | callback | AsyncCallback&lt;boolean&gt; | Yes | Callback invoked to return the result. The value **true** means multiple OS accounts are supported; the value **false** means the opposite.|
**Error codes** **Error codes**
...@@ -192,7 +192,7 @@ Checks whether multiple OS accounts are supported. This API uses a promise to re ...@@ -192,7 +192,7 @@ Checks whether multiple OS accounts are supported. This API uses a promise to re
| Type | Description | | Type | Description |
| :--------------------- | :--------------------------------------------------------- | | :--------------------- | :--------------------------------------------------------- |
| Promise&lt;boolean&gt; | Promise used to return the result. The value **true** means multiple OS accounts are supported; the value false means the opposite.| | Promise&lt;boolean&gt; | Promise used to return the result. The value **true** means multiple OS accounts are supported; the value **false** means the opposite.|
**Error codes** **Error codes**
...@@ -483,7 +483,7 @@ Checks whether this OS account has been verified. This API uses an asynchronous ...@@ -483,7 +483,7 @@ Checks whether this OS account has been verified. This API uses an asynchronous
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ---------------------------- | ---- | ------------------------------------------------------------- | | -------- | ---------------------------- | ---- | ------------------------------------------------------------- |
| callback | AsyncCallback&lt;boolean&gt; | Yes | Callback invoked to return the result. If true is returned, the current account has been verified. If false is returned, the current account has not been verified.| | callback | AsyncCallback&lt;boolean&gt; | Yes | Callback invoked to return the result. The value **true** means the OS account has been verified; the value **false** means the opposite.|
**Error codes** **Error codes**
...@@ -1690,7 +1690,7 @@ Creates an OS account and associates it with the specified domain account. This ...@@ -1690,7 +1690,7 @@ Creates an OS account and associates it with the specified domain account. This
| Type | Description | | Type | Description |
| ---------------------------------------------- | -------------------------------------- | | ---------------------------------------------- | -------------------------------------- |
| Promise&lt;[OsAccountInfo](#osaccountinfo)&gt; | Promise used to return the OS account created.| | Promise&lt;[OsAccountInfo](#osaccountinfo)&gt; | Promise used to return the information about the created OS account.|
**Error codes** **Error codes**
...@@ -2709,6 +2709,7 @@ Obtains the constraint source information of an OS account. This API uses a prom ...@@ -2709,6 +2709,7 @@ Obtains the constraint source information of an OS account. This API uses a prom
console.info('queryOsAccountConstraintSourceType exception:' + JSON.stringify(e)); console.info('queryOsAccountConstraintSourceType exception:' + JSON.stringify(e));
} }
``` ```
### isMultiOsAccountEnable<sup>(deprecated)</sup> ### isMultiOsAccountEnable<sup>(deprecated)</sup>
isMultiOsAccountEnable(callback: AsyncCallback&lt;boolean&gt;): void isMultiOsAccountEnable(callback: AsyncCallback&lt;boolean&gt;): void
...@@ -2725,7 +2726,7 @@ Checks whether multiple OS accounts are supported. This API uses an asynchronous ...@@ -2725,7 +2726,7 @@ Checks whether multiple OS accounts are supported. This API uses an asynchronous
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ---------------------------- | ---- | ------------------------------------------------------ | | -------- | ---------------------------- | ---- | ------------------------------------------------------ |
| callback | AsyncCallback&lt;boolean&gt; | Yes | Callback invoked to return the result. The value **true** means multiple OS accounts are supported; the value false means the opposite.| | callback | AsyncCallback&lt;boolean&gt; | Yes | Callback invoked to return the result. The value **true** means multiple OS accounts are supported; the value **false** means the opposite.|
**Example** **Example**
...@@ -2756,7 +2757,7 @@ Checks whether multiple OS accounts are supported. This API uses a promise to re ...@@ -2756,7 +2757,7 @@ Checks whether multiple OS accounts are supported. This API uses a promise to re
| Type | Description | | Type | Description |
| :--------------------- | :--------------------------------------------------------- | | :--------------------- | :--------------------------------------------------------- |
| Promise&lt;boolean&gt; | Promise used to return the result. The value **true** means multiple OS accounts are supported; the value false means the opposite.| | Promise&lt;boolean&gt; | Promise used to return the result. The value **true** means multiple OS accounts are supported; the value **false** means the opposite.|
**Example** **Example**
...@@ -3694,7 +3695,7 @@ Obtains the OS account ID based on the SN. This API uses an asynchronous callbac ...@@ -3694,7 +3695,7 @@ Obtains the OS account ID based on the SN. This API uses an asynchronous callbac
getOsAccountLocalIdBySerialNumber(serialNumber: number): Promise&lt;number&gt; getOsAccountLocalIdBySerialNumber(serialNumber: number): Promise&lt;number&gt;
Obtains the OS account ID based on the SN. This API uses a promise to return the result. Obtains the OS account ID based on the serial number. This API uses a promise to return the result.
> **NOTE** > **NOTE**
> >
...@@ -4360,7 +4361,7 @@ Register a credential inputer. ...@@ -4360,7 +4361,7 @@ Register a credential inputer.
let authType = account_osAccount.AuthType.DOMAIN; let authType = account_osAccount.AuthType.DOMAIN;
let password = new Uint8Array([0, 0, 0, 0, 0]); let password = new Uint8Array([0, 0, 0, 0, 0]);
try { try {
InputerMgr.registerInputer(authType, { inputerMgr.registerInputer(authType, {
onGetData: (authSubType, callback) => { onGetData: (authSubType, callback) => {
callback.onSetData(authSubType, password); callback.onSetData(authSubType, password);
} }
......
# tagSession # tagSession (Standard NFC Tag Session)
The **tagSession** module provides common APIs for establishing connections and transferring data. The **tagSession** module provides common APIs for establishing connections and transferring data.
...@@ -26,9 +26,12 @@ getTagInfo(): tag.TagInfo ...@@ -26,9 +26,12 @@ getTagInfo(): tag.TagInfo
Obtains the **tagInfo** object provided by the NFC service when the tag is dispatched. Obtains the **tagInfo** object provided by the NFC service when the tag is dispatched.
> **NOTE**
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [tag.getTagInfo](js-apis-nfcTag.md#taggettaginfo9).
**Required permissions**: ohos.permission.NFC_TAG **Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC.Core **System capability**: SystemCapability.Communication.NFC.Tag
**Return value** **Return value**
...@@ -54,9 +57,12 @@ connectTag(): boolean; ...@@ -54,9 +57,12 @@ connectTag(): boolean;
Connects to this tag. Call this API to set up a connection before reading data from or writing data to a tag. Connects to this tag. Call this API to set up a connection before reading data from or writing data to a tag.
> **NOTE**
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [tagSession.connect](#tagsessionconnect9).
**Required permissions**: ohos.permission.NFC_TAG **Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC.Core **System capability**: SystemCapability.Communication.NFC.Tag
**Return value** **Return value**
...@@ -76,15 +82,52 @@ let connectStatus = tag.getIsoDep(tagInfo).connectTag(); ...@@ -76,15 +82,52 @@ let connectStatus = tag.getIsoDep(tagInfo).connectTag();
console.log("connectStatus: " + connectStatus); console.log("connectStatus: " + connectStatus);
``` ```
### tagSession.connect<sup>9+</sup>
connect(): void;
Connects to this tag. Call this API to set up a connection before reading data from or writing data to a tag.
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC.Tag
**Error codes**
For details about the error codes, see [NFC Error Codes](../errorcodes/errorcode-nfc.md).
| ID| Error Message|
| ------- | -------|
| 3100201 | Tag running state is abnormal in service. |
**Example**
```js
import tag from '@ohos.nfc.tag';
// tagInfo is an object provided by the NFC service when a tag is dispatched.
// getXXX can be getIsoDep, getNdef, getMifareClassic, or any other getter for NFC tags.
try {
tag.getIsoDep(tagInfo).connect();
console.log("tag connect success");
} catch (busiError) {
console.log("tag connect busiError: " + busiError);
}
```
### tagSession.reset() ### tagSession.reset()
reset(): void reset(): void
Resets the connection to this tag. Resets the connection to this tag.
> **NOTE**
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [tagSession.resetConnection](#tagsessionresetconnection9).
**Required permissions**: ohos.permission.NFC_TAG **Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC.Core **System capability**: SystemCapability.Communication.NFC.Tag
**Example** **Example**
...@@ -97,15 +140,52 @@ import tag from '@ohos.nfc.tag'; ...@@ -97,15 +140,52 @@ import tag from '@ohos.nfc.tag';
tag.getIsoDep(tagInfo).reset(); tag.getIsoDep(tagInfo).reset();
``` ```
### tagSession.resetConnection()<sup>9+</sup>
resetConnection(): void
Resets the connection to this tag.
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC.Tag
**Error codes**
For details about the error codes, see [NFC Error Codes](../errorcodes/errorcode-nfc.md).
| ID| Error Message|
| ------- | -------|
| 3100201 | Tag running state is abnormal in service. |
**Example**
```js
import tag from '@ohos.nfc.tag';
// tagInfo is an object provided by the NFC service when a tag is dispatched.
// getXXX can be getIsoDep, getNdef, getMifareClassic, or any other getter for NFC tags.
try {
tag.getIsoDep(tagInfo).resetConnection();
console.log("tag resetConnection success");
} catch (busiError) {
console.log("tag resetConnection busiError: " + busiError);
}
```
### tagSession.isTagConnected ### tagSession.isTagConnected
isTagConnected(): boolean isTagConnected(): boolean
Checks whether the tag is connected. Checks whether the tag is connected.
> **NOTE**
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [tagSession.isConnected](#tagsessionisconnected9).
**Required permissions**: ohos.permission.NFC_TAG **Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC.Core **System capability**: SystemCapability.Communication.NFC.Tag
**Return value** **Return value**
...@@ -125,15 +205,50 @@ let isTagConnected = tag.getIsoDep(tagInfo).isTagConnected(); ...@@ -125,15 +205,50 @@ let isTagConnected = tag.getIsoDep(tagInfo).isTagConnected();
console.log("isTagConnected: " + isTagConnected); console.log("isTagConnected: " + isTagConnected);
``` ```
### tagSession.isConnected<sup>9+</sup>
isConnected(): boolean
Checks whether the tag is connected.
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC.Tag
**Return value**
| **Type**| **Description** |
| ------------------ | --------------------------|
| boolean | Returns **true** if the tag is connected; returns **false** otherwise.|
**Example**
```js
import tag from '@ohos.nfc.tag';
// tagInfo is an object provided by the NFC service when a tag is dispatched.
// getXXX can be getIsoDep, getNdef, getMifareClassic, or any other getter for NFC tags.
try {
var isConnected = tag.getIsoDep(tagInfo).isConnected();
console.log("tag isConnected = " + isConnected);
} catch (busiError) {
console.log("tag isConnected busiError: " + busiError);
}
```
### tagSession.getMaxSendLength ### tagSession.getMaxSendLength
getMaxSendLength(): number getMaxSendLength(): number
Obtains the maximum length of the data that can be sent to this tag. Obtains the maximum length of the data that can be sent to this tag.
> **NOTE**
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [tagSession.getMaxTransmitSize](#tagsessiongetmaxtransmitsize9).
**Required permissions**: ohos.permission.NFC_TAG **Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC.Core **System capability**: SystemCapability.Communication.NFC.Tag
**Return value** **Return value**
...@@ -152,15 +267,57 @@ let maxSendLen = tag.getIsoDep(tagInfo).getMaxSendLength(); ...@@ -152,15 +267,57 @@ let maxSendLen = tag.getIsoDep(tagInfo).getMaxSendLength();
console.log("tag maxSendLen: " + maxSendLen); console.log("tag maxSendLen: " + maxSendLen);
``` ```
### tagSession.getMaxTransmitSize<sup>9+</sup>
getMaxTransmitSize(): number
Obtains the maximum length of the data that can be sent to this tag.
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC.Tag
**Return value**
| **Type**| **Description** |
| ------------------ | --------------------------|
| number | Maximum data length obtained. The value cannot be a negative number.|
**Error codes**
For details about the error codes, see [NFC Error Codes](../errorcodes/errorcode-nfc.md).
| ID| Error Message|
| ------- | -------|
| 3100201 | Tag running state is abnormal in service. |
**Example**
```js
import tag from '@ohos.nfc.tag';
// tagInfo is an object provided by the NFC service when a tag is dispatched.
// getXXX can be getIsoDep, getNdef, getMifareClassic, or any other getter for NFC tags.
try {
var maxTransmitSize = tag.getIsoDep(tagInfo).getMaxTransmitSize();
console.log("tag maxTransmitSize = " + maxTransmitSize);
} catch (busiError) {
console.log("tag getMaxTransmitSize busiError: " + busiError);
}
```
### tagSession.getSendDataTimeout ### tagSession.getSendDataTimeout
getSendDataTimeout(): number getSendDataTimeout(): number
Obtains the timeout period for sending data to this tag, in milliseconds. Obtains the timeout period for sending data to this tag, in milliseconds.
> **NOTE**
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [tagSession.getTimeout](#tagsessiongettimeout9).
**Required permissions**: ohos.permission.NFC_TAG **Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC.Core **System capability**: SystemCapability.Communication.NFC.Tag
**Return value** **Return value**
...@@ -180,15 +337,58 @@ let sendDataTimeout = tag.getIsoDep(tagInfo).getSendDataTimeout(); ...@@ -180,15 +337,58 @@ let sendDataTimeout = tag.getIsoDep(tagInfo).getSendDataTimeout();
console.log("tag sendDataTimeout: " + sendDataTimeout); console.log("tag sendDataTimeout: " + sendDataTimeout);
``` ```
### tagSession.getTimeout<sup>9+</sup>
getTimeout(): number
Obtains the timeout period for sending data to this tag, in milliseconds.
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC.Tag
**Return value**
| **Type**| **Description** |
| ------------------ | --------------------------|
| number | Timeout period obtained, in milliseconds. The value cannot be a negative number.|
**Error codes**
For details about the error codes, see [NFC Error Codes](../errorcodes/errorcode-nfc.md).
| ID| Error Message|
| ------- | -------|
| 3100201 | Tag running state is abnormal in service. |
**Example**
```js
import tag from '@ohos.nfc.tag';
// tagInfo is an object provided by the NFC service when a tag is dispatched.
// getXXX can be getIsoDep, getNdef, getMifareClassic, or any other getter for NFC tags.
try {
var timeout = tag.getIsoDep(tagInfo).getTimeout();
console.log("tag timeout = " + timeout);
} catch (busiError) {
console.log("tag getTimeout busiError: " + busiError);
}
```
### tagSession.setSendDataTimeout ### tagSession.setSendDataTimeout
setSendDataTimeout(timeout: number): boolean setSendDataTimeout(timeout: number): boolean
Sets the timeout period for sending data to this tag, in milliseconds. Sets the timeout period for sending data to this tag, in milliseconds.
> **NOTE**
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [tagSession.setTimeout](#tagsessionsettimeout9).
**Required permissions**: ohos.permission.NFC_TAG **Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC.Core **System capability**: SystemCapability.Communication.NFC.Tag
**Parameters** **Parameters**
...@@ -215,15 +415,59 @@ let setStatus = tag.getIsoDep(tagInfo).setSendDataTimeout(timeoutMs); ...@@ -215,15 +415,59 @@ let setStatus = tag.getIsoDep(tagInfo).setSendDataTimeout(timeoutMs);
console.log("tag setSendDataTimeout setStatus: " + setStatus); console.log("tag setSendDataTimeout setStatus: " + setStatus);
``` ```
### tagSession.setTimeout<sup>9+</sup>
setTimeout(timeout: number): void
Sets the timeout period for sending data to this tag, in milliseconds.
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC.Tag
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------- | ---- | -------------------------------------- |
| timeout | number | Yes| Timeout period to set, in milliseconds. The value cannot be a negative number.|
**Error codes**
For details about the error codes, see [NFC Error Codes](../errorcodes/errorcode-nfc.md).
| ID| Error Message|
| ------- | -------|
| 3100201 | Tag running state is abnormal in service. |
**Example**
```js
import tag from '@ohos.nfc.tag';
// tagInfo is an object provided by the NFC service when a tag is dispatched.
// getXXX can be getIsoDep, getNdef, getMifareClassic, or any other getter for NFC tags.
let timeoutMs = 700; // Change it as required.
try {
tag.getIsoDep(tagInfo).setTimeout(timeoutMs);
console.log("tag setTimeout success");
} catch (busiError) {
console.log("tag setTimeout busiError: " + busiError);
}
```
### tagSession.sendData ### tagSession.sendData
sendData(data: number[]): Promise<number[]> sendData(data: number[]): Promise<number[]>
Sends data to this tag. This API uses a promise to return the result. Sends data to this tag. This API uses a promise to return the result.
> **NOTE**
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [tagSession.transmit](#tagsessiontransmit9).
**Required permissions**: ohos.permission.NFC_TAG **Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC.Core **System capability**: SystemCapability.Communication.NFC.Tag
**Parameters** **Parameters**
...@@ -267,9 +511,12 @@ sendData(data: number[], callback: AsyncCallback<number[]>): void ...@@ -267,9 +511,12 @@ sendData(data: number[], callback: AsyncCallback<number[]>): void
Sends data to this tag. This API uses an asynchronous callback to return the result. Sends data to this tag. This API uses an asynchronous callback to return the result.
> **NOTE**
> This parameter is supported since API version 7 and discarded since API version 9. You are advised to use [tagSession.transmit](#tagsessiontransmit9-1).
**Required permissions**: ohos.permission.NFC_TAG **Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC.Core **System capability**: SystemCapability.Communication.NFC.Tag
**Parameters** **Parameters**
...@@ -303,3 +550,123 @@ tag.getIsoDep(tagInfo).sendData(cmdData, (err, response)=> { ...@@ -303,3 +550,123 @@ tag.getIsoDep(tagInfo).sendData(cmdData, (err, response)=> {
} }
}); });
``` ```
### tagSession.transmit<sup>9+</sup>
transmit(data: number[]): Promise<number[]>
Transmits data to this tag. This API uses a promise to return the result.
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC.Tag
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------- | ---- | -------------------------------------- |
| data | number[] | Yes| Data to transmit. The data consists of hexadecimal numbers ranging from **0x00** to **0xFF**. |
**Return value**
| **Type**| **Description** |
| ------------------ | --------------------------|
| Promise<number[]> | Promise used to return the response from the tag. The response consists of hexadecimal numbers ranging from **0x00** to **0xFF**.|
**Error codes**
For details about the error codes, see [NFC Error Codes](../errorcodes/errorcode-nfc.md).
| ID| Error Message|
| ------- | -------|
| 3100201 | Tag running state is abnormal in service. |
**Example**
```js
import tag from '@ohos.nfc.tag';
// tagInfo is an object provided by the NFC service when a tag is dispatched.
// getXXX can be getIsoDep, getNdef, getMifareClassic, or any other getter for NFC tags.
// Connect to the tag if it is not connected.
try {
if (!tag.getIsoDep(tagInfo).isConnected()) {
tag.getIsoDep(tagInfo).connect();
}
} catch (busiError) {
console.log("tag connect busiError: " + busiError);
return;
}
let cmdData = [0x01, 0x02, 0x03, 0x04]; // Change it as required.
try {
tag.getIsoDep(tagInfo).transmit(cmdData).then((response) => {
console.log("tagSession transmit Promise response: " + response);
}).catch((err)=> {
console.log("tagSession transmit Promise err: " + err);
});
} catch (busiError) {
console.log("tag transmit busiError: " + busiError);
return;
}
```
### tagSession.transmit<sup>9+</sup>
transmit(data: number[], callback: AsyncCallback<number[]>): void
Transmits data to this tag. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC.Tag
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------- | ---- | -------------------------------------- |
| data | number[] | Yes| Data to transmit. The data consists of hexadecimal numbers ranging from **0x00** to **0xFF**. |
| callback | AsyncCallback<number[]> | Yes| Callback invoked to return the response from the tag. The response consists of hexadecimal numbers ranging from **0x00** to **0xFF**.|
**Error codes**
For details about the error codes, see [NFC Error Codes](../errorcodes/errorcode-nfc.md).
| ID| Error Message|
| ------- | -------|
| 3100201 | Tag running state is abnormal in service. |
**Example**
```js
import tag from '@ohos.nfc.tag';
// tagInfo is an object provided by the NFC service when a tag is dispatched.
// getXXX can be getIsoDep, getNdef, getMifareClassic, or any other getter for NFC tags.
// Connect to the tag if it is not connected.
try {
if (!tag.getIsoDep(tagInfo).isConnected()) {
tag.getIsoDep(tagInfo).connect();
}
} catch (busiError) {
console.log("tag connect busiError: " + busiError);
return;
}
let cmdData = [0x01, 0x02, 0x03, 0x04]; // Change it as required.
try {
tag.getIsoDep(tagInfo).transmit(cmdData, (err, response)=> {
if (err) {
console.log("tagSession transmit AsyncCallback err: " + err);
} else {
console.log("tagSession transmit AsyncCallback response: " + response);
}
});
} catch (busiError) {
console.log("tag transmit busiError: " + busiError);
return;
}
```
...@@ -263,7 +263,7 @@ Represents the WLAN configuration. ...@@ -263,7 +263,7 @@ Represents the WLAN configuration.
## IpType<sup>7+</sup> ## IpType<sup>7+</sup>
Enumerate the IP address types. Enumerates the IP address types.
**System API**: This is a system API. **System API**: This is a system API.
......
# WLAN # WLAN
The **WLAN** module provides basic wireless local area network (WLAN) functions, peer-to-peer (P2P) functions, and WLAN message notification services. It allows applications to communicate with other devices over WLAN. The **WLAN** module provides basic wireless local area network (WLAN) functions, peer-to-peer (P2P) functions, and WLAN message notification services. It allows applications to communicate with other devices over WLAN.
> **NOTE** > **NOTE**
...@@ -1038,7 +1037,7 @@ Removes the specified network configuration. ...@@ -1038,7 +1037,7 @@ Removes the specified network configuration.
| **Name**| **Type**| **Mandatory**| **Description**| | **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| id | number | Yes| ID of the network configuration to remove.| | id | number | Yes| ID of the network configuration to remove.|
**Return value** **Return value**
...@@ -1788,7 +1787,7 @@ Unregisters the WLAN state change events. ...@@ -1788,7 +1787,7 @@ Unregisters the WLAN state change events.
``` ```
## wifi.on('wifiConnectionChange')<sup>7+</sup> ## wifi.on('wifiConnectionChange')<sup>9+</sup>
on(type: "wifiConnectionChange", callback: Callback&lt;number&gt;): void on(type: "wifiConnectionChange", callback: Callback&lt;number&gt;): void
......
# WLAN Extension Interface # WLAN Extension Interface
This **wifiext** module provides WLAN extension interfaces for non-universal products. This **wifiext** module provides WLAN extension interfaces for non-universal products.
> **NOTE** > **NOTE**
...@@ -26,9 +25,9 @@ Enables the WLAN hotspot. ...@@ -26,9 +25,9 @@ Enables the WLAN hotspot.
**Return value** **Return value**
| **Type**| **Description**| | **Type**| **Description**|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
## wifiext.disableHotspot ## wifiext.disableHotspot
...@@ -43,9 +42,9 @@ Disables the WLAN hotspot. ...@@ -43,9 +42,9 @@ Disables the WLAN hotspot.
**Return value** **Return value**
| **Type**| **Description**| | **Type**| **Description**|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
## wifiext.getSupportedPowerModel ## wifiext.getSupportedPowerModel
...@@ -60,9 +59,9 @@ Obtains the supported power models. This API uses a promise to return the result ...@@ -60,9 +59,9 @@ Obtains the supported power models. This API uses a promise to return the result
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;Array&lt;[PowerModel](#powermodel)&gt;&gt; | Promise used to return the power models obtained.| | Promise&lt;Array&lt;[PowerModel](#powermodel)&gt;&gt; | Promise used to return the power models obtained.|
## PowerModel ## PowerModel
...@@ -90,9 +89,9 @@ Obtains the supported power models. This API uses an asynchronous callback to re ...@@ -90,9 +89,9 @@ Obtains the supported power models. This API uses an asynchronous callback to re
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;Array&lt;[PowerModel](#powermodel)&gt;&gt; | Yes| Callback invoked to return the result. If the operation is successful, **err** is 0 and **data** is the power models obtained. If **err** is not **0**, an error has occurred.| | callback | AsyncCallback&lt;Array&lt;[PowerModel](#powermodel)&gt;&gt; | Yes| Callback invoked to return the result. If the operation is successful, **err** is 0 and **data** is the power models obtained. If **err** is not **0**, an error has occurred.|
## wifiext.getPowerModel ## wifiext.getPowerModel
...@@ -107,9 +106,9 @@ Obtains the power model. This API uses a promise to return the result. ...@@ -107,9 +106,9 @@ Obtains the power model. This API uses a promise to return the result.
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;[PowerModel](#powermodel)&gt; | Promise used to return the power model obtained.| | Promise&lt;[PowerModel](#powermodel)&gt; | Promise used to return the power model obtained.|
## wifiext.getPowerModel ## wifiext.getPowerModel
...@@ -124,16 +123,16 @@ Obtains the power model. This API uses an asynchronous callback to return the re ...@@ -124,16 +123,16 @@ Obtains the power model. This API uses an asynchronous callback to return the re
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;[PowerModel](#powermodel)&gt; | Yes| Callback invoked to return the result. If the operation is successful, **err** is **0** and **data** is the power model obtained. If **err** is not **0**, an error has occurred.| | callback | AsyncCallback&lt;[PowerModel](#powermodel)&gt; | Yes| Callback invoked to return the result. If the operation is successful, **err** is **0** and **data** is the power model obtained. If **err** is not **0**, an error has occurred.|
## wifiext.setPowerModel ## wifiext.setPowerModel
setPowerModel(model: PowerModel) : boolean; setPowerModel(model: PowerModel) : boolean;
Sets the power model. Sets the power model.
**Required permissions**: ohos.permission.MANAGE_WIFI_HOTSPOT_EXT **Required permissions**: ohos.permission.MANAGE_WIFI_HOTSPOT_EXT
...@@ -141,12 +140,12 @@ setPowerModel(model: PowerModel) : boolean; ...@@ -141,12 +140,12 @@ setPowerModel(model: PowerModel) : boolean;
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| model | [PowerModel](#powermodel) | Yes| Power model to set.| | model | [PowerModel](#powermodel) | Yes| Power model to set.|
**Return value** **Return value**
| **Type**| **Description**| | **Type**| **Description**|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
# @ohos.wifiext # @ohos.wifiext (WLAN Extension)
This **wifiext** module provides WLAN extension interfaces for non-universal products. This **wifiext** module provides WLAN extension interfaces for non-universal products.
...@@ -26,9 +26,9 @@ Enables the WLAN hotspot. ...@@ -26,9 +26,9 @@ Enables the WLAN hotspot.
**Return value** **Return value**
| **Type**| **Description**| | **Type**| **Description**|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
## wifiext.disableHotspot ## wifiext.disableHotspot
...@@ -43,9 +43,9 @@ Disables the WLAN hotspot. ...@@ -43,9 +43,9 @@ Disables the WLAN hotspot.
**Return value** **Return value**
| **Type**| **Description**| | **Type**| **Description**|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
## wifiext.getSupportedPowerModel ## wifiext.getSupportedPowerModel
...@@ -60,9 +60,9 @@ Obtains the supported power models. This API uses a promise to return the result ...@@ -60,9 +60,9 @@ Obtains the supported power models. This API uses a promise to return the result
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;Array&lt;[PowerModel](#powermodel)&gt;&gt; | Promise used to return the power models obtained.| | Promise&lt;Array&lt;[PowerModel](#powermodel)&gt;&gt; | Promise used to return the power models obtained.|
## PowerModel ## PowerModel
...@@ -90,9 +90,9 @@ Obtains the supported power models. This API uses an asynchronous callback to re ...@@ -90,9 +90,9 @@ Obtains the supported power models. This API uses an asynchronous callback to re
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;Array&lt;[PowerModel](#powermodel)&gt;&gt; | Yes| Callback invoked to return the result. If the operation is successful, **err** is 0 and **data** is the power models obtained. If **err** is not **0**, an error has occurred.| | callback | AsyncCallback&lt;Array&lt;[PowerModel](#powermodel)&gt;&gt; | Yes| Callback invoked to return the result. If the operation is successful, **err** is 0 and **data** is the power models obtained. If **err** is not **0**, an error has occurred.|
## wifiext.getPowerModel ## wifiext.getPowerModel
...@@ -107,9 +107,9 @@ Obtains the power model. This API uses a promise to return the result. ...@@ -107,9 +107,9 @@ Obtains the power model. This API uses a promise to return the result.
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;[PowerModel](#powermodel)&gt; | Promise used to return the power model obtained.| | Promise&lt;[PowerModel](#powermodel)&gt; | Promise used to return the power model obtained.|
## wifiext.getPowerModel ## wifiext.getPowerModel
...@@ -124,16 +124,16 @@ Obtains the power model. This API uses an asynchronous callback to return the re ...@@ -124,16 +124,16 @@ Obtains the power model. This API uses an asynchronous callback to return the re
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;[PowerModel](#powermodel)&gt; | Yes| Callback invoked to return the result. If the operation is successful, **err** is **0** and **data** is the power model obtained. If **err** is not **0**, an error has occurred.| | callback | AsyncCallback&lt;[PowerModel](#powermodel)&gt; | Yes| Callback invoked to return the result. If the operation is successful, **err** is **0** and **data** is the power model obtained. If **err** is not **0**, an error has occurred.|
## wifiext.setPowerModel ## wifiext.setPowerModel
setPowerModel(model: PowerModel) : boolean; setPowerModel(model: PowerModel) : boolean;
Sets the power model. Sets the power model.
**Required permissions**: ohos.permission.MANAGE_WIFI_HOTSPOT_EXT **Required permissions**: ohos.permission.MANAGE_WIFI_HOTSPOT_EXT
...@@ -141,12 +141,12 @@ setPowerModel(model: PowerModel) : boolean; ...@@ -141,12 +141,12 @@ setPowerModel(model: PowerModel) : boolean;
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| model | [PowerModel](#powermodel) | Yes| Power model to set.| | model | [PowerModel](#powermodel) | Yes| Power model to set.|
**Return value** **Return value**
| **Type**| **Description**| | **Type**| **Description**|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册