提交 f06ef602 编写于 作者: A Annie_wang

update docs

Signed-off-by: NAnnie_wang <annie.wangli@huawei.com>
上级 73106484
...@@ -34,7 +34,7 @@ Before developing applications related to tag read and write, you must declare N ...@@ -34,7 +34,7 @@ Before developing applications related to tag read and write, you must declare N
{ {
"name": "tag-tech", "name": "tag-tech",
"value": "IsoDep" "value": "IsoDep"
}, }
// Add other technologies, // Add other technologies,
// such as NfcB, NfcF, NfcV, Ndef, MifareClassic, MifareUL, and NdefFormatable. // such as NfcB, NfcF, NfcV, Ndef, MifareClassic, MifareUL, and NdefFormatable.
] ]
...@@ -67,8 +67,10 @@ import tag from '@ohos.nfc.tag'; ...@@ -67,8 +67,10 @@ import tag from '@ohos.nfc.tag';
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. 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
import tag from '@ohos.nfc.tag'; import tag from '@ohos.nfc.tag';
import UIAbility from '@ohos.app.ability.UIAbility';
onCreate(want, launchParam) { export default class EntryAbility extends UIAbility {
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.
...@@ -118,8 +120,8 @@ onCreate(want, launchParam) { ...@@ -118,8 +120,8 @@ onCreate(want, launchParam) {
} }
// Other code to read or write this tag. // Other code to read or write this tag.
} }
// Use the same code to handle "NfcA/NfcB/NfcF/NfcV/Ndef/MifareClassic/MifareUL/NdefFormatable". // Use the same code to handle "NfcA/NfcB/NfcF/NfcV/Ndef/MifareClassic/MifareUL/NdefFormatable".
}
} }
``` ```
...@@ -136,14 +138,14 @@ Obtains an **NfcATag** object, which allows access to the tags that use the NFC- ...@@ -136,14 +138,14 @@ Obtains an **NfcATag** object, which allows access to the tags that use the NFC-
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| --------- | ------------------------- | ---- | ---------------------------------------- | | ------- | ------------------- | ---- | ------------------------------------------------------------- |
| 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)**.|
**Return value** **Return value**
| **Type** | **Description** | | **Type** | **Description** |
| ------------------------------------- | ------------- | | ------------------------------------- | ------------------ |
| [NfcATag](js-apis-nfctech.md#nfcatag) | **NfcATag** object obtained.| | [NfcATag](js-apis-nfctech.md#nfcatag) | **NfcATag** object obtained.|
## tag.getNfcA<sup>9+</sup> ## tag.getNfcA<sup>9+</sup>
...@@ -156,22 +158,22 @@ Obtains an **NfcATag** object, which allows access to the tags that use the NFC- ...@@ -156,22 +158,22 @@ Obtains an **NfcATag** object, which allows access to the tags that use the NFC-
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| --------- | ------------------------- | ---- | ---------------------------------------- | | ------- | ------------------- | ---- | ------------------------------------------------------------- |
| 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)**.|
**Return value** **Return value**
| **Type** | **Description** | | **Type** | **Description** |
| ------------------------------------- | ------------- | | ------------------------------------- | ------------------ |
| [NfcATag](js-apis-nfctech.md#nfcatag) | **NfcATag** object obtained.| | [NfcATag](js-apis-nfctech.md#nfcatag) | **NfcATag** object obtained.|
**Error codes** **Error codes**
For details about the error codes, see [NFC Error Codes](../errorcodes/errorcode-nfc.md). For details about the error codes, see [NFC Error Codes](../errorcodes/errorcode-nfc.md).
| ID | Error Message | | ID| Error Message |
| ------- | ---------------------------------------- | | -------- | ----------------------------------------- |
| 3100201 | Tag running state is abnormal in service. | | 3100201 | Tag running state is abnormal in service. |
## tag.getNfcBTag ## tag.getNfcBTag
...@@ -187,14 +189,14 @@ Obtains an **NfcBTag** object, which allows access to the tags that use the NFC- ...@@ -187,14 +189,14 @@ Obtains an **NfcBTag** object, which allows access to the tags that use the NFC-
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| --------- | ------------------------- | ---- | ---------------------------------------- | | ------- | ------------------- | ---- | ------------------------------------------------------------- |
| 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)**.|
**Return value** **Return value**
| **Type** | **Description** | | **Type** | **Description** |
| ------------------------------------- | ------------- | | ------------------------------------- | ------------------ |
| [NfcBTag](js-apis-nfctech.md#nfcbtag) | **NfcBTag** object obtained.| | [NfcBTag](js-apis-nfctech.md#nfcbtag) | **NfcBTag** object obtained.|
## tag.getNfcB<sup>9+</sup> ## tag.getNfcB<sup>9+</sup>
...@@ -207,22 +209,22 @@ Obtains an **NfcBTag** object, which allows access to the tags that use the NFC- ...@@ -207,22 +209,22 @@ Obtains an **NfcBTag** object, which allows access to the tags that use the NFC-
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| --------- | ------------------------- | ---- | ---------------------------------------- | | ------- | ------------------- | ---- | ------------------------------------------------------------- |
| 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)**.|
**Return value** **Return value**
| **Type** | **Description** | | **Type** | **Description** |
| ------------------------------------- | ------------- | | ------------------------------------- | ------------------ |
| [NfcBTag](js-apis-nfctech.md#nfcbtag) | **NfcBTag** object obtained.| | [NfcBTag](js-apis-nfctech.md#nfcbtag) | **NfcBTag** object obtained.|
**Error codes** **Error codes**
For details about the error codes, see [NFC Error Codes](../errorcodes/errorcode-nfc.md). For details about the error codes, see [NFC Error Codes](../errorcodes/errorcode-nfc.md).
| ID | Error Message | | ID| Error Message |
| ------- | ---------------------------------------- | | -------- | ----------------------------------------- |
| 3100201 | Tag running state is abnormal in service. | | 3100201 | Tag running state is abnormal in service. |
## tag.getNfcFTag ## tag.getNfcFTag
...@@ -238,14 +240,14 @@ Obtains an **NfcFTag** object, which allows access to the tags that use the NFC- ...@@ -238,14 +240,14 @@ Obtains an **NfcFTag** object, which allows access to the tags that use the NFC-
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| --------- | ------------------------- | ---- | ---------------------------------------- | | ------- | ------------------- | ---- | ------------------------------------------------------------- |
| 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)**.|
**Return value** **Return value**
| **Type** | **Description** | | **Type** | **Description** |
| ------------------------------------- | ------------- | | ------------------------------------- | ------------------ |
| [NfcFTag](js-apis-nfctech.md#nfcftag) | **NfcFTag** object obtained.| | [NfcFTag](js-apis-nfctech.md#nfcftag) | **NfcFTag** object obtained.|
## tag.getNfcF<sup>9+</sup> ## tag.getNfcF<sup>9+</sup>
...@@ -258,22 +260,22 @@ Obtains an **NfcFTag** object, which allows access to the tags that use the NFC- ...@@ -258,22 +260,22 @@ Obtains an **NfcFTag** object, which allows access to the tags that use the NFC-
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| --------- | ------------------------- | ---- | ---------------------------------------- | | ------- | ------------------- | ---- | ------------------------------------------------------------- |
| 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)**.|
**Return value** **Return value**
| **Type** | **Description** | | **Type** | **Description** |
| ------------------------------------- | ------------- | | ------------------------------------- | ------------------ |
| [NfcFTag](js-apis-nfctech.md#nfcftag) | **NfcFTag** object obtained.| | [NfcFTag](js-apis-nfctech.md#nfcftag) | **NfcFTag** object obtained.|
**Error codes** **Error codes**
For details about the error codes, see [NFC Error Codes](../errorcodes/errorcode-nfc.md). For details about the error codes, see [NFC Error Codes](../errorcodes/errorcode-nfc.md).
| ID | Error Message | | ID| Error Message |
| ------- | ---------------------------------------- | | -------- | ----------------------------------------- |
| 3100201 | Tag running state is abnormal in service. | | 3100201 | Tag running state is abnormal in service. |
## tag.getNfcVTag ## tag.getNfcVTag
...@@ -289,14 +291,14 @@ Obtains an **NfcVTag** object, which allows access to the tags that use the NFC- ...@@ -289,14 +291,14 @@ Obtains an **NfcVTag** object, which allows access to the tags that use the NFC-
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| --------- | ------------------------- | ---- | ---------------------------------------- | | ------- | ------------------- | ---- | ------------------------------------------------------------- |
| 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)**.|
**Return value** **Return value**
| **Type** | **Description** | | **Type** | **Description** |
| ------------------------------------- | ------------- | | ------------------------------------- | ------------------ |
| [NfcVTag](js-apis-nfctech.md#nfcvtag) | **NfcVTag** object obtained.| | [NfcVTag](js-apis-nfctech.md#nfcvtag) | **NfcVTag** object obtained.|
## tag.getNfcV<sup>9+</sup> ## tag.getNfcV<sup>9+</sup>
...@@ -309,22 +311,22 @@ Obtains an **NfcVTag** object, which allows access to the tags that use the NFC- ...@@ -309,22 +311,22 @@ Obtains an **NfcVTag** object, which allows access to the tags that use the NFC-
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| --------- | ------------------------- | ---- | ---------------------------------------- | | ------- | ------------------- | ---- | ------------------------------------------------------------- |
| 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)**.|
**Return value** **Return value**
| **Type** | **Description** | | **Type** | **Description** |
| ------------------------------------- | ------------- | | ------------------------------------- | ------------------ |
| [NfcVTag](js-apis-nfctech.md#nfcvtag) | **NfcVTag** object obtained.| | [NfcVTag](js-apis-nfctech.md#nfcvtag) | **NfcVTag** object obtained.|
**Error codes** **Error codes**
For details about the error codes, see [NFC Error Codes](../errorcodes/errorcode-nfc.md). For details about the error codes, see [NFC Error Codes](../errorcodes/errorcode-nfc.md).
| ID | Error Message | | ID| Error Message |
| ------- | ---------------------------------------- | | -------- | ----------------------------------------- |
| 3100201 | Tag running state is abnormal in service. | | 3100201 | Tag running state is abnormal in service. |
## tag.getIsoDep<sup>9+</sup> ## tag.getIsoDep<sup>9+</sup>
...@@ -337,22 +339,22 @@ Obtains an **IsoDepTag** object, which allows access to the tags that use the IS ...@@ -337,22 +339,22 @@ Obtains an **IsoDepTag** object, which allows access to the tags that use the IS
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| ------- | ------------------- | ---- | ---------------------------------------- | | ------- | ------------------- | ---- | ------------------------------------------------------------- |
| 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)**.|
**Return value** **Return value**
| **Type** | **Description** | | **Type** | **Description** |
| ---------------------------------------- | ----------------------------------- | | ------------------------------------------ | ------------------------------------------------------- |
| [IsoDepTag](js-apis-nfctech.md#isodeptag9) | **IsoDepTag** object obtained.| | [IsoDepTag](js-apis-nfctech.md#isodeptag9) | **IsoDepTag** object obtained.|
**Error codes** **Error codes**
For details about the error codes, see [NFC Error Codes](../errorcodes/errorcode-nfc.md). For details about the error codes, see [NFC Error Codes](../errorcodes/errorcode-nfc.md).
| ID | Error Message | | ID| Error Message |
| ------- | ---------------------------------------- | | -------- | ----------------------------------------- |
| 3100201 | Tag running state is abnormal in service. | | 3100201 | Tag running state is abnormal in service. |
## tag.getNdef<sup>9+</sup> ## tag.getNdef<sup>9+</sup>
...@@ -365,22 +367,22 @@ Obtains an **NdefTag** object, which allows access to the tags in the NFC Data E ...@@ -365,22 +367,22 @@ Obtains an **NdefTag** object, which allows access to the tags in the NFC Data E
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| ------- | ------------------- | ---- | ---------------------------------------- | | ------- | ------------------- | ---- | ------------------------------------------------------------- |
| 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)**.|
**Return value** **Return value**
| **Type** | **Description** | | **Type** | **Description** |
| -------------------------------------- | ------------------------------- | | -------------------------------------- | --------------------------------------------------- |
| [NdefTag](js-apis-nfctech.md#ndeftag9) | **NdefTag** object obtained.| | [NdefTag](js-apis-nfctech.md#ndeftag9) | **NdefTag** object obtained.|
**Error codes** **Error codes**
For details about the error codes, see [NFC Error Codes](../errorcodes/errorcode-nfc.md). For details about the error codes, see [NFC Error Codes](../errorcodes/errorcode-nfc.md).
| ID | Error Message | | ID| Error Message |
| ------- | ---------------------------------------- | | -------- | ----------------------------------------- |
| 3100201 | Tag running state is abnormal in service. | | 3100201 | Tag running state is abnormal in service. |
## tag.getMifareClassic<sup>9+</sup> ## tag.getMifareClassic<sup>9+</sup>
...@@ -393,22 +395,22 @@ Obtains a **MifareClassicTag** object, which allows access to the tags that use ...@@ -393,22 +395,22 @@ Obtains a **MifareClassicTag** object, which allows access to the tags that use
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| ------- | ------------------- | ---- | ---------------------------------------- | | ------- | ------------------- | ---- | ------------------------------------------------------------- |
| 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)**.|
**Return value** **Return value**
| **Type** | **Description** | | **Type** | **Description** |
| ---------------------------------------- | ---------------------------------------- | | --------------------------------------------------------- | ----------------------------------------------------------------------- |
| [MifareClassicTag](js-apis-nfctech.md#mifareclassictag-9) | **MifareClassicTag** object obtained.| | [MifareClassicTag](js-apis-nfctech.md#mifareclassictag-9) | **MifareClassicTag** object obtained.|
**Error codes** **Error codes**
For details about the error codes, see [NFC Error Codes](../errorcodes/errorcode-nfc.md). For details about the error codes, see [NFC Error Codes](../errorcodes/errorcode-nfc.md).
| ID | Error Message | | ID| Error Message |
| ------- | ---------------------------------------- | | -------- | ----------------------------------------- |
| 3100201 | Tag running state is abnormal in service. | | 3100201 | Tag running state is abnormal in service. |
## tag.getMifareUltralight<sup>9+</sup> ## tag.getMifareUltralight<sup>9+</sup>
...@@ -420,22 +422,22 @@ Obtains a **MifareUltralightTag** object, which allows access to the tags that u ...@@ -420,22 +422,22 @@ Obtains a **MifareUltralightTag** object, which allows access to the tags that u
**System capability**: SystemCapability.Communication.NFC.Tag **System capability**: SystemCapability.Communication.NFC.Tag
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| ------- | ------------------- | ---- | ---------------------------------------- | | ------- | ------------------- | ---- | ------------------------------------------------------------- |
| 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)**.|
**Return value** **Return value**
| **Type** | **Description** | | **Type** | **Description** |
| ---------------------------------------- | ---------------------------------------- | | -------------------------------------------------------------- | ----------------------------------------------------------------------------- |
| [MifareUltralightTag](js-apis-nfctech.md#mifareultralighttag9) | **MifareUltralightTag** object obtained.| | [MifareUltralightTag](js-apis-nfctech.md#mifareultralighttag9) | **MifareUltralightTag** object obtained.|
**Error codes** **Error codes**
For details about the error codes, see [NFC Error Codes](../errorcodes/errorcode-nfc.md). For details about the error codes, see [NFC Error Codes](../errorcodes/errorcode-nfc.md).
| ID | Error Message | | ID| Error Message |
| ------- | ---------------------------------------- | | -------- | ----------------------------------------- |
| 3100201 | Tag running state is abnormal in service. | | 3100201 | Tag running state is abnormal in service. |
## tag.getNdefFormatable<sup>9+</sup> ## tag.getNdefFormatable<sup>9+</sup>
...@@ -449,15 +451,15 @@ Obtains an **NdefFormatableTag** object, which allows access to the tags that ar ...@@ -449,15 +451,15 @@ Obtains an **NdefFormatableTag** object, which allows access to the tags that ar
**Return value** **Return value**
| **Type** | **Description** | | **Type** | **Description** |
| ---------------------------------------- | ---------------------------------------- | | --------------------------------------------------------- | ------------------------------------------------------------------------- |
| [NdefFormatableTag](js-apis-nfctech.md#ndefformatabletag) | **NdefFormatableTag** object obtained.| | [NdefFormatableTag](js-apis-nfctech.md#ndefformatabletag) | **NdefFormatableTag** object obtained.|
**Error codes** **Error codes**
For details about the error codes, see [NFC Error Codes](../errorcodes/errorcode-nfc.md). For details about the error codes, see [NFC Error Codes](../errorcodes/errorcode-nfc.md).
| ID | Error Message | | ID| Error Message |
| ------- | ---------------------------------------- | | -------- | ----------------------------------------- |
| 3100201 | Tag running state is abnormal in service. | | 3100201 | Tag running state is abnormal in service. |
## tag.getTagInfo<sup>9+</sup> ## tag.getTagInfo<sup>9+</sup>
...@@ -470,14 +472,14 @@ Obtains **TagInfo** from **Want**, which is initialized by the NFC service and c ...@@ -470,14 +472,14 @@ Obtains **TagInfo** from **Want**, which is initialized by the NFC service and c
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name| Type | Mandatory| Description |
| ---- | ---------------------------------------- | ---- | --------------------------------- | | ------ | ---------------------------------------- | ---- | --------------------------------------------------- |
| 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.| | 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.|
**Return value** **Return value**
| **Type** | **Description** | | **Type** | **Description** |
| ------------------- | --------------------------- | | ------------------- | -------------------------------------------- |
| [TagInfo](#taginfo) | **TagInfo** object obtained.| | [TagInfo](#taginfo) | **TagInfo** object obtained.|
...@@ -491,14 +493,14 @@ Creates an NDEF record based on the specified URI. ...@@ -491,14 +493,14 @@ Creates an NDEF record based on the specified URI.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name| Type | Mandatory| Description |
| ---- | ------ | ---- | ---------------------- | | ------ | ------ | ---- | --------------------------------- |
| uri | string | Yes | Data to write to the NDEF record.| | uri | string | Yes | Data to write to the NDEF record.|
**Return value** **Return value**
| **Type** | **Description** | | **Type** | **Description** |
| -------------------------- | ---------------------------------------- | | -------------------------- | ------------------------------------------------------------ |
| [NdefRecord](#ndefrecord9) | NDEF record created. For details, see *NFCForum-TS-NDEF_1.0*.| | [NdefRecord](#ndefrecord9) | NDEF record created. For details, see *NFCForum-TS-NDEF_1.0*.|
**Example** **Example**
...@@ -530,15 +532,15 @@ Creates an NDEF record based on the specified text data and encoding type. ...@@ -530,15 +532,15 @@ Creates an NDEF record based on the specified text data and encoding type.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------------ | | ------ | ------ | ---- | ------------------------------------- |
| text | string | Yes | Text to write to the NDEF record.| | text | string | Yes | Text to write to the NDEF record.|
| locale | string | Yes | Encoding mode of the text. | | locale | string | Yes | Encoding mode of the text. |
**Return value** **Return value**
| **Type** | **Description** | | **Type** | **Description** |
| -------------------------- | ---------------------------------------- | | -------------------------- | ------------------------------------------------------------ |
| [NdefRecord](#ndefrecord9) | NDEF record created. For details, see *NFCForum-TS-NDEF_1.0*.| | [NdefRecord](#ndefrecord9) | NDEF record created. For details, see *NFCForum-TS-NDEF_1.0*.|
**Example** **Example**
...@@ -572,15 +574,15 @@ Creates an NDEF record based on the specified MIME data and type. ...@@ -572,15 +574,15 @@ Creates an NDEF record based on the specified MIME data and type.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| -------- | -------- | ---- | ---------------------------------------- | | -------- | -------- | ---- | ------------------------------------------------------- |
| mimeType | string | Yes | MIME type that complies with RFC rules, for example, **text/plain** or **image/jpeg**.| | mimeType | string | Yes | MIME type that complies with RFC rules, for example, **text/plain** or **image/jpeg**.|
| mimeData | number[] | Yes | MIME data, which consists of hexadecimal numbers ranging from **0x00** to **0xFF**. | | mimeData | number[] | Yes | MIME data, which consists of hexadecimal numbers ranging from **0x00** to **0xFF**.|
**Return value** **Return value**
| **Type** | **Description** | | **Type** | **Description** |
| -------------------------- | ---------------------------------------- | | -------------------------- | ------------------------------------------------------------ |
| [NdefRecord](#ndefrecord9) | NDEF record created. For details, see *NFCForum-TS-NDEF_1.0*.| | [NdefRecord](#ndefrecord9) | NDEF record created. For details, see *NFCForum-TS-NDEF_1.0*.|
**Example** **Example**
...@@ -612,8 +614,8 @@ Creates an NDEF record based on application-specific data. ...@@ -612,8 +614,8 @@ Creates an NDEF record based on application-specific data.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| ------------ | -------- | ---- | ----------------------------------- | | ------------ | -------- | ---- | ------------------------------------------------------- |
| domainName | string | Yes | Bundle name of the application or domain name of the organization that releases the applications. | | domainName | string | Yes | Bundle name of the application or domain name of the organization that releases the applications. |
| type | string | Yes | Type of the application data. | | type | string | Yes | Type of the application data. |
| externalData | number[] | Yes | Application data, which consists of hexadecimal numbers ranging from **0x00** to **0xFF**.| | externalData | number[] | Yes | Application data, which consists of hexadecimal numbers ranging from **0x00** to **0xFF**.|
...@@ -621,7 +623,7 @@ Creates an NDEF record based on application-specific data. ...@@ -621,7 +623,7 @@ Creates an NDEF record based on application-specific data.
**Return value** **Return value**
| **Type** | **Description** | | **Type** | **Description** |
| -------------------------- | ---------------------------------------- | | -------------------------- | ------------------------------------------------------------ |
| [NdefRecord](#ndefrecord9) | NDEF record created. For details, see *NFCForum-TS-NDEF_1.0*.| | [NdefRecord](#ndefrecord9) | NDEF record created. For details, see *NFCForum-TS-NDEF_1.0*.|
**Example** **Example**
...@@ -655,14 +657,14 @@ Converts an NDEF message to bytes. ...@@ -655,14 +657,14 @@ Converts an NDEF message to bytes.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| ----------- | ---------------------------------------- | ---- | ----------- | | ----------- | ---------------------------------------------- | ---- | ------------------ |
| ndefMessage | [NdefMessage](js-apis-nfctech.md#ndefmessage9) | Yes | NDEF message to convert.| | ndefMessage | [NdefMessage](js-apis-nfctech.md#ndefmessage9) | Yes | NDEF message to convert.|
**Return value** **Return value**
| **Type** | **Description** | | **Type**| **Description** |
| -------- | ---------------------------------------- | | -------- | ------------------------------------------------------------------------------------- |
| number[] | NDEF message in bytes, which consists of hexadecimal numbers ranging from **0x00** to **0xFF**.| | number[] | NDEF message in bytes, which consists of hexadecimal numbers ranging from **0x00** to **0xFF**.|
**Example** **Example**
...@@ -696,14 +698,14 @@ Creates an NDEF message from raw byte data. The data must comply with the NDEF r ...@@ -696,14 +698,14 @@ Creates an NDEF message from raw byte data. The data must comply with the NDEF r
**Parameters** **Parameters**
| **Name**| **Type** | **Mandatory**| **Description** | | **Name**| **Type**| **Mandatory**| **Description** |
| ------- | -------- | ------ | ---------------------------------------- | | ---------- | -------- | -------- | ---------------------------------------------------------------------------------- |
| 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.| | 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.|
**Return value** **Return value**
| **Type** | **Description** | | **Type** | **Description** |
| ---------------------------------------- | ---------------------------------------- | | ---------------------------------------------- | ------------------------------------------------------------- |
| [NdefMessage](js-apis-nfctech.md#ndefmessage9) | NDEF message created. For details, see *NFCForum-TS-NDEF_1.0*.| | [NdefMessage](js-apis-nfctech.md#ndefmessage9) | NDEF message created. For details, see *NFCForum-TS-NDEF_1.0*.|
**Example** **Example**
...@@ -731,13 +733,13 @@ Creates an NDEF message from the NDEF records list. ...@@ -731,13 +733,13 @@ Creates an NDEF message from the NDEF records list.
**Parameters** **Parameters**
| **Name** | **Type** | **Mandatory**| **Description** | | **Name** | **Type** | **Mandatory**| **Description** |
| ----------- | ---------------------------------------- | ------ | ---------------------------------------- | | ----------- | --------------------------------------------- | -------- | ---------------------------------------------------------------- |
| 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*.| | 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*.|
**Return value** **Return value**
| **Type** | **Description** | | **Type** | **Description** |
| ---------------------------------------- | ---------------------------------------- | | ---------------------------------------------- | ------------------------------------------------------------- |
| [NdefMessage](js-apis-nfctech.md#ndefmessage9) | NDEF message created. For details, see *NFCForum-TS-NDEF_1.0*.| | [NdefMessage](js-apis-nfctech.md#ndefmessage9) | NDEF message created. For details, see *NFCForum-TS-NDEF_1.0*.|
**Example** **Example**
...@@ -766,10 +768,10 @@ Defines the **TagInfo** object, which provides information about the tag technol ...@@ -766,10 +768,10 @@ Defines the **TagInfo** object, which provides information about the tag technol
**Required permissions**: ohos.permission.NFC_TAG **Required permissions**: ohos.permission.NFC_TAG
| **Name** | **Type** | **Readable**| **Writable**| **Description** | | **Name** | **Type** | **Readable**| **Writable**| **Description** |
| ----------------------------- | ---------------------------------------- | ------ | ------ | ---------------------------------------- | | ----------------------------- | ------------------------------------------------------------- | -------- | -------- | -------------------------------------------------------------------------------------------- |
| uid<sup>9+</sup> | number[] | Yes | No | Tag unique identifier (UID), which consists of hexadecimal numbers ranging from **0x00** to **0xFF**. | | 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. | | 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](#tagtaginfo) instead.| | supportedProfiles | number[] | Yes | No | Supported profiles. This parameter is not supported since API version 9. Use [tag.TagInfo#technology](#tagtaginfo) 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. | | 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. | | 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.| | 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.|
...@@ -778,12 +780,12 @@ Defines an NDEF record. For details, see *NFCForum-TS-NDEF_1.0*. ...@@ -778,12 +780,12 @@ Defines an NDEF record. For details, see *NFCForum-TS-NDEF_1.0*.
**System capability**: SystemCapability.Communication.NFC.Tag **System capability**: SystemCapability.Communication.NFC.Tag
| **Name** | **Type** | **Readable**| **Writable**| **Description** | | **Name**| **Type**| **Readable**| **Writable**| **Description** |
| ------- | -------- | ------ | ------ | ---------------------------------------- | | -------- | -------- | -------- | -------- | ----------------------------------------------------------------------------------------- |
| tnf | number | Yes | No | Type name field (TNF) of the NDEF record. | | tnf | number | Yes | No | Type name field (TNF) of the NDEF record. |
| rtdType | number[] | Yes | No | Record type definition (RTD) of the NDEF record. It consists of hexadecimal numbers ranging from **0x00** to **0xFF**.| | rtdType | number[] | Yes | No | Record type definition (RTD) of the NDEF record. It consists of hexadecimal numbers ranging from **0x00** to **0xFF**.|
| id | number[] | Yes | No | NDEF record ID, which consists of hexadecimal numbers ranging from **0x00** to **0xFF**.| | id | number[] | Yes | No | NDEF record ID, which consists of hexadecimal numbers ranging from **0x00** to **0xFF**. |
| payload | number[] | Yes | No | NDEF payload, which consists of hexadecimal numbers ranging from **0x00** to **0xFF**.| | payload | number[] | Yes | No | NDEF payload, which consists of hexadecimal numbers ranging from **0x00** to **0xFF**. |
## Technology Type Definition ## Technology Type Definition
Enumerates the tag technology types. Enumerates the tag technology types.
...@@ -791,7 +793,7 @@ Enumerates the tag technology types. ...@@ -791,7 +793,7 @@ Enumerates the tag technology types.
**System capability**: SystemCapability.Communication.NFC.Tag **System capability**: SystemCapability.Communication.NFC.Tag
| **Name** | **Value**| **Description** | | **Name** | **Value**| **Description** |
| ---------------------------- | ----- | ------------------------ | | ---------------------------- | ------ | --------------------------- |
| NFC_A | 1 | NFC-A (ISO 14443-3A). | | NFC_A | 1 | NFC-A (ISO 14443-3A). |
| NFC_B | 2 | NFC-B (ISO 14443-3B).| | NFC_B | 2 | NFC-B (ISO 14443-3B).|
| ISO_DEP | 3 | ISO-DEP (ISO 14443-4).| | ISO_DEP | 3 | ISO-DEP (ISO 14443-4).|
...@@ -808,10 +810,10 @@ Enumerates the TNF types. For details, see *NFCForum-TS-NDEF_1.0*. ...@@ -808,10 +810,10 @@ Enumerates the TNF types. For details, see *NFCForum-TS-NDEF_1.0*.
**System capability**: SystemCapability.Communication.NFC.Tag **System capability**: SystemCapability.Communication.NFC.Tag
| **Name** | **Value**| **Description** | | **Name** | **Value**| **Description** |
| ---------------- | ----- | ---------------------------------------- | | ---------------- | ------ | ------------------------------------------------ |
| TNF_EMPTY | 0x0 | Empty. | | TNF_EMPTY | 0x0 | Empty. |
| TNF_WELL_KNOWN | 0x1 | NFC Forum Well Known Type [NFC RTD]. | | TNF_WELL_KNOWN | 0x1 | NFC Forum Well Known Type [NFC RTD]. |
| TNF_MEDIA | 0x2 | Media-type as defined in RFC 2046 [RFC 2046].| | TNF_MEDIA | 0x2 | Media-type as defined in RFC 2046 [RFC 2046]. |
| TNF_ABSOLUTE_URI | 0x3 | Absolute URI as defined in RFC 3986 [RFC 3986].| | TNF_ABSOLUTE_URI | 0x3 | Absolute URI as defined in RFC 3986 [RFC 3986].|
| TNF_EXT_APP | 0x4 | NFC Forum external type [NFC RTD]. | | TNF_EXT_APP | 0x4 | NFC Forum external type [NFC RTD]. |
| TNF_UNKNOWN | 0x5 | Unknown. | | TNF_UNKNOWN | 0x5 | Unknown. |
...@@ -822,10 +824,10 @@ Enumerates the NDEF record types. For details about the RTD, see *NFCForum-TS-ND ...@@ -822,10 +824,10 @@ Enumerates the NDEF record types. For details about the RTD, see *NFCForum-TS-ND
**System capability**: SystemCapability.Communication.NFC.Tag **System capability**: SystemCapability.Communication.NFC.Tag
| **Name** | **Value** | **Description** | | **Name** | **Value**| **Description** |
| --------------------- | ------ | ------------------ | | --------------------- | ------ | ----------------------- |
| RTD_TEXT<sup>9+</sup> | [0x54] | NDEF record of the text type. | | RTD_TEXT<sup>9+</sup> | [0x54] | NDEF record of the text type.|
| RTD_URI<sup>9+</sup> | [0x55] | NDEF record of the URI type.| | RTD_URI<sup>9+</sup> | [0x55] | NDEF record of the URI type. |
## NfcForumType<sup>9+</sup> ## NfcForumType<sup>9+</sup>
Enumerates the NFC Forum tag types. Enumerates the NFC Forum tag types.
...@@ -833,7 +835,7 @@ Enumerates the NFC Forum tag types. ...@@ -833,7 +835,7 @@ Enumerates the NFC Forum tag types.
**System capability**: SystemCapability.Communication.NFC.Tag **System capability**: SystemCapability.Communication.NFC.Tag
| **Name** | **Value**| **Description** | | **Name** | **Value**| **Description** |
| ---------------- | ----- | ----------------- | | ---------------- | ------ | -------------------- |
| NFC_FORUM_TYPE_1 | 1 | NFC Forum tag type 1. | | NFC_FORUM_TYPE_1 | 1 | NFC Forum tag type 1. |
| NFC_FORUM_TYPE_2 | 2 | NFC Forum tag type 2. | | NFC_FORUM_TYPE_2 | 2 | NFC Forum tag type 2. |
| NFC_FORUM_TYPE_3 | 3 | NFC Forum tag type 3. | | NFC_FORUM_TYPE_3 | 3 | NFC Forum tag type 3. |
...@@ -846,7 +848,7 @@ Enumerates the MIFARE Classic tag types. ...@@ -846,7 +848,7 @@ Enumerates the MIFARE Classic tag types.
**System capability**: SystemCapability.Communication.NFC.Tag **System capability**: SystemCapability.Communication.NFC.Tag
| **Name** | **Value**| **Description** | | **Name** | **Value**| **Description** |
| ------------ | ----- | ----------------- | | ------------ | ------ | -------------------- |
| TYPE_UNKNOWN | 0 | Unknown type. | | TYPE_UNKNOWN | 0 | Unknown type. |
| TYPE_CLASSIC | 1 | MIFARE Classic.| | TYPE_CLASSIC | 1 | MIFARE Classic.|
| TYPE_PLUS | 2 | MIFARE Plus. | | TYPE_PLUS | 2 | MIFARE Plus. |
...@@ -858,7 +860,7 @@ Enumerates the sizes of a MIFARE Classic tag. ...@@ -858,7 +860,7 @@ Enumerates the sizes of a MIFARE Classic tag.
**System capability**: SystemCapability.Communication.NFC.Tag **System capability**: SystemCapability.Communication.NFC.Tag
| **Name** | **Value**| **Description** | | **Name** | **Value**| **Description** |
| ------------ | ----- | ------------------ | | ------------ | ------ | --------------------------------- |
| MC_SIZE_MINI | 320 | Each tag has 5 sectors, and each sector has 4 blocks. | | MC_SIZE_MINI | 320 | Each tag has 5 sectors, and each sector has 4 blocks. |
| MC_SIZE_1K | 1024 | Each tag has 16 sectors, and each sector has 4 blocks.| | MC_SIZE_1K | 1024 | Each tag has 16 sectors, and each sector has 4 blocks.|
| MC_SIZE_2K | 2048 | Each tag has 32 sectors, and each sector has 4 blocks.| | MC_SIZE_2K | 2048 | Each tag has 32 sectors, and each sector has 4 blocks.|
...@@ -870,9 +872,8 @@ Enumerates the MIFARE Ultralight tag types. ...@@ -870,9 +872,8 @@ Enumerates the MIFARE Ultralight tag types.
**System capability**: SystemCapability.Communication.NFC.Tag **System capability**: SystemCapability.Communication.NFC.Tag
| **Name** | **Value**| **Description** | | **Name** | **Value**| **Description** |
| ----------------- | ----- | ---------------------- | | ----------------- | ------ | ------------------------- |
| TYPE_UNKNOWN | 0 | Unknown type. | | TYPE_UNKNOWN | 0 | Unknown type. |
| TYPE_ULTRALIGHT | 1 | MIFARE Ultralight. | | TYPE_ULTRALIGHT | 1 | MIFARE Ultralight. |
| TYPE_ULTRALIGHT_C | 2 | MIFARE Ultralight C.| | TYPE_ULTRALIGHT_C | 2 | MIFARE Ultralight C.|
<!--no_check--> <!--no_check-->
...@@ -43,10 +43,10 @@ The returned **SEService** object is available only when **true** is returned by ...@@ -43,10 +43,10 @@ The returned **SEService** object is available only when **true** is returned by
**Parameters** **Parameters**
| **Name**| **Type** | **Description** | | **Name**| **Type** | **Mandatory**| **Description** |
| ---------- | ---------------------------------------------------- | -------------------- | | ---------- | ---------------------------------------------------- | ------ | -------------------- |
| type | string | 'serviceState' | | type | string | Yes | 'serviceState' |
| callback | Callback<[ServiceState](#secureelementservicestate)> | Callback invoked to return the SE service status.| | callback | Callback<[ServiceState](#secureelementservicestate)> | Yes | Callback invoked to return the SE service status.|
**Return value** **Return value**
...@@ -59,20 +59,18 @@ The returned **SEService** object is available only when **true** is returned by ...@@ -59,20 +59,18 @@ The returned **SEService** object is available only when **true** is returned by
```js ```js
import secureElement from '@ohos.secureElement'; import secureElement from '@ohos.secureElement';
@State result: string = ''; let nfcSEService = null;
@State nfcSEService: secureElement.SEService = null;
this.result = "Service state is Unkown";
try { try {
this.nfcSEService = secureElement.newSEService("serviceState", (state) => { nfcSEService = secureElement.newSEService("serviceState", (state) => {
if (state == secureElement.ServiceState.DISCONNECTED) { if (state == secureElement.ServiceState.DISCONNECTED) {
this.result = "Service state is Disconnected"; console.log("Service state is Disconnected");
} else { } else {
this.result = "Service state is Connected"; console.log.("Service state is Connected");
} }
}); });
} catch (e) { } catch (e) {
this.result = "newSEService occurs exception:" + e.message; console.log("newSEService occurs exception:" + e.message);
} }
``` ```
...@@ -95,35 +93,34 @@ Obtains the available SE readers. The returned array cannot contain duplicate ob ...@@ -95,35 +93,34 @@ Obtains the available SE readers. The returned array cannot contain duplicate ob
```js ```js
import secureElement from '@ohos.secureElement'; import secureElement from '@ohos.secureElement';
@State result: string = ''; let nfcSEService = null;
@State nfcSEService: secureElement.SEService = null; let nfcServiceState = null;
@State nfcServiceState: secureElement.ServiceState = null; let nfcOmaReader = null;
@State nfcOmaReader: secureElement.Reader = null; let nfcOmaReaderList = null;
@State nfcOmaReaderList: secureElement.Reader[] = null;
// get SEService // get SEService
try { try {
this.nfcSEService = secureElement.newSEService("serviceState", (state) => { nfcSEService = secureElement.newSEService("serviceState", (state) => {
if (state == secureElement.ServiceState.DISCONNECTED) { if (state == secureElement.ServiceState.DISCONNECTED) {
this.result = "Service state is Disconnected"; console.log("Service state is Disconnected");
} else { } else {
this.result = "Service state is Connected"; console.log("Service state is Connected");
} }
}); });
} catch (e) { } catch (e) {
this.result = "newSEService excpetion:" + e.message; console.log("newSEService excpetion:" + e.message);
} }
try { try {
this.nfcOmaReaderList = this.nfcSEService.getReaders(); nfcOmaReaderList = nfcSEService.getReaders();
if (this.nfcOmaReaderList != null && this.nfcOmaReaderList.length > 0) { if (nfcOmaReaderList != null && nfcOmaReaderList.length > 0) {
this.nfcOmaReader = this.nfcOmaReaderList[0]; nfcOmaReader = this.nfcOmaReaderList[0];
this.result = "get reader successfully"; console.log("get reader successfully");
} else { } else {
this.result = "get reader failed"; console.log("get reader failed");
} }
} catch (e) { } catch (e) {
this.result = "getReaders exception:" + e.message; console.log("getReaders exception:" + e.message);
} }
``` ```
...@@ -146,20 +143,19 @@ Checks whether this SE service is connected. ...@@ -146,20 +143,19 @@ Checks whether this SE service is connected.
```JS ```JS
import secureElement from '@ohos.secureElement'; import secureElement from '@ohos.secureElement';
@State result: string = '' let nfcSEService = null;
@State nfcSEService: secureElement.SEService = null;
try { try {
let ret: boolean; let ret: boolean;
// refer to newSEService for this.nfcSEService // refer to newSEService for this.nfcSEService
ret = this.nfcSEService.isConnected(); ret = nfcSEService.isConnected();
if (ret) { if (ret) {
this.result = 'get state: connected'; console.log("get state: connected");
} else { } else {
this.result = 'get state: not connected'; console.log("get state: not connected");
} }
} catch (e) { } catch (e) {
this.result = "isConnected exception: " + e.message; console.log("isConnected exception: " + e.message);
} }
``` ```
...@@ -176,15 +172,15 @@ Releases all SE resources allocated to this service. After that, [isConnected](# ...@@ -176,15 +172,15 @@ Releases all SE resources allocated to this service. After that, [isConnected](#
```js ```js
import secureElement from '@ohos.secureElement'; import secureElement from '@ohos.secureElement';
@State result: string = '';
@State nfcSEService: secureElement.SEService = null; let nfcSEService = null;
try { try {
// refer to newSEService for this.nfcSEService // refer to newSEService for this.nfcSEService
this.nfcSEService.shutdown(); nfcSEService.shutdown();
this.result = "shutdown successfully"; console.log("shutdown successfully");
} catch (e) { } catch (e) {
this.result = "shutdown exception:" + e.message; console.log("shutdown exception:" + e.message);
} }
``` ```
...@@ -207,15 +203,14 @@ Obtains the version of the Open Mobile API Specification used for the implementa ...@@ -207,15 +203,14 @@ Obtains the version of the Open Mobile API Specification used for the implementa
```JS ```JS
import secureElement from '@ohos.secureElement'; import secureElement from '@ohos.secureElement';
@State result: string = ''; let nfcSEService = null;
@State nfcSEService: secureElement.SEService = null;
this.result = "version: " this.result = "version: "
try { try {
// refer to newSEService for this.nfcSEService // refer to newSEService for this.nfcSEService
this.result += this.nfcSEService.getVersion(); console.log("version: " + nfcSEService.getVersion());
} catch (e) { } catch (e) {
this.result = "getVersion exception:" + e.message; console.log("getVersion exception:" + e.message);
} }
``` ```
...@@ -238,14 +233,13 @@ Obtains the reader name. If the card reader is a SIM reader, its name must be in ...@@ -238,14 +233,13 @@ Obtains the reader name. If the card reader is a SIM reader, its name must be in
```js ```js
import secureElement from '@ohos.secureElement'; import secureElement from '@ohos.secureElement';
@State result: string = ''; let nfcOmaReader = null;
@State nfcOmaReader: secureElement.Reader = null;
try { try {
// refer to SEService.getReaders for this.nfcOmaReader // refer to SEService.getReaders for this.nfcOmaReader
this.result = this.nfcOmaReader.getName(); console.log(nfcOmaReader.getName());
} catch (e) { } catch (e) {
this.result = "getName exception:" + e.message; console.log("getName exception:" + e.message);
} }
``` ```
...@@ -276,18 +270,17 @@ For details about error codes, see [SE Error Codes](../errorcodes/errorcode-se.m ...@@ -276,18 +270,17 @@ For details about error codes, see [SE Error Codes](../errorcodes/errorcode-se.m
```js ```js
import secureElement from '@ohos.secureElement'; import secureElement from '@ohos.secureElement';
@State result: string = ''; let nfcOmaReader = null;
@State nfcOmaReader: secureElement.Reader = null;
try { try {
// refer to SEService.getReaders for this.nfcOmaReader // refer to SEService.getReaders for this.nfcOmaReader
if (this.nfcOmaReader.isSecureElementPresent()) { if (nfcOmaReader.isSecureElementPresent()) {
this.result = "isSecureElementPresent TRUE"; console.log("isSecureElementPresent TRUE");
} else { } else {
this.result = "isSecureElementPresent FALSE"; console.log("isSecureElementPresent FALSE");
} }
} catch (e) { } catch (e) {
this.result = "isSecureElementPresent exception:" + e.message; console.log("isSecureElementPresent exception:" + e.message);
} }
``` ```
...@@ -319,20 +312,19 @@ For details about error codes, see [SE Error Codes](../errorcodes/errorcode-se.m ...@@ -319,20 +312,19 @@ For details about error codes, see [SE Error Codes](../errorcodes/errorcode-se.m
```js ```js
import secureElement from '@ohos.secureElement'; import secureElement from '@ohos.secureElement';
@State result: string = ''; let nfcOmaReader = null;
@State nfcOmaReader: secureElement.Reader = null; let nfcOmaSession = null;
@State nfcOmaSession: secureElement.Session = null;
try { try {
// refer to SEService.getReaders for this.nfcOmaReader // refer to SEService.getReaders for this.nfcOmaReader
this.nfcOmaSession = this.nfcOmaReader.openSession(); nfcOmaSession = nfcOmaReader.openSession();
if (this.nfcOmaSession) { if (nfcOmaSession) {
this.result = "get session successfully"; console.log("get session successfully");
} else { } else {
this.result = "get session failed"; console.log("get session failed");
} }
} catch (e) { } catch (e) {
this.result = "OpenSession exception: " + e.message; console.log("OpenSession exception: " + e.message);
} }
``` ```
...@@ -357,15 +349,14 @@ For details about error codes, see [SE Error Codes](../errorcodes/errorcode-se.m ...@@ -357,15 +349,14 @@ For details about error codes, see [SE Error Codes](../errorcodes/errorcode-se.m
```js ```js
import secureElement from '@ohos.secureElement'; import secureElement from '@ohos.secureElement';
@State result: string = ''; nfcOmaReader = null;
@State nfcOmaReader: secureElement.Reader = null;
try { try {
// refer to SEService.getReaders for this.nfcOmaReader // refer to SEService.getReaders for this.nfcOmaReader
this.nfcOmaReader.closeSessions(); nfcOmaReader.closeSessions();
this.result = "close Sessions successfully"; console.log("close Sessions successfully");
} catch (e) { } catch (e) {
this.result = "closeSessions exception:" + e.message; console.log("closeSessions exception:" + e.message);
} }
``` ```
...@@ -388,20 +379,19 @@ Obtains the reader that provides this session. ...@@ -388,20 +379,19 @@ Obtains the reader that provides this session.
```js ```js
import secureElement from '@ohos.secureElement'; import secureElement from '@ohos.secureElement';
@State result: string = ''; let nfcOmaReader = null;
@State nfcOmaReader: secureElement.Reader = null; let nfcOmaSession = null;
@State nfcOmaSession: secureElement.Session = null;
try { try {
// refer to Reader.openSession for this.nfcOmaSession // See Reader.openSession for this.nfcOmaSession.
this.nfcOmaReader = this.nfcOmaSession.getReader(); nfcOmaReader = nfcOmaSession.getReader();
if (this.nfcOmaReader) { if (nfcOmaReader) {
this.result = "get reader successfully"; console.log("get reader successfully");
} else { } else {
this.result = "get reader failed"; console.log("get reader failed");
} }
} catch (e) { } catch (e) {
this.result = "getReader exception:" + e.message; console.log("getReader exception:" + e.message);
} }
``` ```
...@@ -432,24 +422,25 @@ For details about error codes, see [SE Error Codes](../errorcodes/errorcode-se.m ...@@ -432,24 +422,25 @@ For details about error codes, see [SE Error Codes](../errorcodes/errorcode-se.m
```js ```js
import secureElement from '@ohos.secureElement'; import secureElement from '@ohos.secureElement';
@State result: string = ''; let nfcOmaSession = null;
@State nfcOmaSession: secureElement.Session = null; let str = "";
try { try {
// refer to Reader.openSession for this.nfcOmaSession // See Reader.openSession for this.nfcOmaSession.
let ret = this.nfcOmaSession.getATR(); let ret = nfcOmaSession.getATR();
if (ret) { if (ret) {
this.result = "getATR result:["; str = 'getATR result:[';
for (let i = 0; i < ret.length; ++i) { for (let i = 0; i < ret.length; ++i) {
this.result += ret[i]; str += ret[i];
this.result += ' '; str += ' ';
} }
this.result += ']'; str += ']';
console.log(str);
} else { } else {
this.result = "getATR result is null"; console.log("getATR result is null");
} }
} catch (e) { } catch (e) {
this.result = "getATR exception:" + e.message; console.log("getATR exception:" + e.message);
} }
``` ```
...@@ -474,15 +465,14 @@ For details about error codes, see [SE Error Codes](../errorcodes/errorcode-se.m ...@@ -474,15 +465,14 @@ For details about error codes, see [SE Error Codes](../errorcodes/errorcode-se.m
```js ```js
import secureElement from '@ohos.secureElement'; import secureElement from '@ohos.secureElement';
@State result: string = ''; let nfcOmaSession = null;
@State nfcOmaSession: secureElement.Session = null;
try { try {
// refer to Reader.openSession for this.nfcOmaSession // See Reader.openSession for this.nfcOmaSession.
this.nfcOmaSession.close(); nfcOmaSession.close();
this.result = "session close successfully"; console.log("session close successfully");
} catch (e) { } catch (e) {
this.result = "session close exception:" + e.message; console.log("session close exception:" + e.message);
} }
``` ```
...@@ -509,19 +499,18 @@ For details about error codes, see [SE Error Codes](../errorcodes/errorcode-se.m ...@@ -509,19 +499,18 @@ For details about error codes, see [SE Error Codes](../errorcodes/errorcode-se.m
```Js ```Js
import secureElement from '@ohos.secureElement'; import secureElement from '@ohos.secureElement';
@State result: string = ''; let nfcOmaSession = null;
@State nfcOmaSession: secureElement.Session = null;
try { try {
// refer to Reader.openSession for this.nfcOmaSession // See Reader.openSession for this.nfcOmaSession.
let ret = this.nfcOmaSession.isClosed(); let ret = nfcOmaSession.isClosed();
if (ret) { if (ret) {
this.result = "session state is closed"; console.log("session state is closed");
} else { } else {
this.result = "session state is not closed"; console.log("session state is not closed");
} }
} catch (e) { } catch (e) {
this.result = "isClosed exception:" + e.message; console.log("isClosed exception:" + e.message);
} }
``` ```
...@@ -546,21 +535,20 @@ For details about error codes, see [SE Error Codes](../errorcodes/errorcode-se.m ...@@ -546,21 +535,20 @@ For details about error codes, see [SE Error Codes](../errorcodes/errorcode-se.m
```js ```js
import secureElement from '@ohos.secureElement'; import secureElement from '@ohos.secureElement';
@State result: string = ''; let nfcOmaSession = null;
@State nfcOmaSession: secureElement.Session = null;
try { try {
// refer to Reader.openSession for this.nfcOmaSession // See Reader.openSession for this.nfcOmaSession.
this.nfcOmaSession.closeChannels(); nfcOmaSession.closeChannels();
this.result = "close Channels successfully"; console.log("close Channels successfully");
} catch (e) { } catch (e) {
this.result = "closeChannels exception:" + e.message; console.log("closeChannels exception:" + e.message);
} }
``` ```
## Session.openBasicChannel ## Session.openBasicChannel
openBasicChannel(aid: number[]): Promise<Channel> openBasicChannel(aid: number[]): Promise\<Channel>
Opens a basic channel. This API uses a promise to return the result. Opens a basic channel. This API uses a promise to return the result.
...@@ -568,15 +556,15 @@ Opens a basic channel. This API uses a promise to return the result. ...@@ -568,15 +556,15 @@ Opens a basic channel. This API uses a promise to return the result.
**Parameters** **Parameters**
| **Name**| **Type**| **Description** | | **Name**| **Type**| **Mandatory**| **Description** |
| ---------- | -------- | ------------------------------------------------------------ | | ---------- | -------- | ------ | ------------------------------------------------------------ |
| aid | number[] | AIDs of the applets selected on this channel or null if no applet is selected. | | aid | number[] | Yes |AIDs of the applets selected on this channel or null if no applet is selected.|
**Return value** **Return value**
| **Type**| **Description** | | **Type**| **Description** |
| -------- | --------------------- | | -------- | --------------------- |
| Channel | Returns the **Channel** instance opened. If the SE cannot provide a new basic channel or cannot obtain the access control rule due to lack of available basic channels, null will be returned. | | Channel | Returns the **Channel** instance opened. If the SE cannot provide a new basic channel or cannot obtain the access control rule due to lack of available basic channels, null will be returned.|
**Error codes** **Error codes**
...@@ -594,27 +582,26 @@ For details about error codes, see [SE Error Codes](../errorcodes/errorcode-se.m ...@@ -594,27 +582,26 @@ For details about error codes, see [SE Error Codes](../errorcodes/errorcode-se.m
```js ```js
import secureElement from '@ohos.secureElement'; import secureElement from '@ohos.secureElement';
@State result: string = ''; let nfcOmaSession = null;
@State nfcOmaSession: secureElement.Session = null; let nfcOmaChannel = null;
@State nfcOmaChannel: secureElement.Channel = null;
try { try {
// See Reader.openSession for this.nfcOmaSession. // See Reader.openSession for this.nfcOmaSession.
let getPromise = this.nfcOmaSession.openBasicChannel(this.aidArray); let getPromise = nfcOmaSession.openBasicChannel(this.aidArray);
getPromise.then((channel) => { getPromise.then((channel) => {
this.nfcOmaChannel = channel; nfcOmaChannel = channel;
this.result = "openBasicChannel1 get channel successfully"; console.log("openBasicChannel1 get channel successfully");
}).catch ((err) => { }).catch ((err) => {
this.result = "openBasicChannel1 exception:" + err.message; console.log("openBasicChannel1 exception:" + err.message);
}); });
} catch (e) { } catch (e) {
this.result = "OpenBasicChannel1 exception:" + e.message; console.log("OpenBasicChannel1 exception:" + e.message);
} }
``` ```
## Session.openBasicChannel ## Session.openBasicChannel
openBasicChannel(aid: number[], callback: AsyncCallback<Channel>): void openBasicChannel(aid: number[], callback: AsyncCallback\<Channel>): void
Opens a basic channel. This API uses an asynchronous callback to return the result. Opens a basic channel. This API uses an asynchronous callback to return the result.
...@@ -622,10 +609,10 @@ Opens a basic channel. This API uses an asynchronous callback to return the resu ...@@ -622,10 +609,10 @@ Opens a basic channel. This API uses an asynchronous callback to return the resu
**Parameters** **Parameters**
| **Name**| **Type** | **Description** | | **Name**| **Type** | **Mandatory**| **Description** |
| ---------- | ---------------------- | ------------------------------------------------------------ | | ---------- | ---------------------- | ------ | ------------------------------------------------------------ |
| aid | number[] | AIDs of the applets selected on this channel or null if no applet is selected. | | aid | number[] | Yes | AIDs of the applets selected on this channel or null if no applet is selected.|
| callback | AsyncCallback<Channel> | Callback invoked to return the **Channel** instance opened. If the SE cannot provide a new basic channel or cannot obtain the access control rule due to lack of available basic channels, null will be returned. | | callback | AsyncCallback\<Channel> | Yes | Callback invoked to return the **Channel** instance opened. If the SE cannot provide a new basic channel or cannot obtain the access control rule due to lack of available basic channels, null will be returned. |
**Error codes** **Error codes**
...@@ -643,29 +630,28 @@ For details about error codes, see [SE Error Codes](../errorcodes/errorcode-se.m ...@@ -643,29 +630,28 @@ For details about error codes, see [SE Error Codes](../errorcodes/errorcode-se.m
```js ```js
import secureElement from '@ohos.secureElement'; import secureElement from '@ohos.secureElement';
@State result: string = ''; let nfcOmaSession = null;
@State nfcOmaSession: secureElement.Session = null; let nfcOmaChannel = null;
@State nfcOmaChannel: secureElement.Channel = null; let aidArray = [720, 1080];
aidArray: number[] = [720, 1080];
try { try {
// See Reader.openSession for this.nfcOmaSession. // See Reader.openSession for this.nfcOmaSession.
this.nfcOmaSession.openBasicChannel(this.aidArray, (error, data) => { nfcOmaSession.openBasicChannel(aidArray, (error, data) => {
if (error) { if (error) {
this.result = "openBasicChannel2 failed:" + JSON.stringify(error); console.log("openBasicChannel2 failed:" + JSON.stringify(error));
return; return;
} }
this.nfcOmaChannel = data; nfcOmaChannel = data;
this.result = "openBasicChannel2 get channel successfully"; console.log("openBasicChannel2 get channel successfully");
}); });
} catch (e) { } catch (e) {
this.result = "openBasicChannel2 exception:" + e.message; console.log("openBasicChannel2 exception:" + e.message);
} }
``` ```
## Session.openBasicChannel ## Session.openBasicChannel
openBasicChannel(aid: number[], p2: number): Promise<Channel> openBasicChannel(aid: number[], p2: number): Promise\<Channel>
Opens a basic channel. This API uses a promise to return the result. Opens a basic channel. This API uses a promise to return the result.
...@@ -673,16 +659,16 @@ Opens a basic channel. This API uses a promise to return the result. ...@@ -673,16 +659,16 @@ Opens a basic channel. This API uses a promise to return the result.
**Parameters** **Parameters**
| **Name**| **Type**| **Description** | | **Name**| **Type**| **Mandatory**| **Description** |
| ---------- | -------- | ------------------------------------------------------------ | | ---------- | -------- | ------ | ------------------------------------------------------------ |
| aid | number[] | AIDs of the applets selected on this channel or null if no applet is selected. | | aid | number[] | Yes | AIDs of the applets selected on this channel or null if no applet is selected.|
| p2 | number | P2 parameter of the **SELECT APDU** command executed on the channel. | | p2 | number | Yes |P2 parameter of the **SELECT APDU** command executed on the channel. |
**Return value** **Return value**
| **Type**| **Description** | | **Type**| **Description** |
| -------- | --------------------- | | -------- | --------------------- |
| Channel | Returns the **Channel** instance opened. If the SE cannot provide a new basic channel or cannot obtain the access control rule due to lack of available basic channels, null will be returned. | | Channel | Returns the **Channel** instance opened. If the SE cannot provide a new basic channel or cannot obtain the access control rule due to lack of available basic channels, null will be returned.|
**Error codes** **Error codes**
...@@ -700,29 +686,28 @@ For details about error codes, see [SE Error Codes](../errorcodes/errorcode-se.m ...@@ -700,29 +686,28 @@ For details about error codes, see [SE Error Codes](../errorcodes/errorcode-se.m
```js ```js
import secureElement from '@ohos.secureElement'; import secureElement from '@ohos.secureElement';
@State result: string = ''; let nfcOmaSession = null;
@State nfcOmaSession: secureElement.Session = null; let nfcOmaChannel = null;
@State nfcOmaChannel: secureElement.Channel = null; let aidArray = [720, 1080];
aidArray: number[] = [720, 1080]; let p2 = 0x00;
p2: number = 0x00;
try { try {
// See Reader.openSession for this.nfcOmaSession. // See Reader.openSession for this.nfcOmaSession.
let getPromise = this.nfcOmaSession.openBasicChannel(this.aidArray, this.p2); let getPromise = nfcOmaSession.openBasicChannel(aidArray, p2);
getPromise.then((channel) => { getPromise.then((channel) => {
this.nfcOmaChannel = channel; nfcOmaChannel = channel;
this.result = "openBasicChannel3 get channel successfully"; console.log("openBasicChannel3 get channel successfully");
}).catch ((err) => { }).catch ((err) => {
this.result = "openBasicChannel3 exception"; console.log("openBasicChannel3 exception");
}); });
} catch (e) { } catch (e) {
this.result = "openBasicChannel3 exception:" + e.message; console.log("openBasicChannel3 exception:" + e.message);
} }
``` ```
## Session.openBasicChannel ## Session.openBasicChannel
openBasicChannel(aid: number[], p2:number, callback: AsyncCallback<Channel>): void openBasicChannel(aid: number[], p2:number, callback: AsyncCallback\<Channel>): void
Opens a basic channel. This API uses an asynchronous callback to return the result. Opens a basic channel. This API uses an asynchronous callback to return the result.
...@@ -730,11 +715,11 @@ Opens a basic channel. This API uses an asynchronous callback to return the resu ...@@ -730,11 +715,11 @@ Opens a basic channel. This API uses an asynchronous callback to return the resu
**Parameters** **Parameters**
| **Name**| **Type** | **Description** | | **Name**| **Type** | **Mandatory**| **Description** |
| ---------- | ---------------------- | ------------------------------------------------------------ | | ---------- | ---------------------- | ------ | ------------------------------------------------------------ |
| aid | number[] | AIDs of the applets selected on this channel or null if no applet is selected. | | aid | number[] | Yes | AIDs of the applets selected on this channel or null if no applet is selected.|
| p2 | number | P2 parameter of the **SELECT APDU** command executed on the channel. | | p2 | number | Yes | P2 parameter of the **SELECT APDU** command executed on the channel. |
| callback | AsyncCallback<Channel> | Callback invoked to return the **Channel** instance opened. If the SE cannot provide a new basic channel or cannot obtain the access control rule due to lack of available basic channels, null will be returned. | | callback | AsyncCallback\<Channel> | Yes | Callback invoked to return the **Channel** instance opened. If the SE cannot provide a new basic channel or cannot obtain the access control rule due to lack of available basic channels, null will be returned. |
**Error codes** **Error codes**
...@@ -752,30 +737,30 @@ For details about error codes, see [SE Error Codes](../errorcodes/errorcode-se.m ...@@ -752,30 +737,30 @@ For details about error codes, see [SE Error Codes](../errorcodes/errorcode-se.m
```js ```js
import secureElement from '@ohos.secureElement'; import secureElement from '@ohos.secureElement';
@State result: string = '';
@State nfcOmaSession: secureElement.Session = null; let nfcOmaSession = null;
@State nfcOmaChannel: secureElement.Channel = null; let nfcOmaChannel = null;
aidArray: number[] = [720, 1080]; let aidArray = [720, 1080];
p2: number = 0x00; let p2 = 0x00;
try { try {
// See Reader.openSession for this.nfcOmaSession. // See Reader.openSession for this.nfcOmaSession.
this.nfcOmaSession.openBasicChannel(this.aidArray, this.p2, (error, data) => { nfcOmaSession.openBasicChannel(aidArray, p2, (error, data) => {
if (error) { if (error) {
this.result = "openBasicChannel4 failed:" + JSON.stringify(error); console.log("openBasicChannel4 failed:" + JSON.stringify(error));
return; return;
} }
this.nfcOmaChannel = data; nfcOmaChannel = data;
this.result = "openBasicChannel4 get channel successfully"; console.log("openBasicChannel4 get channel successfully");
}); });
} catch (e) { } catch (e) {
this.result = "openBasicChannel4 exception:" + e.message; console.log("openBasicChannel4 exception:" + e.message);
} }
``` ```
## Session.openLogicalChannel ## Session.openLogicalChannel
openLogicalChannel(aid: number[]): Promise<Channel> openLogicalChannel(aid: number[]): Promise\<Channel>
Opens a logical channel. This API uses a promise to return the result. Opens a logical channel. This API uses a promise to return the result.
...@@ -783,9 +768,9 @@ Opens a logical channel. This API uses a promise to return the result. ...@@ -783,9 +768,9 @@ Opens a logical channel. This API uses a promise to return the result.
**Parameters** **Parameters**
| **Name**| **Type**| **Description** | | **Name**| **Type**| **Mandatory**| **Description** |
| ---------- | -------- | --------------------------------------- | | ---------- | -------- | ------ | --------------------------------------- |
| aid | number[] | AIDs of the applets selected on the **Channel** instance. | | aid | number[] | Yes | AIDs of the applets selected on the **Channel** instance.|
**Return value** **Return value**
...@@ -809,28 +794,27 @@ For details about error codes, see [SE Error Codes](../errorcodes/errorcode-se.m ...@@ -809,28 +794,27 @@ For details about error codes, see [SE Error Codes](../errorcodes/errorcode-se.m
```js ```js
import secureElement from '@ohos.secureElement'; import secureElement from '@ohos.secureElement';
@State result: string = ''; let nfcOmaSession = null;
@State nfcOmaSession: secureElement.Session = null; let nfcOmaChannel = null;
@State nfcOmaChannel: secureElement.Channel = null; let aidArray = [720, 1080];
aidArray: number[] = [720, 1080];
try { try {
// See Reader.openSession for this.nfcOmaSession. // See Reader.openSession for this.nfcOmaSession.
let getPromise = this.nfcOmaSession.openLogicalChannel(this.aidArray) let getPromise = nfcOmaSession.openLogicalChannel(aidArray)
getPromise.then((channel) => { getPromise.then((channel) => {
this.nfcOmaChannel = channel; nfcOmaChannel = channel;
this.result = "openLogicChannel1 get channel successfully"; console.log("openLogicChannel1 get channel successfully");
}).catch ((err) => { }).catch ((err) => {
this.result = "openLogicChannel1 exception:" + err.message; console.log("openLogicChannel1 exception:" + err.message);
}); });
} catch (e) { } catch (e) {
this.result = "openLogicChannel1 exception:" + e.message; console.log("openLogicChannel1 exception:" + e.message);
} }
``` ```
## Session.openLogicalChannel ## Session.openLogicalChannel
openLogicalChannel(aid:number[], callback: AsyncCallback<Channel>): void openLogicalChannel(aid:number[], callback: AsyncCallback\<Channel>): void
Opens a logical channel. This API uses an asynchronous callback to return the result. Opens a logical channel. This API uses an asynchronous callback to return the result.
...@@ -838,10 +822,10 @@ Opens a logical channel. This API uses an asynchronous callback to return the re ...@@ -838,10 +822,10 @@ Opens a logical channel. This API uses an asynchronous callback to return the re
**Parameters** **Parameters**
| **Name**| **Type** | **Description** | | **Name**| **Type** | **Mandatory**| **Description** |
| ---------- | ---------------------- | ------------------------------------------------------------ | | ---------- | ---------------------- | ------ | ------------------------------------------------------------ |
| aid | number[] | AIDs of the applets selected on the **Channel** instance. | | aid | number[] | Yes | AIDs of the applets selected on the **Channel** instance. |
| callback | AsyncCallback<Channel> | Callback invoked to return the **Channel** instance opened. If the SE cannot provide a new **Channel** instance or cannot obtain access control rules due to lack of available logical **Channel** instances, null will be returned.| | callback | AsyncCallback\<Channel> | Yes | Callback invoked to return the **Channel** instance opened. If the SE cannot provide a new **Channel** instance or cannot obtain access control rules due to lack of available logical **Channel** instances, null will be returned.|
**Error codes** **Error codes**
...@@ -859,29 +843,28 @@ For details about error codes, see [SE Error Codes](../errorcodes/errorcode-se.m ...@@ -859,29 +843,28 @@ For details about error codes, see [SE Error Codes](../errorcodes/errorcode-se.m
```js ```js
import secureElement from '@ohos.secureElement'; import secureElement from '@ohos.secureElement';
@State result: string = ''; let nfcOmaSession = null;
@State nfcOmaSession: secureElement.Session = null; let nfcOmaChannel = null;
@State nfcOmaChannel: secureElement.Channel = null; let aidArray = [720, 1080];
aidArray: number[] = [720, 1080];
try { try {
// See Reader.openSession for this.nfcOmaSession. // See Reader.openSession for this.nfcOmaSession.
this.nfcOmaSession.openLogicalChannel(this.aidArray, (error, data) => { nfcOmaSession.openLogicalChannel(aidArray, (error, data) => {
if (error) { if (error) {
this.result = "openLogicChannel2 failed:" + JSON.stringify(error); console.log("openLogicChannel2 failed:" + JSON.stringify(error));
return; return;
} }
this.nfcOmaChannel = data; nfcOmaChannel = data;
this.result = "openLogicChannel2 get channel successfully"; console.log("openLogicChannel2 get channel successfully");
}); });
} catch (e) { } catch (e) {
this.result = "openLogicChannel2 exception:" + e.message; console.log("openLogicChannel2 exception:" + e.message);
} }
``` ```
## Session.openLogicalChannel ## Session.openLogicalChannel
openLogicalChannel(aid: number[], p2: number): Promise<Channel> openLogicalChannel(aid: number[], p2: number): Promise\<Channel>
Opens a logical channel with the applet represented by the given AID (the AID is not null and the length is not 0). Opens a logical channel with the applet represented by the given AID (the AID is not null and the length is not 0).
...@@ -895,10 +878,10 @@ If the AID is null, this API sends the **MANAGE CHANNEL Open** only. In this cas ...@@ -895,10 +878,10 @@ If the AID is null, this API sends the **MANAGE CHANNEL Open** only. In this cas
**Parameters** **Parameters**
| **Name**| **Type**| **Description** | | **Name**| **Type**| **Mandatory**| **Description** |
| ---------- | -------- | ----------------------------------------- | | ---------- | -------- | ------ | ----------------------------------------- |
| aid | number[] | AIDs of the applets selected on the **Channel** instance. | | aid | number[] | Yes | AIDs of the applets selected on the **Channel** instance.|
| p2 | number | P2 parameter of the **SELECT APDU** command executed on the channel. | | p2 | number | Yes | P2 parameter of the **SELECT APDU** command executed on the channel. |
**Error codes** **Error codes**
...@@ -916,30 +899,30 @@ For details about error codes, see [SE Error Codes](../errorcodes/errorcode-se.m ...@@ -916,30 +899,30 @@ For details about error codes, see [SE Error Codes](../errorcodes/errorcode-se.m
```js ```js
import secureElement from '@ohos.secureElement'; import secureElement from '@ohos.secureElement';
@State result: string = '';
@State nfcOmaSession: secureElement.Session = null;
@State nfcOmaChannel: secureElement.Channel = null;
aidArray: number[] = [720, 1080];
p2: number = 0x00;
if (this.nfcOmaSession) { let nfcOmaSession = null;
let nfcOmaChannel = null;
let aidArray = [720, 1080];
let p2 = 0x00;
if (nfcOmaSession) {
try { try {
// See Reader.openSession for this.nfcOmaSession. // See Reader.openSession for this.nfcOmaSession.
let getPromise = this.nfcOmaSession.openLogicalChannel(this.aidArray, this.p2); let getPromise = nfcOmaSession.openLogicalChannel(aidArray, p2);
getPromise.then((channel) => { getPromise.then((channel) => {
this.nfcOmaChannel = channel; nfcOmaChannel = channel;
this.result = "openLogicChannel3 get channel successfully"; console.log("openLogicChannel3 get channel successfully");
}).catch ((err) => { }).catch ((err) => {
this.result = "openLogicChannel3 exception"; console.log("openLogicChannel3 exception");
}) })
} catch (e) { } catch (e) {
this.result = "openLogicChannel3 exception:" + e.message; console.log("openLogicChannel3 exception:" + e.message);
} }
``` ```
## Session.openLogicalChannel ## Session.openLogicalChannel
openLogicalChannel(aid: number[], p2: number, callback: AsyncCallback<Channel>):void openLogicalChannel(aid: number[], p2: number, callback: AsyncCallback\<Channel>):void
Opens a logical channel with the applet represented by the given AID (the AID is not null and the length is not 0). Opens a logical channel with the applet represented by the given AID (the AID is not null and the length is not 0).
...@@ -953,11 +936,11 @@ If the AID is null, this API sends the **MANAGE CHANNEL Open** only. In this cas ...@@ -953,11 +936,11 @@ If the AID is null, this API sends the **MANAGE CHANNEL Open** only. In this cas
**Parameters** **Parameters**
| **Name**| **Type** | **Description** | | **Name**| **Type** | **Mandatory**| **Description** |
| ---------- | ---------------------- | ------------------------------------------------------------ | | ---------- | ---------------------- | ------ | ------------------------------------------------------------ |
| aid | number[] | AIDs of the applets selected on the **Channel** instance. | | aid | number[] | Yes | AIDs of the applets selected on the **Channel** instance. |
| p2 | number | P2 parameter of the **SELECT APDU** command executed on the channel. | | p2 | number | Yes | P2 parameter of the **SELECT APDU** command executed on the channel. |
| callback | AsyncCallback<Channel> | Callback invoked to return the **Channel** instance opened. If the SE cannot provide a new **Channel** instance or cannot obtain access control rules due to lack of available logical **Channel** instances, null will be returned.| | callback | AsyncCallback\<Channel> | Yes | Callback invoked to return the **Channel** instance opened. If the SE cannot provide a new **Channel** instance or cannot obtain access control rules due to lack of available logical **Channel** instances, null will be returned.|
**Error codes** **Error codes**
...@@ -975,24 +958,23 @@ For details about error codes, see [SE Error Codes](../errorcodes/errorcode-se.m ...@@ -975,24 +958,23 @@ For details about error codes, see [SE Error Codes](../errorcodes/errorcode-se.m
```js ```js
import secureElement from '@ohos.secureElement'; import secureElement from '@ohos.secureElement';
@State result: string = ''; let nfcOmaSession = null;
@State nfcOmaSession: secureElement.Session = null; let nfcOmaChannel = null;
@State nfcOmaChannel: secureElement.Channel = null; let aidArray = [720, 1080];
aidArray: number[] = [720, 1080]; let p2 = 0x00;
p2: number = 0x00;
try { try {
// See Reader.openSession for this.nfcOmaSession. // See Reader.openSession for this.nfcOmaSession.
this.nfcOmaSession.openLogicalChannel(this.aidArray, this.p2, (error, data) => { nfcOmaSession.openLogicalChannel(aidArray, p2, (error, data) => {
if (error) { if (error) {
this.result = "openLogicChannel4 failed:" + JSON.stringify(error); console.log("openLogicChannel4 failed:" + JSON.stringify(error));
return; return;
} }
this.nfcOmaChannel = data; nfcOmaChannel = data;
this.result = "openLogicChannel4 get channel successfully"; console.log("openLogicChannel4 get channel successfully");
}) })
} catch (e) { } catch (e) {
this.result = "openLogicChannel4 exception:" + e.message; console.log("openLogicChannel4 exception:" + e.message);
} }
``` ```
...@@ -1015,20 +997,19 @@ Obtains the session that opens this channel. ...@@ -1015,20 +997,19 @@ Obtains the session that opens this channel.
```js ```js
import secureElement from '@ohos.secureElement'; import secureElement from '@ohos.secureElement';
@State result: string = ''; let nfcOmaSession = null;
@State nfcOmaSession: secureElement.Session = null; let nfcOmaChannel = null;
@State nfcOmaChannel: secureElement.Channel = null;
try { try {
// See Session.openBasicChannel for this.nfcOmaChannel. // See Session.openBasicChannel for this.nfcOmaChannel.
let ret = this.nfcOmaChannel.getSession(); let ret = nfcOmaChannel.getSession();
if (ret) { if (ret) {
this.result = "get session successfully"; console.log("get session successfully");
} else { } else {
this.result = "get session failed"; console.log("get session failed");
} }
} catch (e) { } catch (e) {
this.result = "getSession exception:" + e.message; console.log("getSession exception:" + e.message);
} }
``` ```
...@@ -1045,16 +1026,15 @@ Closes the channel of the SE. ...@@ -1045,16 +1026,15 @@ Closes the channel of the SE.
```js ```js
import secureElement from '@ohos.secureElement'; import secureElement from '@ohos.secureElement';
@State result: string = ''; let nfcOmaSession = null;
@State nfcOmaSession: secureElement.Session = null; let nfcOmaChannel = null;
@State nfcOmaChannel: secureElement.Channel = null;
try { try {
// See Session.openBasicChannel for this.nfcOmaChannel. // See Session.openBasicChannel for this.nfcOmaChannel.
this.nfcOmaChannel.close(); nfcOmaChannel.close();
this.result = "channel close successfully"; console.log("channel close successfully");
} catch (e) { } catch (e) {
this.result = "channel close exception:" + e.message; console.log("channel close exception:" + e.message);
} }
``` ```
...@@ -1077,19 +1057,18 @@ Checks whether this channel is a basic channel. ...@@ -1077,19 +1057,18 @@ Checks whether this channel is a basic channel.
```js ```js
import secureElement from '@ohos.secureElement'; import secureElement from '@ohos.secureElement';
@State result: string = ''; let nfcOmaChannel = null;
@State nfcOmaChannel: secureElement.Channel = null;
try { try {
// See Session.openBasicChannel for this.nfcOmaChannel. // See Session.openBasicChannel for this.nfcOmaChannel.
let ret = this.nfcOmaChannel.isBasicChannel(); let ret = nfcOmaChannel.isBasicChannel();
if (ret) { if (ret) {
this.result = "isBasicChannel TRUE"; console.log("isBasicChannel TRUE");
} else { } else {
this.result = "isBasicChannel FALSE"; console.log("isBasicChannel FALSE");
} }
} catch (e) { } catch (e) {
this.result = "isBasicChannel Exception: "+ e.message; console.log ("isBasicChannelException: "+ e.message);
} }
``` ```
...@@ -1112,19 +1091,18 @@ Checks whether this channel is closed. ...@@ -1112,19 +1091,18 @@ Checks whether this channel is closed.
```js ```js
import secureElement from '@ohos.secureElement'; import secureElement from '@ohos.secureElement';
@State result: string = ''; let nfcOmaChannel = null;
@State nfcOmaChannel: secureElement.Channel = null;
try { try {
// See Session.openBasicChannel for this.nfcOmaChannel. // See Session.openBasicChannel for this.nfcOmaChannel.
let ret = this.nfcOmaChannel.isClosed(); let ret = nfcOmaChannel.isClosed();
if (ret) { if (ret) {
this.result = "channel isClosed TRUE"; console.log("channel isClosed TRUE");
} else { } else {
this.result = "channel isClosed False"; console.log("channel isClosed False");
} }
} catch (e) { } catch (e) {
this.result = "Channel isClosed exception:" + e.message; console.log("Channel isClosed exception:" + e.message);
} }
``` ```
...@@ -1151,24 +1129,25 @@ For details about error codes, see [SE Error Codes](../errorcodes/errorcode-se.m ...@@ -1151,24 +1129,25 @@ For details about error codes, see [SE Error Codes](../errorcodes/errorcode-se.m
```js ```js
import secureElement from '@ohos.secureElement'; import secureElement from '@ohos.secureElement';
@State result: string = ''; let str = '';
@State nfcOmaChannel: secureElement.Channel = null; let nfcOmaChannel = null;
try { try {
// See Session.openBasicChannel for this.nfcOmaChannel. // See Session.openBasicChannel for this.nfcOmaChannel.
let ret = this.nfcOmaChannel.getSelectResponse(); let ret = nfcOmaChannel.getSelectResponse();
if (ret) { if (ret) {
this.result = "getSelectResponse result:["; str = "getSelectResponse result:[";
for (let i = 0; i < ret.length; ++i) { for (let i = 0; i < ret.length; ++i) {
this.result += ret[i]; str += ret[i];
this.result += ' '; str += ' ';
} }
this.result += ']'; str += ']';
console.log(str);
} else { } else {
this.result = "getSelectResponse result is null"; console.log("getSelectResponse result is null");
} }
} catch (e) { } catch (e) {
this.result = "getSelectResponse exception:" + e.message; console.log("getSelectResponse exception:" + e.message);
} }
``` ```
...@@ -1182,9 +1161,9 @@ Transmits the **APDU** command to the SE (according to ISO/IEC 7816). This API u ...@@ -1182,9 +1161,9 @@ Transmits the **APDU** command to the SE (according to ISO/IEC 7816). This API u
**Parameters** **Parameters**
| **Name**| **Type**| **Description** | | **Name**| **Type**| **Mandatory**| **Description** |
| ---------- | -------- | ------------------------------------- | | ---------- | -------- | ------ | ------------------------------------- |
| command | number[] | AIDs of the applets selected on the channel. | | command | number[] | Yes | AIDs of the applets selected on the channel.|
**Return value** **Return value**
...@@ -1207,25 +1186,25 @@ For details about error codes, see [SE Error Codes](../errorcodes/errorcode-se.m ...@@ -1207,25 +1186,25 @@ For details about error codes, see [SE Error Codes](../errorcodes/errorcode-se.m
```js ```js
import secureElement from '@ohos.secureElement'; import secureElement from '@ohos.secureElement';
@State result: string = ''; let nfcOmaChannel = null;
@State nfcOmaChannel: secureElement.Channel = null; let str = "";
try { try {
let command: number[] = [100, 200]; let command: number[] = [100, 200];
// See Session.openBasicChannel for this.nfcOmaChannel. // See Session.openBasicChannel for this.nfcOmaChannel.
let getPromise = this.nfcOmaChannel.transmit(command); let getPromise = nfcOmaChannel.transmit(command);
getPromise.then((data) => { getPromise.then((data) => {
this.result = "transmit1 result:["; str = "transmit1 result:[";
for (let i = 0; i < data.length; ++i) { for (let i = 0; i < data.length; ++i) {
this.result += data[i]; str += data[i];
this.result += " "; str += " ";
} }
this.result += "]"; str += "]";
console.log(str);
}).catch ((err) => { }).catch ((err) => {
this.result = "transmit1 exception:" + err.code; console.log("transmit1 exception:" + err.code);
}) })
} catch (e) { } catch (e) {
this.result = "transit1 exception:" + e.message; console.log("transit1 exception:" + e.message);
} }
``` ```
...@@ -1239,10 +1218,10 @@ Transmits the **APDU** command to the SE (according to ISO/IEC 7816). This API u ...@@ -1239,10 +1218,10 @@ Transmits the **APDU** command to the SE (according to ISO/IEC 7816). This API u
**Parameters** **Parameters**
| **Name**| **Type** | **Description** | | **Name**| **Type** | **Mandatory**| **Description** |
| ---------- | ----------------------- | ------------------------------------- | | ---------- | ----------------------- | ------ | ------------------------------------- |
| command | number[] | AIDs of the applets selected on the channel. | | command | number[] | Yes | AIDs of the applets selected on the channel.|
| callback | AsyncCallback<number[]> | Callback invoked to return the result. | | callback | AsyncCallback<number[]> | Yes | Callback invoked to return the result. |
**Error codes** **Error codes**
...@@ -1259,25 +1238,26 @@ For details about error codes, see [SE Error Codes](../errorcodes/errorcode-se.m ...@@ -1259,25 +1238,26 @@ For details about error codes, see [SE Error Codes](../errorcodes/errorcode-se.m
```js ```js
import secureElement from '@ohos.secureElement'; import secureElement from '@ohos.secureElement';
@State result: string = ''; let str = "";
@State nfcOmaChannel: secureElement.Channel = null; let nfcOmaChannel = null;
try { try {
let command: number[] = [100, 200]; let command: number[] = [100, 200];
// See Session.openBasicChannel for this.nfcOmaChannel. // See Session.openBasicChannel for this.nfcOmaChannel.
this.nfcOmaChannel.transmit(command, (error, data) => { nfcOmaChannel.transmit(command, (error, data) => {
if (error) { if (error) {
this.result = "transmit2 exception:" + JSON.stringify(error); console.log("transmit2 exception:" + JSON.stringify(error));
return; return;
} }
this.result = "transmit2 result:["; str = "transmit2 result:[";
for (let i = 0; i < data.length; ++i) { for (let i = 0; i < data.length; ++i) {
this.result += data[i]; str += data[i];
this.result += " "; str += " ";
} }
this.result += "]"; str += "]";
console.log(str)
}); });
} catch (e) { } catch (e) {
this.result = "transit2 exception:" + e.message; console.log("transit2 exception:" + e.message);
} }
``` ```
...@@ -20,7 +20,7 @@ get(options: GetStorageOptions): void ...@@ -20,7 +20,7 @@ get(options: GetStorageOptions): void
Reads the value stored in the cache based on the specified key. Reads the value stored in the cache based on the specified key.
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core.Lite
**Parameters** **Parameters**
...@@ -55,7 +55,7 @@ set(options: SetStorageOptions): void ...@@ -55,7 +55,7 @@ set(options: SetStorageOptions): void
Sets the value in the cache based on the specified key. Sets the value in the cache based on the specified key.
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core.Lite
**Parameters** **Parameters**
...@@ -88,7 +88,7 @@ clear(options?: ClearStorageOptions): void ...@@ -88,7 +88,7 @@ clear(options?: ClearStorageOptions): void
Clears the key-value pairs from the cache. Clears the key-value pairs from the cache.
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core.Lite
**Parameters** **Parameters**
...@@ -119,7 +119,7 @@ delete(options: DeleteStorageOptions): void ...@@ -119,7 +119,7 @@ delete(options: DeleteStorageOptions): void
Deletes the key-value pair based on the specified key. Deletes the key-value pair based on the specified key.
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core.Lite
**Parameters** **Parameters**
...@@ -147,7 +147,7 @@ export default { ...@@ -147,7 +147,7 @@ export default {
## GetStorageOptions ## GetStorageOptions
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core.Lite
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ---------------- | ---- | ------------------- | | -------- | ---------------- | ---- | ------------------- |
...@@ -160,7 +160,7 @@ export default { ...@@ -160,7 +160,7 @@ export default {
## SetStorageOptions ## SetStorageOptions
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core.Lite
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------------------- | ---- | -------------------- | | -------- | ------------------- | ---- | -------------------- |
...@@ -173,7 +173,7 @@ export default { ...@@ -173,7 +173,7 @@ export default {
## ClearStorageOptions ## ClearStorageOptions
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core.Lite
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | --------------------- | ---- | -------------------- | | -------- | --------------------- | ---- | -------------------- |
...@@ -184,7 +184,7 @@ export default { ...@@ -184,7 +184,7 @@ export default {
## DeleteStorageOptions ## DeleteStorageOptions
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core.Lite
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | ------------------ | | -------- | -------------------- | ---- | ------------------ |
...@@ -192,4 +192,3 @@ export default { ...@@ -192,4 +192,3 @@ export default {
| success | () => void | No | Called when **storage.delete()** is called successfully. | | success | () => void | No | Called when **storage.delete()** is called successfully. |
| fail | (data: string, code: number) => void | No | Called to return the result when **storage.delete()** fails to be called. **data** is the error information, and **code** indicates the error code. | | fail | (data: string, code: number) => void | No | Called to return the result when **storage.delete()** fails to be called. **data** is the error information, and **code** indicates the error code. |
| complete | () => void | No | Called when **storage.delete()** is complete. | | complete | () => void | No | Called when **storage.delete()** is complete. |
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册