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.
...
@@ -3173,7 +3173,7 @@ Set credentials for an app account. This API uses an asynchronous callback to re
...
@@ -3173,7 +3173,7 @@ Set credentials for an app account. This API uses an asynchronous callback to re
| name | string | Yes | Name of the target app account. |
| name | string | Yes | Name of the target app account. |
| credentialType | string | Yes | Type of the credential to delete. |
| credentialType | string | Yes | Type of the credential to set. |
| credential | string | Yes | Credential value. |
| credential | string | Yes | Credential value. |
| callback | AsyncCallback<void> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.|
| callback | AsyncCallback<void> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.|
...
@@ -3203,7 +3203,7 @@ Set credentials for an app account. This API uses a promise to return the result
...
@@ -3203,7 +3203,7 @@ Set credentials for an app account. This API uses a promise to return the result
| Name | Type | Mandatory | Description |
| Name | Type | Mandatory | Description |
| -------------- | ------ | ---- | ---------- |
| -------------- | ------ | ---- | ---------- |
| name | string | Yes | Name of the target app account. |
| name | string | Yes | Name of the target app account. |
| credentialType | string | Yes | Type of the credential to delete.|
| credentialType | string | Yes | Type of the credential to set.|
| credential | string | Yes | Credential value.|
| credential | string | Yes | Credential value.|
**Return value**
**Return value**
...
@@ -3576,7 +3576,7 @@ Obtains the credential of an app account. This API uses an asynchronous callback
...
@@ -3576,7 +3576,7 @@ Obtains the credential of an app account. This API uses an asynchronous callback
| name | string | Yes | Name of the target app account. |
| name | string | Yes | Name of the target app account. |
| credentialType | string | Yes | Type of the credential to delete.|
| credentialType | string | Yes | Type of the credential to obtain.|
| callback | AsyncCallback<string> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is the credential obtained. Otherwise, **err** is an error object.|
| callback | AsyncCallback<string> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is the credential obtained. Otherwise, **err** is an error object.|
**Example**
**Example**
...
@@ -3606,7 +3606,7 @@ Obtains the credential of an app account. This API uses a promise to return the
...
@@ -3606,7 +3606,7 @@ Obtains the credential of an app account. This API uses a promise to return the
| Name | Type | Mandatory | Description |
| Name | Type | Mandatory | Description |
| -------------- | ------ | ---- | ---------- |
| -------------- | ------ | ---- | ---------- |
| name | string | Yes | Name of the target app account. |
| name | string | Yes | Name of the target app account. |
| credentialType | string | Yes | Type of the credential to delete.|
| credentialType | string | Yes | Type of the credential to obtain.|
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.
> **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.
...
@@ -202,7 +203,7 @@ Obtains the connection state of a profile.
...
@@ -202,7 +203,7 @@ Obtains the connection state of a profile.
| MATCH_MODE_AGGRESSIVE | 1 | Hardware reports the scan result with a lower threshold of signal strength and few number of matches in a duration. This is the default value.|
| MATCH_MODE_AGGRESSIVE | 1 | Hardware reports the scan result with a lower threshold of signal strength and few number of matches in a duration. This is the default value.|
| MATCH_MODE_STICKY | 2 | Hardware reports the scan result with a higher threshold of signal strength and sightings. |
| MATCH_MODE_STICKY | 2 | Hardware reports the scan result with a higher threshold of signal strength and sightings. |
...
@@ -3596,7 +3591,7 @@ Enumerates the Bluetooth states.
...
@@ -3596,7 +3591,7 @@ Enumerates the Bluetooth states.
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).
> **NOTE**<br>
> **NOTE**
>
> The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import
## Modules to Import
```
```
...
@@ -18,7 +18,7 @@ Enumerates the NFC card emulation types.
...
@@ -18,7 +18,7 @@ Enumerates the NFC card emulation types.
The **connectedTag** module provides methods for using active tags. You can use the APIs provided by this module 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.
> **NOTE**<br>
> **NOTE**
>
> 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.
> 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
## Modules to Import
```
```js
importconnectedTagfrom'@ohos.connectedTag';
importconnectedTagfrom'@ohos.connectedTag';
```
```
## connectedTag.init
## connectedTag.init
init(): boolean
init(): boolean
...
@@ -23,11 +22,11 @@ Initializes the active tag chip.
...
@@ -23,11 +22,11 @@ Initializes the active tag chip.
| type | string | Yes| Event type. The value is **notify**.|
| -------- | -------- | -------- | -------- |
| callback | Callback<number> | No| Callback used to return the field strength state. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.|
| type | string | Yes| Event type. The value is **notify**.|
| callback | Callback<number> | No| Callback used to return the field strength state. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.|
- Example
```
**Example**
import connectedTag from '@ohos.connectedTag';
```js
var NFC_RF_NOTIFY = "notify";
importconnectedTagfrom'@ohos.connectedTag';
var recvNfcRfNotifyFunc = result => {
// Register the event.
console.info("nfc rf receive state: " + result);
connectedTag.on("notify",(err,rfState)=>{
}
if(err){
console.log("connectedTag on Callback err: "+err);
The **distributedAccount** module provides APIs for managing distributed accounts, including querying and updating account login status.
The **distributedAccount** module provides APIs for managing distributed accounts, including querying and updating account login states.
> **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.
...
@@ -49,7 +49,7 @@ Obtains distributed account information. This API uses an asynchronous callback
...
@@ -49,7 +49,7 @@ Obtains distributed account information. This API uses an asynchronous callback
| Name| Type| Mandatory| Description|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback<[DistributedInfo](#distributedinfo)> | Yes| Callback invoked to return the result. If the operation is successful, **err** is **undefined** and data is the distributed account information obtained. Otherwise, **err** is an error object.|
| callback | AsyncCallback<[DistributedInfo](#distributedinfo)> | Yes| Callback invoked to return the result. If the operation is successful, **err** is **undefined** and **data** is the distributed account information obtained. Otherwise, **err** is an error object.|
**Error codes**
**Error codes**
...
@@ -124,7 +124,7 @@ Obtains distributed account information. This API uses an asynchronous callback
...
@@ -124,7 +124,7 @@ Obtains distributed account information. This API uses an asynchronous callback
| Name| Type| Mandatory| Description|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback<[DistributedInfo](#distributedinfo)> | Yes| Callback invoked to return the result. If the operation is successful, **err** is **undefined** and data is the distributed account information obtained. Otherwise, **err** is an error object.|
| callback | AsyncCallback<[DistributedInfo](#distributedinfo)> | Yes| Callback invoked to return the result. If the operation is successful, **err** is **undefined** and **data** is the distributed account information obtained. Otherwise, **err** is an error object.|
**Example**
**Example**
```js
```js
...
@@ -181,7 +181,7 @@ Sets the distributed account information. This API uses an asynchronous callback
...
@@ -181,7 +181,7 @@ Sets the distributed account information. This API uses an asynchronous callback
| Name| Type| Mandatory| Description|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
| accountInfo | [DistributedInfo](#distributedinfo) | Yes| New distributed account information.|
| accountInfo | [DistributedInfo](#distributedinfo) | Yes| Distributed account information to set.|
| callback | AsyncCallback<void> | Yes| Callback invoked to return the result. If the distributed account information is set successfully, **err** is **undefined**. Otherwise, **err** is an error object.|
| callback | AsyncCallback<void> | Yes| Callback invoked to return the result. If the distributed account information is set successfully, **err** is **undefined**. Otherwise, **err** is an error object.|
**Error codes**
**Error codes**
...
@@ -219,7 +219,7 @@ Sets the distributed account information. This API uses a promise to return the
...
@@ -219,7 +219,7 @@ Sets the distributed account information. This API uses a promise to return the
| Name| Type| Mandatory| Description|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
| accountInfo | [DistributedInfo](#distributedinfo) | Yes| New distributed account information.|
| accountInfo | [DistributedInfo](#distributedinfo) | Yes| Distributed account information to set.|
**Return value**
**Return value**
...
@@ -322,7 +322,7 @@ Defines distributed OS account information.
...
@@ -322,7 +322,7 @@ Defines distributed OS account information.
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
| name | string | Yes| Name of the distributed account. It must be a non-null string.|
| name | string | Yes| Name of the distributed account. It must be a non-null string.|
| id | string | Yes| UID of the distributed account. It must be a non-null string.|
| id | string | Yes| UID of the distributed account. It must be a non-null string.|
| event | string | Yes| Login state of a distributed account. The state can be login, logout, token invalid, or logoff, which correspond to the following strings respectively:<br>- Ohos.account.event.LOGIN<br>- Ohos.account.event.LOGOUT<br>- Ohos.account.event.TOKEN_INVALID<br>- Ohos.account.event.LOGOFF |
| event | string | Yes| Login state of the distributed account. The state can be login, logout, token invalid, or logoff, which correspond to the following strings respectively:<br>- Ohos.account.event.LOGIN<br>- Ohos.account.event.LOGOUT<br>- Ohos.account.event.TOKEN_INVALID<br>- Ohos.account.event.LOGOFF |
| nickname<sup>9+</sup> | string | No| Nickname of the distributed account. It must be a non-null string.|
| nickname<sup>9+</sup> | string | No| Nickname of the distributed account. It must be a non-null string.|
| avatar<sup>9+</sup> | string | No| Avatar of the distributed account. It must be a non-null string.|
| avatar<sup>9+</sup> | string | No| Avatar of the distributed account. It must be a non-null string.|
| scalableData | object | No| Extended information about the distributed account, passed in key-value (KV) pairs.<br>**NOTE**<br>This parameter is reserved and not used in query and update methods.|
| scalableData | object | No| Extended information about the distributed account, passed in key-value (KV) pairs.<br>**NOTE**<br>This parameter is reserved and not used in the setters and getters.|
The **nfcTag** module provides APIs for managing Near-Field Communication (NFC) tags.
The **nfcTag** module provides APIs for managing Near-Field Communication (NFC) tags.
> **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.
## **Declaration**
## **Declaration**
...
@@ -47,12 +48,10 @@ Before developing applications related to tag read and write, you must declare N
...
@@ -47,12 +48,10 @@ Before developing applications related to tag read and write, you must declare N
}
}
```
```
> **CAUTION**<br>
> **CAUTION**<br>
>
1. The **actions** field is mandatory. It must be **ohos.nfc.tag.action.TAG_FOUND** and cannot be changed.
> - The **actions** field is mandatory. It must be **ohos.nfc.tag.action.TAG_FOUND** and cannot be changed.
2. The **name** field under **metadata** is mandatory. It must be **tag-tech** and cannot be changed.
> - The **name** field of **metadata** is mandatory. It must be **tag-tech** and cannot be changed.
3. The **value** field under **metadata** is mandatory. It can be **NfcA**, **NfcB**, **NfcF**, **NfcV**, **IsoDep**, **Ndef**, **MifareClassic**, **MifareUL**, **NdefFormatable** or any of their combinations. Incorrect settings of this field will cause a parsing failure.
> - The **value** field of **metadata** is mandatory. It can be **NfcA**, **NfcB**, **NfcF**, **NfcV**, **IsoDep**, **Ndef**, **MifareClassic**, **MifareUL**, **NdefFormatable** or their combinations. Incorrect setting of this field will cause a parsing failure.
4. The **name** field under **requestPermissions** is mandatory. It must be **ohos.permission.NFC_TAG** and cannot be changed.
> - The **name** field of **requestPermissions** is mandatory. It must be **ohos.permission.NFC_TAG** and cannot be changed.
## **Modules to Import**
## **Modules to Import**
...
@@ -61,34 +60,63 @@ import tag from '@ohos.nfc.tag';
...
@@ -61,34 +60,63 @@ import tag from '@ohos.nfc.tag';
```
```
## **tag.TagInfo**
## **tag.TagInfo**
Before reading or writing data to a card with tags, the application must obtain **TagInfo** to determine the tag technologies supported by the card. Then, the application can invoke the correct API to communicate with the card.
Before a card with tags is read or written, **TagInfo** must be obtained to determine the tag technologies supported by the card. In this way, the application can invoke the correct API to communicate with the card.
```js
```js
importtagfrom'@ohos.nfc.tag';
importtagfrom'@ohos.nfc.tag';
onCreate(want,launchParam){
onCreate(want,launchParam){
// Add other code here.
// Add other code here.
// want is initialized by the NFC service and contains taginfo.
// want is initialized by the NFC service and contains tagInfo.
| taginfo | [TagInfo](#taginfo) | Yes| Tag information including the technology type and related parameters, which are obtained from **tag.getTagInfo(want: Want)**. |
| taginfo | [TagInfo](#taginfo) | Yes | Tag information including the technology type and related parameters, which are obtained from **tag.getTagInfo(want: Want)**. |
| taginfo | [TagInfo](#taginfo) | Yes | Tag information including the technology type and related parameters, which are obtained from **tag.getTagInfo(want: Want)**. |
| taginfo | [TagInfo](#taginfo) | Yes | Tag information including the technology type and related parameters, which are obtained from **tag.getTagInfo(want: Want)**. |
| want | [Want](js-apis-app-ability-want.md#Want) | Yes | Data obtained from the parameters of the **onCreate** entry function when an ability is dispatched. |
Creates an NDEF message from raw byte data. The data must comply with the NDEF record format. Otherwise, the NDE record list contained in the **NdefMessage** object will be empty.
| data | number[] | Yes| Raw byte data, which consists of hexadecimal numbers ranging from **0x00** to **0xFF**. The data must comply with the NDEF record format.|
| ndefRecords | [NdefRecord](js-apis-nfcTag.md#ndefrecord9)[] | Yes| NDEF record list used to create the NDEF message. For details, see *NFCForum-TS-NDEF_1.0*.|
| uid<sup>9+</sup> | number[] | Yes| No| Tag unique identifier (UID), which consists of hexadecimal numbers ranging from **0x00** to **0xFF**.|
| technology<sup>9+</sup> | number[] | Yes| No| Supported technologies. Each number is a constant indicating the supported technology.|
| supportedProfiles | number[] | Yes| No| Supported profiles. This parameter is not supported since API version 9. Use [tag.TagInfo#technology](#taginfo) instead.|
| extrasData<sup>9+</sup> | [PacMap](js-apis-inner-ability-dataAbilityHelper.md#pacmap)[] | Yes| No| Extended attribute value of the tag technology.<br>**System API**: This is a system API.|
| tagRfDiscId<sup>9+</sup> | number | Yes| No| ID allocated when the tag is discovered.<br>**System API**: This is a system API.|
| remoteTagService<sup>9+</sup> | [rpc.RemoteObject](js-apis-rpc.md#remoteobject) | Yes| No| Remote object of the NFC service process used for interface communication between the client and the service.<br>**System API**: This is a system API.|
## NdefRecord<sup>9+</sup>
Defines an NDEF record. For details, see *NFCForum-TS-NDEF_1.0*.
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.
> **NOTE**
> **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
```js
importtagfrom'@ohos.nfc.tag';
importtagfrom'@ohos.nfc.tag';
...
@@ -13,11 +14,11 @@ import tag from '@ohos.nfc.tag';
...
@@ -13,11 +14,11 @@ import tag from '@ohos.nfc.tag';
## NfcATag
## NfcATag
Provides access to NFC-A (ISO 14443-3A) properties and I/O operations. This class inherits from **TagSession**.
Provides APIs to access NFC-A (ISO 14443-3A) properties and perform I/O operations on a tag. This class inherits from **[TagSession](js-apis-tagSession.md)**.
**TagSession** is the base class of all NFC tag technologies. It provides common interfaces for establishing connections and transferring data. For more details, see [TagSession](js-apis-tagSession.md).
**TagSession** is the base class of all NFC tag technologies. It provides common interfaces for establishing connections and transferring data. For more details, see [TagSession](js-apis-tagSession.md).
The following describes the unique interfaces of **NfcATag**.
The following describes the unique APIs of **NfcATag**.
### NfcATag.getSak
### NfcATag.getSak
...
@@ -40,8 +41,7 @@ Obtains the SAK value of this NFC-A tag.
...
@@ -40,8 +41,7 @@ Obtains the SAK value of this NFC-A tag.
```js
```js
importtagfrom'@ohos.nfc.tag';
importtagfrom'@ohos.nfc.tag';
// Check whether 'tag.TagInfo' at 'js-apis-nfcTag' has obtained the 'nfcA' correctly.
// Check whether 'tag.TagInfo' in 'js-apis-nfcTag.md' has obtained 'nfcA' correctly.
letsak=nfcA.getSak();
letsak=nfcA.getSak();
console.log("nfcA sak: "+sak);
console.log("nfcA sak: "+sak);
```
```
...
@@ -67,18 +67,18 @@ Obtains the ATQA value of this NFC-A tag.
...
@@ -67,18 +67,18 @@ Obtains the ATQA value of this NFC-A tag.
```js
```js
importtagfrom'@ohos.nfc.tag';
importtagfrom'@ohos.nfc.tag';
// Check whether 'tag.TagInfo' at 'js-apis-nfcTag' has obtained the 'nfcA' correctly.
// Check whether 'tag.TagInfo' in 'js-apis-nfcTag.md' has obtained 'nfcA' correctly.
letatqa=nfcA.getAtqa();
letatqa=nfcA.getAtqa();
console.log("nfcA atqa: "+atqa);
console.log("nfcA atqa: "+atqa);
```
```
## NfcBTag
## NfcBTag
Provides access to NFC-B (ISO 14443-3B) properties and I/O operations. This class inherits from **TagSession**.
Provides APIs to access NFC-B (ISO 14443-3B) properties and perform I/O operations on a tag. This class inherits from **TagSession**.
**TagSession** is the base class of all NFC tag technologies. It provides common interfaces for establishing connections and transferring data. For more details, see [TagSession](js-apis-tagSession.md).
**TagSession** is the base class of all NFC tag technologies. It provides common interfaces for establishing connections and transferring data. For more details, see [TagSession](js-apis-tagSession.md).
The following describes the unique interfaces of **NfcBTag**.
The following describes the unique APIs of **NfcBTag**.
### NfcBTag.getRespAppData
### NfcBTag.getRespAppData
...
@@ -94,14 +94,14 @@ Obtains the application data of this NFC-B tag.
...
@@ -94,14 +94,14 @@ Obtains the application data of this NFC-B tag.
| number[] | Protocol information obtained. Each number in the return result is a hexadecimal number ranging from **0x00** to **0xFF**.|
| number[] | Protocol information obtained, which consists of hexadecimal numbers ranging from **0x00** to **0xFF**.|
**Example**
**Example**
```js
```js
importtagfrom'@ohos.nfc.tag';
importtagfrom'@ohos.nfc.tag';
// Check whether 'tag.TagInfo' at 'js-apis-nfcTag' has obtained the 'nfcB' correctly.
// Check whether 'tag.TagInfo' in 'js-apis-nfcTag.md' has obtained 'nfcB' correctly.
letrespProtocol=nfcB.getRespProtocol();
letrespProtocol=nfcB.getRespProtocol();
console.log("nfcB respProtocol: "+respProtocol);
console.log("nfcB respProtocol: "+respProtocol);
```
```
## NfcFTag
## NfcFTag
Provides access to NFC-F (JIS 6319-4) properties and I/O operations. This class inherits from **TagSession**.
Provides APIs to access NFC-F (JIS 6319-4) properties and perform I/O operations on a tag. This class inherits from **TagSession**.
**TagSession** is the base class of all NFC tag technologies. It provides common interfaces for establishing connections and transferring data. For more details, see [TagSession](js-apis-tagSession.md).
**TagSession** is the base class of all NFC tag technologies. It provides common interfaces for establishing connections and transferring data. For more details, see [TagSession](js-apis-tagSession.md).
The following describes the unique interfaces of **NfcFTag**.
The following describes the unique APIs of **NfcFTag**.
### NfcFTag.getSystemCode
### NfcFTag.getSystemCode
...
@@ -154,14 +154,14 @@ Obtains the system code from this NFC-F tag.
...
@@ -154,14 +154,14 @@ Obtains the system code from this NFC-F tag.
| number[] | PMm information obtained. Each number in the return result is a hexadecimal number ranging from **0x00** to **0xFF**.|
| number[] | PMm information obtained, which consists of hexadecimal numbers ranging from **0x00** to **0xFF**.|
**Example**
**Example**
```js
```js
importtagfrom'@ohos.nfc.tag';
importtagfrom'@ohos.nfc.tag';
// Check whether 'tag.TagInfo' at 'js-apis-nfcTag' has obtained the 'nfcF' correctly.
// Check whether 'tag.TagInfo' in 'js-apis-nfcTag.md' has obtained 'nfcF' correctly.
letpmm=nfcF.getPmm();
letpmm=nfcF.getPmm();
console.log("nfcF pmm: "+pmm);
console.log("nfcF pmm: "+pmm);
```
```
## NfcVTag
## NfcVTag
Provides access to NFC-V (ISO 15693) properties and I/O operations. This class inherits from **TagSession**.
Provides APIs to access NFC-V (ISO 15693) properties and perform I/O operations on a tag. This class inherits from **TagSession**.
**TagSession** is the base class of all NFC tag technologies. It provides common interfaces for establishing connections and transferring data. For more details, see [TagSession](js-apis-tagSession.md).
**TagSession** is the base class of all NFC tag technologies. It provides common interfaces for establishing connections and transferring data. For more details, see [TagSession](js-apis-tagSession.md).
The following describes the unique interfaces of **NfcVTag**.
The following describes the unique APIs of **NfcVTag**.
### NfcvTag.getResponseFlags
### NfcvTag.getResponseFlags
...
@@ -208,20 +208,20 @@ Obtains the response flags from this NFC-V tag.
...
@@ -208,20 +208,20 @@ Obtains the response flags from this NFC-V tag.
| number | DSFID obtained. The value is a hexadecimal number ranging from **0x00** to **0xFF**.|
| number | DSFID obtained, which consists of hexadecimal numbers ranging from **0x00** to **0xFF**.|
**Example**
**Example**
```js
```js
importtagfrom'@ohos.nfc.tag';
importtagfrom'@ohos.nfc.tag';
// Check whether 'tag.TagInfo' at 'js-apis-nfcTag' has obtained the 'nfcV' correctly.
// Check whether 'tag.TagInfo' in 'js-apis-nfcTag.md' has obtained 'nfcV' correctly.
letdsfId=nfcV.getDsfId();
letdsfId=nfcV.getDsfId();
console.log("nfcV dsfId: "+dsfId);
console.log("nfcV dsfId: "+dsfId);
```
```
## IsoDepTag<sup>9+</sup>
## IsoDepTag<sup>9+</sup>
Provides access to ISO-DEP (ISO 14443-4) properties and I/O operations. This class inherits from **TagSession**.
Provides APIs to access ISO-DEP (ISO 14443-4) properties and I/O operations on a tag. This class inherits from **TagSession**.
**TagSession** is the base class of all NFC tag technologies. It provides common interfaces for establishing connections and transferring data. For more details, see [TagSession](js-apis-tagSession.md).
**TagSession** is the base class of all NFC tag technologies. It provides common interfaces for establishing connections and transferring data. For more details, see [TagSession](js-apis-tagSession.md).
The following describes the unique interfaces of **IsoDepTag**.
The following describes the unique APIs of **IsoDepTag**.
### IsoDepTag.getHistoricalBytes<sup>9+</sup>
### IsoDepTag.getHistoricalBytes<sup>9+</sup>
getHistoricalBytes(): number[]
getHistoricalBytes(): number[]
Obtains the historical bytes of this tag.
Obtains the historical bytes for the given tag. This API applies only to the IsoDep cards that use the NFC-A technology.
| number[] | Historical bytes obtained. Each number in the return result is a hexadecimal number ranging from **0x00** to **0xFF**.|
| number[] | Historical bytes obtained, which consist of hexadecimal numbers ranging from **0x00** to **0xFF**. If the IsoDep tag uses the NFC-B technology, **null** will be returned.|
**Example**
**Example**
```js
```js
importtagfrom'@ohos.nfc.tag';
importtagfrom'@ohos.nfc.tag';
// Check whether 'tag.TagInfo' at 'js-apis-nfcTag' has obtained the 'isoDep' correctly.
// Check whether 'tag.TagInfo' in 'js-apis-nfcTag.md' has obtained 'isoDep' correctly.
| number[] | HiLayer response obtained. Each number in the return result is a hexadecimal number ranging from **0x00** to **0xFF**.|
| number[] | Higher-layer response bytes obtained, which consist of hexadecimal numbers ranging from **0x00** to **0xFF**. If the IsoDep tag uses the NFC-A technology, **null** will be returned.|
**Example**
**Example**
```js
```js
importtagfrom'@ohos.nfc.tag';
importtagfrom'@ohos.nfc.tag';
// Check whether 'tag.TagInfo' at 'js-apis-nfcTag' has obtained the 'isoDep' correctly.
// Check whether 'tag.TagInfo' in 'js-apis-nfcTag.md' has obtained 'isoDep' correctly.
| Promise<boolean> | Promise used to return the result. If the extended APDU is supported, **true** is returned; otherwise, **false** is returned.|
| Promise<boolean> | Promise used to return the result. If the extended APDU is supported, **true** is returned; otherwise, **false** is returned.|
**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**
**Example**
```js
```js
importtagfrom'@ohos.nfc.tag';
importtagfrom'@ohos.nfc.tag';
// Check whether 'tag.TagInfo' at 'js-apis-nfcTag' has obtained the 'isoDep' correctly.
// Check whether 'tag.TagInfo' in 'js-apis-nfcTag.md' has obtained 'isoDep' correctly.
| callback | AsyncCallback\<boolean> | Yes | Callback invoked to return the result. If the extended APDU is supported, **true** is returned; otherwise, **false** is returned.|
| callback | AsyncCallback\<boolean> | Yes | Callback invoked to return the result. If the extended APDU is supported, **true** is returned; otherwise, **false** is returned.|
```js
**Error codes**
importtagfrom'@ohos.nfc.tag';
// Check whether 'tag.TagInfo' at 'js-apis-nfcTag' has obtained the 'isoDep' correctly.
Provides access to the tags in the NFC Data Exchange Format (NDEF). This class inherits from **TagSession**.
**TagSession** is the base class of all NFC tag technologies. It provides common interfaces for establishing connections and transferring data. For more details, see [TagSession](js-apis-tagSession.md).
The following describes the unique interfaces of **NdefTag**.
| ndefRecords | [NdefRecord](js-apis-nfcTag.md#ndefrecord9)[] | Yes| NDEF records used to create the NDEF message. For details, see *NFCForum-TS-NDEF_1.0*.|
| [NdefMessage](#ndefmessage9) | NDEF message created. For details, see *NFCForum-TS-NDEF_1.0*.|
**Example**
```js
Provides APIs to access the tags in the NFC Data Exchange Format (NDEF). This class inherits from **TagSession**.
importtagfrom'@ohos.nfc.tag';
// Check whether 'tag.TagInfo' at 'js-apis-nfcTag' has obtained the 'ndef' correctly.
**TagSession** is the base class of all NFC tag technologies. It provides common interfaces for establishing connections and transferring data. For more details, see [TagSession](js-apis-tagSession.md).
| callback | AsyncCallback\<boolean> | Yes | Callback invoked to return the result. If the tag is writable, **true** is returned; otherwise, **false** is returned.|
**Example**
**Example**
```js
```js
importtagfrom'@ohos.nfc.tag';
importtagfrom'@ohos.nfc.tag';
// Check whether 'tag.TagInfo' at 'js-apis-nfcTag' has obtained the 'ndef' correctly.
// Check whether 'tag.TagInfo' in 'js-apis-nfcTag.md' has obtained 'ndefTag' correctly.
| Promise\<number> | Promise used to return the result. If **0** is returned, the operation is successful. If the operation fails, an error code is returned.|
| ID| Error Message|
| ------- | -------|
| 3100201 | Tag running state is abnormal in service. |
**Example**
**Example**
```js
```js
importtagfrom'@ohos.nfc.tag';
importtagfrom'@ohos.nfc.tag';
// Check whether 'tag.TagInfo' at 'js-apis-nfcTag' has obtained the 'ndef' correctly.
// Check whether 'tag.TagInfo' in 'js-apis-nfcTag.md' has obtained 'ndefTag' correctly.
letndefMessage=ndef.createNdefMessage([0x01,0x02,...]);// change the raw data to be correct.
// NDEF message created from raw data, such as:
letndefMessage=tag.ndef.createNdefMessage([0xD1,0x01,0x03,0x54,0x4E,0x46,0x43]);// It must be parsed as NDEF Record.
// or ndefMessage created from tag.ndef.createNdefMessage(ndefRecords: NdefRecord[])
Provides access to MIFARE Classic properties and I/O operations. This class inherits from **TagSession**.
Provides APIs to access MIFARE Classic properties and perform I/O operations on a tag. This class inherits from [TagSession](js-apis-tagSession.md).
**TagSession** is the base class of all NFC tag technologies. It provides common interfaces for establishing connections and transferring data. For more details, see [TagSession](js-apis-tagSession.md).
**TagSession** is the base class of all NFC tag technologies. It provides common interfaces for establishing connections and transferring data. For more details, see [TagSession](js-apis-tagSession.md).
The following describes the unique interfaces of **MifareClassicTag**.
The following describes the unique APIs of **MifareClassicTag**.
Authenticates a sector using the key. The sector can be accessed only after the authentication is successful. This API uses a promise to return the result.
Authenticates a sector using a key. The sector can be accessed only after the authentication is successful. This API uses a promise to return the result.
Authenticates a sector using the key. The sector can be accessed only after the authentication is successful. This API uses an asynchronous callback to return the result.
Authenticates a sector using a key. The sector can be accessed only after the authentication is successful. This API uses an asynchronous callback to return the result.
| Promise\<number> | Promise used to return the result. If **0** is returned, the operation is successful. If the operation fails, an error code is returned.|
| ID| Error Message|
| ------- | -------|
| 3100201 | Tag running state is abnormal in service. |
**Example**
**Example**
```js
```js
importtagfrom'@ohos.nfc.tag';
importtagfrom'@ohos.nfc.tag';
// Check whether 'tag.TagInfo' at 'js-apis-nfcTag' has obtained the 'mifareClassic' correctly.
// Check whether 'tag.TagInfo' in 'js-apis-nfcTag.md' has obtained 'mifareClassic' correctly.
letblockIndex=1;// change it to be correct index.
letrawData=[0x0a,0x14,...];// change it to be correct data.
| Promise\<number> | Promise used to return the result. If **0** is returned, the operation is successful. If the operation fails, an error code is returned.|
| ID| Error Message|
| ------- | -------|
| 3100201 | Tag running state is abnormal in service. |
**Example**
**Example**
```js
```js
importtagfrom'@ohos.nfc.tag';
importtagfrom'@ohos.nfc.tag';
// Check whether 'tag.TagInfo' at 'js-apis-nfcTag' has obtained the 'mifareClassic' correctly.
// Check whether 'tag.TagInfo' in 'js-apis-nfcTag.md' has obtained 'mifareClassic' correctly.
| Promise\<number> | Promise used to return the result. If **0** is returned, the operation is successful. If the operation fails, an error code is returned.|
| ID| Error Message|
| ------- | -------|
| 3100201 | Tag running state is abnormal in service. |
**Example**
**Example**
```js
```js
importtagfrom'@ohos.nfc.tag';
importtagfrom'@ohos.nfc.tag';
// Check whether 'tag.TagInfo' at 'js-apis-nfcTag' has obtained the 'mifareClassic' correctly.
// Check whether 'tag.TagInfo' in 'js-apis-nfcTag.md' has obtained 'mifareClassic' correctly.
| Promise\<number> | Promise used to return the result. If **0** is returned, the operation is successful. If the operation fails, an error code is returned.|
| ID| Error Message|
| ------- | -------|
| 3100201 | Tag running state is abnormal in service. |
**Example**
**Example**
```js
```js
importtagfrom'@ohos.nfc.tag';
importtagfrom'@ohos.nfc.tag';
// Check whether 'tag.TagInfo' at 'js-apis-nfcTag' has obtained the 'mifareClassic' correctly.
// Check whether 'tag.TagInfo' in 'js-apis-nfcTag.md' has obtained 'mifareClassic' correctly.
| Promise\<number> | Promise used to return the result. If **0** is returned, the operation is successful. If the operation fails, an error code is returned.|
| ID| Error Message|
| ------- | -------|
| 3100201 | Tag running state is abnormal in service. |
**Example**
**Example**
```js
```js
importtagfrom'@ohos.nfc.tag';
importtagfrom'@ohos.nfc.tag';
// Check whether 'tag.TagInfo' at 'js-apis-nfcTag' has obtained the 'mifareClassic' correctly.
// Check whether 'tag.TagInfo' in 'js-apis-nfcTag.md' has obtained 'mifareClassic' correctly.
Provides access to MIFARE Ultralight properties and I/O operations. This class inherits from **TagSession**.
Provides APIs to access MIFARE Ultralight properties and perform I/O operations on a tag. This class inherits from **TagSession**.
**TagSession** is the base class of all NFC tag technologies. It provides common interfaces for establishing connections and transferring data. For more details, see [TagSession](js-apis-tagSession.md).
**TagSession** is the base class of all NFC tag technologies. It provides common interfaces for establishing connections and transferring data. For more details, see [TagSession](js-apis-tagSession.md).
The following describes the unique interfaces of **MifareUltralightTag**.
The following describes the unique APIs of **MifareUltralightTag**.
| Promise\<number> | Promise used to return the result. If **0** is returned, the operation is successful. If the operation fails, an error code is returned.|
| ID| Error Message|
| ------- | -------|
| 3100201 | Tag running state is abnormal in service. |
**Example**
**Example**
```js
```js
importtagfrom'@ohos.nfc.tag';
importtagfrom'@ohos.nfc.tag';
// Check whether 'tag.TagInfo' at 'js-apis-nfcTag' has obtained the 'mifareUltralight' correctly.
// Check whether 'tag.TagInfo' in 'js-apis-nfcTag.md' has obtained 'mifareUltralight' correctly.
letpageIndex=1;// change it to be correct index.
letdata=[0x01,0x02,...];// change it to be correct raw data.
Provides APIs for operating NDEF formattable tags. This class inherits from **TagSession**.
Provides APIs for formatting NDEF formattable tags. This class inherits from **TagSession**.
**TagSession** is the base class of all NFC tag technologies. It provides common interfaces for establishing connections and transferring data. For more details, see [TagSession](js-apis-tagSession.md).
**TagSession** is the base class of all NFC tag technologies. It provides common interfaces for establishing connections and transferring data. For more details, see [TagSession](js-apis-tagSession.md).
The following describes the unique interfaces of **NdefFormatableTag**.
The following describes the unique APIs of **NdefFormatableTag**.
| message | [NdefMessage](#ndefmessage9) | Yes | NDEF message to write when the formatting is successful. If this parameter is **null**, the tag is formatted only (no data will be written).|
| message | [NdefMessage](#ndefmessage9) | Yes | NDEF message to write. If this parameter is **null**, the tag is formatted only (no data will be written).|
**Return value**
**Error codes**
| **Type**| **Description** |
For details about the error codes, see [NFC Error Codes](../errorcodes/errorcode-nfc.md).
| Promise\<number> | Promise used to return the result. If **0** is returned, the operation is successful. If the operation fails, an error code is returned.|
| ID| Error Message|
| ------- | -------|
| 3100201 | Tag running state is abnormal in service. |
**Example**
**Example**
```js
```js
importtagfrom'@ohos.nfc.tag';
importtagfrom'@ohos.nfc.tag';
// Check whether 'tag.TagInfo' at 'js-apis-nfcTag' has obtained the 'ndef' correctly.
// Check whether 'tag.TagInfo' in 'js-apis-nfcTag.md' has obtained 'ndefFormatable' correctly.
letdata=[0x01,0x02,...];// change it to be correct raw data.
letndefmessage=ndef.createNdefMessage(data);
// Check whether 'tag.TagInfo' at 'js-apis-nfcTag' has obtained the 'ndefFormatable' correctly.
// Connect to the tag if it is not connected.
ndefFormatable.format(ndefmessage,(err,data)=>{
if(!ndefFormatable.isTagConnected()){
if(err){
if(!ndefFormatable.connectTag()){
console.log("ndefFormatable format err: "+err);
console.log("ndefFormatable connectTag failed.");
}else{
return;
console.log("ndefFormatable format data: "+data);
}
}
});
}
try{
// NDEF message created from raw data, such as:
letndefMessage=tag.ndef.createNdefMessage([0xD1,0x01,0x03,0x54,0x4E,0x46,0x43]);// It must be parsed as NDEF Record.
// or ndefMessage created from tag.ndef.createNdefMessage(ndefRecords: NdefRecord[])
ndefFormatable.format(ndefMessage).then(()=>{
console.log("ndefFormatable format Promise success.");
}).catch((err)=>{
console.log("ndefFormatable format Promise err: "+err);
});
}catch(busiError){
console.log("ndefFormatable format Promise catch busiError: "+busiError);
Formats this tag as an NDEF tag, writes an NDEF message to the NDEF tag, and then sets the tag to read-only. This API uses a promise to return the result.
Formats this tag as an NDEF tag, writes an NDEF message to it, and then sets the tag to read-only. This API uses a promise to return the result.
| message | [NdefMessage](#ndefmessage9) | Yes | NDEF message to write when the formatting is successful. If this parameter is **null**, the tag is formatted only (no data will be written).|
| message | [NdefMessage](#ndefmessage9) | Yes | NDEF message to write. If this parameter is **null**, the tag is formatted only (no data will be written).|
**Return value**
**Error codes**
| **Type**| **Description** |
For details about the error codes, see [NFC Error Codes](../errorcodes/errorcode-nfc.md).
| Promise\<number> | Promise used to return the result. If **0** is returned, the operation is successful. If the operation fails, an error code is returned.|
| ID| Error Message|
| ------- | -------|
| 3100201 | Tag running state is abnormal in service. |
**Example**
**Example**
```js
```js
importtagfrom'@ohos.nfc.tag';
importtagfrom'@ohos.nfc.tag';
// Check whether 'tag.TagInfo' at 'js-apis-nfcTag' has obtained the 'ndef' correctly.
// Check whether 'tag.TagInfo' in 'js-apis-nfcTag.md' has obtained 'ndefFormatable' correctly.
letdata=[0x01,0x02,...];// change it to be correct raw data.
letndefmessage=ndef.createNdefMessage(data);
// Check whether 'tag.TagInfo' at 'js-apis-nfcTag' has obtained the 'ndefFormatable' correctly.
Formats this tag as an NDEF tag, writes an NDEF message to the NDEF tag, and then sets the tag to read-only. This API uses an asynchronous callback to return the result.
Formats this tag as an NDEF tag, writes an NDEF message to the NDEF tag, and then sets the tag to read-only. This API uses an asynchronous callback to return the result.
| message | [NdefMessage](#ndefmessage9) | Yes | NDEF message to write when the formatting is successful. If this parameter is **null**, the tag is formatted only (no data will be written).|
| message | [NdefMessage](#ndefmessage9) | Yes | NDEF message to write. If this parameter is **null**, the tag is formatted only (no data will be written).|
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.
> **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.
...
@@ -2708,7 +2709,6 @@ Obtains the constraint source information of an OS account. This API uses a prom
...
@@ -2708,7 +2709,6 @@ Obtains the constraint source information of an OS account. This API uses a prom
The **RPC** module implements communication between processes, including inter-process communication (IPC) on a single device and remote procedure call (RPC) between processes on difference devices. IPC is implemented based on the Binder driver, and RPC is based on the DSoftBus driver.
The **RPC** module implements communication between processes, including inter-process communication (IPC) on a single device and remote procedure call (RPC) between processes on difference devices. IPC is implemented based on the Binder driver, and RPC is based on the DSoftBus driver.
> **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.
>
> This module supports return of error codes since API version 9.
> This module supports return of error codes since API version 9.
...
@@ -24,7 +26,7 @@ The APIs of this module return exceptions since API version 9. The following tab
...
@@ -24,7 +26,7 @@ The APIs of this module return exceptions since API version 9. The following tab
| OS_MMAP_ERROR | 1900001 | Failed to call mmap. |
| OS_MMAP_ERROR | 1900001 | Failed to call mmap. |
| OS_IOCTL_ERROR | 1900002 | Failed to execute**ioctl** with the shared memory file descriptor.|
| OS_IOCTL_ERROR | 1900002 | Failed to call**ioctl** with the shared memory file descriptor.|
| WRITE_TO_ASHMEM_ERROR | 1900003 | Failed to write data to the shared memory. |
| WRITE_TO_ASHMEM_ERROR | 1900003 | Failed to write data to the shared memory. |
| READ_FROM_ASHMEM_ERROR | 1900004 | Failed to read data from the shared memory. |
| READ_FROM_ASHMEM_ERROR | 1900004 | Failed to read data from the shared memory. |
| ONLY_PROXY_OBJECT_PERMITTED_ERROR | 1900005 | This operation is allowed only on the proxy object. |
| ONLY_PROXY_OBJECT_PERMITTED_ERROR | 1900005 | This operation is allowed only on the proxy object. |
...
@@ -123,7 +125,7 @@ For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode
...
@@ -123,7 +125,7 @@ For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode
readRemoteObject(): IRemoteObject
readRemoteObject(): IRemoteObject
Reads a remote object from **MessageSequence**. You can use this API to deserialize the **MessageSequence** object to generate an **IRemoteObject**. The remote object is read in the order in which it is written to this **MessageSequence** object.
Reads the remote object from **MessageSequence**. You can use this API to deserialize the **MessageSequence** object to generate an **IRemoteObject**. The remote object is read in the order in which it is written to this **MessageSequence** object.
The **tagSession** module provides common APIs for establishing connections and transferring data.
The **tagSession** module provides common APIs for establishing connections and transferring data.
> **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**
...
@@ -15,17 +16,15 @@ import tag from '@ohos.nfc.tag';
...
@@ -15,17 +16,15 @@ import tag from '@ohos.nfc.tag';
Provides common APIs for establishing connections and transferring data. **tagSession** is the base class of all [NFC tag technologies](js-apis-nfctech.md).
Provides common APIs for establishing connections and transferring data. **tagSession** is the base class of all [NFC tag technologies](js-apis-nfctech.md).
A child class instance is required to access the following interfaces. You can use **get**XX**Tag()** to obtain a child class instance.
A child class instance is required to access the following interfaces. You can use **get**XXX() to obtain a child class instance.
The specific API varies with the NFC tag technology in use. For details, see [NFC Tags](js-apis-nfcTag.md).
The specific API varies with the NFC tag technology in use. For details, see [NFC Tags](js-apis-nfcTag.md).
### tagSession.connectTag
### tagSession.getTagInfo
connectTag(): boolean;
Connects to this tag.
getTagInfo(): tag.TagInfo
Call this API to set up a connection before reading data from or writing data to a tag.
Obtains the **tagInfo** object provided by the NFC service when the tag is dispatched.
**Required permissions**: ohos.permission.NFC_TAG
**Required permissions**: ohos.permission.NFC_TAG
...
@@ -35,23 +34,25 @@ Call this API to set up a connection before reading data from or writing data to
...
@@ -35,23 +34,25 @@ Call this API to set up a connection before reading data from or writing data to
| Promise<number[]> | Promise used to return the response from the tag. The response consists of hexadecimal numbers ranging from **0x00** to **0xFF**.|
**Example**
```js
importtagfrom'@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.
if(!tag.getIsoDep(tagInfo).isTagConnected()){
if(!tag.getIsoDep(tagInfo).connectTag()){
console.log("tagSession connectTag failed.");
return;
}
}
letcmdData=[0x01,0x02,0x03,0x04];// Change it as required.
| data | number[] | Yes| Data to send. 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**.|
**Example**
**Example**
```js
```js
importtagfrom'@ohos.nfc.tag';
importtagfrom'@ohos.nfc.tag';
// tagInfo is an object given by the NFC service when a tag is dispatched.
// tagInfo is an object provided by the NFC service when a tag is dispatched.
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**<br>
> **NOTE**
>
> The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version.
| rssi | number | Read only| Received signal strength indicator (RSSI) of the hotspot, in dBm.|
| rssi | number | Yes| No| Received signal strength indicator (RSSI) of the hotspot, in dBm.|
| band | number | Read only| Frequency band of the WLAN access point (AP).|
| band | number | Yes| No| Frequency band of the WLAN access point (AP).|
| frequency | number | Read only| Frequency of the WLAN AP.|
| frequency | number | Yes| No| Frequency of the WLAN AP.|
| channelWidth | number | Read only| Channel width of the WLAN AP.|
| channelWidth | number | Yes| No| Channel width of the WLAN AP.|
| centerFrequency0<sup>9+</sup> | number | Read only| Center frequency of the hotspot.|
| timestamp | number | Yes| No| Timestamp.|
| centerFrequency1<sup>9+</sup> | number | Read only| Center frequency of the hotspot. If the hotspot uses two non-overlapping WLAN channels, two center frequencies, namely **centerFrequency0** and **centerFrequency1**, are returned.|
| infoElems<sup>9+</sup> | Array<[WifiInfoElem](#wifiinfoelem9)> | Read only| Information elements.|
| timestamp | number | Read only| Timestamp.|
## WifiSecurityType
## WifiSecurityType
...
@@ -189,50 +188,13 @@ Enumerates the WLAN security types.
...
@@ -189,50 +188,13 @@ Enumerates the WLAN security types.
@@ -500,122 +395,6 @@ Removes the configuration of an untrusted network. This API uses an asynchronous
...
@@ -500,122 +395,6 @@ Removes the configuration of an untrusted network. This API uses an asynchronous
| callback | AsyncCallback<boolean> | Yes| Callback invoked to return the result. If the operation is successful, **err** is **0** and **data** is **true**. If the operation fails, **data** is **false**. If **err** is not **0**, an error has occurred.|
| callback | AsyncCallback<boolean> | Yes| Callback invoked to return the result. If the operation is successful, **err** is **0** and **data** is **true**. If the operation fails, **data** is **false**. If **err** is not **0**, an error has occurred.|
| config | [WifiDeviceConfig](#wifideviceconfig) | Yes| WLAN configuration to add.|
| callback | AsyncCallback<number> | Yes| Callback invoked to return the result. If the operation is successful, **err** is **0** and **data** is the network configuration ID. If **data** is **-1**, the operation has failed. If **err** is not **0**, an error has occurred.|
| networkId | number | Yes| ID of the network configuration to remove.|
| callback | AsyncCallback<void> | Yes| Callback invoked to return the result. If the operation is successful, the value of **err** is **0**. If **err** is not **0**, an error has occurred.|
| callback | AsyncCallback<[WifiP2pDevice](#wifip2pdevice8)> | Yes| Callback invoked to return the result. If the operation is successful, **err** is **0** and **data** is the local device information obtained. If **err** is not **0**, an error has occurred.|
## wifi.createGroup<sup>8+</sup>
## wifi.createGroup<sup>8+</sup>
createGroup(config: WifiP2PConfig): boolean
createGroup(config: WifiP2PConfig): boolean
...
@@ -1520,13 +1264,13 @@ Represents P2P group configuration.
...
@@ -1520,13 +1264,13 @@ Represents P2P group configuration.
| callback | AsyncCallback< Array<[WifiP2pGroupInfo](#wifip2pgroupinfo8)>> | Yes| Callback invoked to return the result. If the operation is successful, **err** is **0** and **data** is the group information obtained. If **err** is not **0**, an error has occurred.|
## wifi.setDeviceName<sup>8+</sup>
## wifi.setDeviceName<sup>8+</sup>
...
@@ -1830,10 +1536,10 @@ Registers the WLAN state change events.
...
@@ -1830,10 +1536,10 @@ Registers the WLAN state change events.
| **Value**| **Description**|
| **Value**| **Description**|
| -------- | -------- |
| -------- | -------- |
| 0 | Deactivated. |
| 0 | Deactivated|
| 1 | Activated. |
| 1 | Activated|
| 2 | Activating. |
| 2 | Activating|
| 3 | Deactivating. |
| 3 | Deactivating|
## wifi.off('wifiStateChange')<sup>7+</sup>
## wifi.off('wifiStateChange')<sup>7+</sup>
...
@@ -2012,10 +1718,10 @@ Registers the hotspot state change events.
...
@@ -2012,10 +1718,10 @@ Registers the hotspot state change events.
| **Value**| **Description**|
| **Value**| **Description**|
| -------- | -------- |
| -------- | -------- |
| 0 | Deactivated. |
| 0 | Deactivated|
| 1 | Activated. |
| 1 | Activated|
| 2 | Activating. |
| 2 | Activating|
| 3 | Deactivating. |
| 3 | Deactivating|
## wifi.off('hotspotStateChange')<sup>7+</sup>
## wifi.off('hotspotStateChange')<sup>7+</sup>
...
@@ -2057,11 +1763,11 @@ Registers the P2P state change events.
...
@@ -2057,11 +1763,11 @@ Registers the P2P state change events.
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**
>
> The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import
```js
importwifiManagerfrom'@ohos.wifiManager';
```
## wifi.enableWifi<sup>9+</sup>
enableWifi(): void
Enables WLAN.
**System API**: This is a system API.
**Required permissions**: ohos.permission.SET_WIFI_INFO and ohos.permission.MANAGE_WIFI_CONNECTION (available only to system applications)
| callback | AsyncCallback< Array<[WifiScanInfo](#wifiscaninfo)>> | Yes| Callback invoked to return the result. If the operation is successful, **err** is **0** and **data** is the detected hotspots. Otherwise, **err** is a non-zero value and **data** is empty.|
| rssi | number | Yes| No| Received signal strength indicator (RSSI) of the hotspot, in dBm.|
| band | number | Yes| No| Frequency band of the WLAN access point (AP).|
| frequency | number | Yes| No| Frequency of the WLAN AP.|
| channelWidth | number | Yes| No| Channel width of the WLAN AP.|
| centerFrequency0 | number | Yes| No| Center frequency of the hotspot.|
| centerFrequency1 | number | Yes| No| Center frequency of the hotspot. If the hotspot uses two non-overlapping WLAN channels, two center frequencies, namely **centerFrequency0** and **centerFrequency1**, are returned.|
| infoElems | Array<[WifiInfoElem](#wifiinfoelem9)> | Yes| No| Information elements.|
| config | [WifiDeviceConfig](#wifideviceconfig) | Yes| WLAN configuration to add.|
**Return value**
| **Type**| **Description**|
| -------- | -------- |
| Promise<number> | Promise used to return the ID of the added network configuration. If **-1** is returned, the network configuration fails to be added.|
| config | [WifiDeviceConfig](#wifideviceconfig) | Yes| WLAN configuration to add.|
| callback | AsyncCallback<number> | Yes| Callback invoked to return the result. If the operation is successful, **err** is **0** and **data** is the network configuration ID. If **data** is **-1**, the operation has failed. If **err** is not **0**, an error has occurred.|
| config | [WifiDeviceConfig](#wifideviceconfig) | Yes| WLAN configuration to add.|
| callback | AsyncCallback<number> | Yes| Callback invoked to return the result. If the operation is successful, **err** is **0** and **data** is the network configuration ID. If **data** is **-1**, the operation has failed. If **err** is not **0**, an error has occurred.|
| networkId | number | Yes| ID of the network configuration to remove.|
| callback | AsyncCallback<void> | Yes| Callback invoked to return the result. If the operation is successful, the value of **err** is **0**. If **err** is not **0**, an error has occurred.|
| networkId | number | Yes| Network configuration ID.|
**Return value**
| **Type**| **Description**|
| -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
## wifi.connectToDevice<sup>9+</sup>
connectToDevice(config: WifiDeviceConfig): void
Connects to the specified network.
**System API**: This is a system API.
**Required permissions**: ohos.permission.SET_WIFI_INFO, ohos.permission.SET_WIFI_CONFIG, and ohos.permissio.MANAGE_WIFI_CONNECTION (available only to system applications)
| callback | AsyncCallback<[WifiLinkedInfo](#wifilinkedinfo)> | Yes| Callback invoked to return the result. If the operation is successful, **err** is **0** and **data** is the WLAN connection information obtained. If **err** is not **0**, an error has occurred.|
**Required permissions**: ohos.permission.GET_WIFI_INFO, ohos.permission.LOCATION, and ohos.permission.MANAGE_WIFI_HOTSPOT (available only to system applications)
| callback | AsyncCallback<[WifiP2pLinkedInfo](#wifip2plinkedinfo9)> | Yes| Callback invoked to return the result. If the operation is successful, **err** is **0** and **data** is the P2P link information. If **err** is not **0**, an error has occurred.|
| callback | AsyncCallback<[WifiP2pGroupInfo](#wifip2pgroupinfo9)> | Yes| Callback invoked to return the result. If the operation is successful, **err** is **0** and **data** is the group information obtained. If **err** is not **0**, an error has occurred.|
| callback | AsyncCallback<[WifiP2pDevice[]](#wifip2pdevice9)> | Yes| Callback invoked to return the result. If the operation is successful, **err** is **0** and **data** is the peer device list obtained. If **err** is not **0**, an error has occurred.|
| callback | AsyncCallback<[WifiP2pDevice](#wifip2pdevice9)> | Yes| Callback invoked to return the result. If the operation is successful, **err** is **0** and **data** is the local device information obtained. If **err** is not **0**, an error has occurred.|
| callback | AsyncCallback< Array<[WifiP2pGroupInfo](#wifip2pgroupinfo9)>> | Yes| Callback invoked to return the result. If the operation is successful, **err** is **0** and **data** is the group information obtained. If **err** is not **0**, an error has occurred.|
## wifi.setDeviceName<sup>9+</sup>
setDeviceName(devName: string): void
Sets the device name.
**System API**: This is a system API.
**Required permissions**: ohos.permission.SET_WIFI_INFO and ohos.permission.MANAGE_WIFI_CONNECTION (available only to system applications)
| type | string | Yes| Event type. The value is **wifiStateChange**.|
| callback | Callback<number> | No| Callback for the WLAN state. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.|
**Example**
```js
importwififrom'@ohos.wifi';
varrecvPowerNotifyFunc=result=>{
console.info("Receive power state change event: "+result);
| type | string | Yes| Event type. The value is **wifiConnectionChange**.|
| callback | Callback<number> | No| Callback for the WLAN connection state. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.|
| type | string | Yes| Event type. The value is **wifiScanStateChange**.|
| callback | Callback<number> | No| Callback for the WLAN scan state. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.|
| type | string | Yes| Event type. The value is **wifiRssiChange**.|
| callback | Callback<number> | No| Callback for the RSSI. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.|
| type | string | Yes| Event type. The value is **hotspotStateChange**.|
| callback | Callback<number> | No| Callback for the hotspot state. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.|
| type | string | Yes| Event type. The value is **p2pStateChange**.|
| callback | Callback<number> | No| Callback for the P2P state. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.|
| type | string | Yes| Event type. The value is **p2pConnectionChange**.|
| callback | Callback<[WifiP2pLinkedInfo](#wifip2plinkedinfo9)> | No| Callback for the P2P connection state. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.|
| type | string | Yes| Event type. The value is **p2pDeviceChange**.|
| callback | Callback<[WifiP2pDevice](#wifip2pdevice9)> | No| Callback for the P2P device state. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.|
| type | string | Yes| Event type. The value is **p2pPeerDeviceChange**.|
| callback | Callback<[WifiP2pDevice[]](#wifip2pdevice9)> | No| Callback for the peer device state. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.|
| type | string | Yes| Event type. The value is **p2pPersistentGroupChange**.|
| callback | Callback<void> | No| Callback for the P2P persistent group state. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.|
| type | string | Yes| Event type. The value is **p2pDiscoveryChange**.|
| callback | Callback<number> | No| Callback for the P2P device discovery state. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.|
This **wifiext** module provides WLAN extension interfaces for non-universal products.
> **NOTE**
>
> 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.
The APIs described in this document are used only for non-universal products, such as routers.
| callback | AsyncCallback<Array<[PowerModel](#powermodel)>> | 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
getPowerModel(): Promise<PowerModel>
Obtains the power model. This API uses a promise to return the result.
| callback | AsyncCallback<[PowerModel](#powermodel)> | 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.|
This **wifiext** module provides WLAN extension interfaces for non-universal products.
This **wifiext** module provides WLAN extension interfaces for non-universal products.
> **NOTE**<br>
> **NOTE**
>
> 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.
> 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.
The APIs described in this document are used only for non-universal products, such as routers.
The APIs described in this document are used only for non-universal products, such as routers.
@@ -90,7 +92,7 @@ Obtains the supported power models. This API uses an asynchronous callback to re
...
@@ -90,7 +92,7 @@ Obtains the supported power models. This API uses an asynchronous callback to re
| Name| Type| Mandatory| Description|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback<[PowerModel](#powermodel)> | 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<Array<[PowerModel](#powermodel)>> | 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.|