未验证 提交 470b5786 编写于 作者: O openharmony_ci 提交者: Gitee

!16371 [翻译完成】#I6LLE1

Merge pull request !16371 from Annie_wang/PR15796
...@@ -16,31 +16,37 @@ import cardEmulation from '@ohos.nfc.cardEmulation'; ...@@ -16,31 +16,37 @@ import cardEmulation from '@ohos.nfc.cardEmulation';
Enumerates the NFC card emulation types. Enumerates the NFC card emulation types.
> **NOTE**
> This parameter is supported since API version 6 and deprecated since API version 9. You are advised to use [hasHceCapability](#hashcecapability9).
**System capability**: SystemCapability.Communication.NFC.CardEmulation **System capability**: SystemCapability.Communication.NFC.CardEmulation
| Name| Value| Description| | Name| Value| Description|
| -------- | -------- | -------- | | -------- | -------- | -------- |
| HCE | 0 | HCE.| | HCE | 0 | HCE.|
| UICC | 1 | Subscriber identity module (SIM) card emulation.| | UICC | 1 | Subscriber identity module (SIM) card emulation.|
| ESE | 2 | embedded Secure Element (eSE) emulation.| | ESE | 2 | embedded Secure Element (eSE) emulation.|
## CardType ## CardType<sup>9+</sup>
Enumerates the card emulation application types. Enumerates the types of services used by the card emulation application.
**System capability**: SystemCapability.Communication.NFC.CardEmulation **System capability**: SystemCapability.Communication.NFC.CardEmulation
| Name| Value| Description| | Name| Value| Description|
| -------- | -------- | -------- | | -------- | -------- | -------- |
| PAYMENT | "payment" | Payment type.| | PAYMENT | "payment" | Payment type.|
| OTHER | "other" | Other types. | | OTHER | "other" | Other types.|
## cardEmulation.isSupported ## isSupported
isSupported(feature: number): boolean isSupported(feature: number): boolean
Checks whether a certain type of card emulation is supported. Checks whether a certain type of card emulation is supported.
> **NOTE**
> This parameter is supported since API version 6 and deprecated since API version 9. You are advised to use [hasHceCapability](#hashcecapability9).
**System capability**: SystemCapability.Communication.NFC.CardEmulation **System capability**: SystemCapability.Communication.NFC.CardEmulation
**Parameters** **Parameters**
...@@ -55,89 +61,44 @@ Checks whether a certain type of card emulation is supported. ...@@ -55,89 +61,44 @@ Checks whether a certain type of card emulation is supported.
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the card emulation type is supported; returns **false** otherwise.| | boolean | Returns **true** if the card emulation type is supported; returns **false** otherwise.|
## cardEmulation.isDefaultService ## hasHceCapability<sup>9+</sup>
isDefaultService(elementName: ElementName, type: CardType): boolean hasHceCapability(): boolean
Checks whether the specified application is of the default payment type. Checks whether HCE is supported.
**System capability**: SystemCapability.Communication.NFC.CardEmulation **System capability**: SystemCapability.Communication.NFC.CardEmulation
**Parameters** **Required permissions**: ohos.permission.NFC_CARD_EMULATION
| Name | Type | Mandatory| Description |
| ------- | -------- | ---- | ----------------------- |
| elementName | [ElementName](js-apis-bundleManager-elementName.md#elementname) | Yes| Application description, which includes the bundle name and component name.|
| type | [CardType](#cardtype) | Yes| Application description, which includes the bundle name and component name.|
**Return value** **Return value**
| **Type**| **Description**| | **Type**| **Description**|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the application is the default payment application; returns **false** otherwise.| | boolean | Returns **true** if HCE is supported; returns **false** otherwise.|
## HceService<sup>8+</sup>
Implements HCE, including receiving Application Protocol Data Units (APDUs) from the peer card reader and sending a response. Before using HCE-related APIs, check whether the device supports HCE. ## isDefaultService<sup>9+</sup>
### startHCE<sup>8+</sup> isDefaultService(elementName: ElementName, type: CardType): boolean
startHCE(aidList: string[]): boolean Checks whether an application is the default application of the specified service type.
Starts HCE, including setting the application to be foreground preferred and dynamically registering the application identifier (AID) list. **System capability**: SystemCapability.Communication.NFC.CardEmulation
**Required permissions**: ohos.permission.NFC_CARD_EMULATION **Required permissions**: ohos.permission.NFC_CARD_EMULATION
**System capability**: SystemCapability.Communication.NFC.CardEmulation
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ------- | -------- | ---- | ----------------------- | | ------- | -------- | ---- | ----------------------- |
| aidList | string[] | Yes | AID list to register.| | elementName | [ElementName](js-apis-bundleManager-elementName.md#elementname) | Yes| Application description, which consists of the bundle name and component name.|
| type | [CardType](#cardtype9) | Yes| Card emulation service type.|
### stopHCE<sup>8+</sup>
stopHCE(): boolean
Stops HCE, including removing the foreground preferred attribute and releasing the dynamically registered AID list.
**Required permissions**: ohos.permission.NFC_CARD_EMULATION
**System capability**: SystemCapability.Communication.NFC.CardEmulation
### on<sup>8+</sup>
on(type: "hceCmd", callback: AsyncCallback<number[]>): void;
Registers a callback to receive APDUs from the peer card reader. **Return value**
**Required permissions**: ohos.permission.NFC_CARD_EMULATION
**System capability**: SystemCapability.Communication.NFC.CardEmulation
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------- | ---- | -------------------------------------------- |
| type | string | Yes | Event type to subscribe to. The value is **hceCmd**. |
| callback | AsyncCallback<number[]> | Yes | Callback invoked to return the APDU, which consists of hexadecimal numbers ranging from **0x00** to **0xFF**.|
### sendResponse<sup>8+</sup>
sendResponse(responseApdu: number[]): void;
Sends a response to the peer card reader.
**Required permissions**: ohos.permission.NFC_CARD_EMULATION
**System capability**: SystemCapability.Communication.NFC.CardEmulation
**Parameters**
| Name | Type | Mandatory| Description | | **Type**| **Description**|
| ------------ | -------- | ---- | -------------------------------------------------- | | -------- | -------- |
| responseApdu | number[] | Yes | Response APDU sent to the peer card reader. The value consists of hexadecimal numbers ranging from **0x00** to **0xFF**.| | boolean | Returns **true** if the application is the default payment application; returns **false** otherwise.|
**Example** **Example**
...@@ -150,30 +111,16 @@ if (!isHceSupported) { ...@@ -150,30 +111,16 @@ if (!isHceSupported) {
return; return;
} }
var hasHceCap = cardEmulation.hasHceCapability();
if (!hasHceCap) {
console.log('this device hasHceCapability false, ignore it.');
return;
}
var elementName = { var elementName = {
"bundleName": "com.test.cardemulation", "bundleName": "com.test.cardemulation",
"abilityName": "com.test.cardemulation.MainAbility", "abilityName": "com.test.cardemulation.MainAbility",
}; };
var isDefaultService = cardEmulation.isDefaultService(elementName, cardEmulation.CardType.PAYMENT); var isDefaultService = cardEmulation.isDefaultService(elementName, cardEmulation.CardType.PAYMENT);
console.log('is the app is default service for this card type: ' + isDefaultService); console.log('is the app is default service for this card type: ' + isDefaultService);
// The device supports HCE and transimits APDUs with the remote NFC reader.
var hceService = new cardEmulation.HceService();
hceService.startHCE([
"F0010203040506", "A0000000041010"
]);
hceService.on("hceCmd", (err, res) => {
if(err.data === 0) {
console.log('callback => Operation hceCmd succeeded. Data: ' + JSON.stringify(res));
hceService.sendResponse([0x00,0xa4,0x04,0x00,
0x0e,0x32,0x50,0x41,0x59,0x2e,0x53,0x59,0x53,0x2e,0x44,0x44,
0x46,0x30,0x31,0x00]);
} else {
console.log('callback => Operation hceCmd failed. Cause: ' + err.data);
}
})
// stop HCE when the application exit the nfc card emulation.
hceService.stopHCE();
``` ```
...@@ -8,7 +8,7 @@ The **relationalStore** module provides the following functions: ...@@ -8,7 +8,7 @@ The **relationalStore** module provides the following functions:
- [RdbStore](#rdbstore): provides APIs for managing data in an RDB store. - [RdbStore](#rdbstore): provides APIs for managing data in an RDB store.
- [Resultset](#resultset): provides APIs for accessing the result set obtained from the RDB store. - [Resultset](#resultset): provides APIs for accessing the result set obtained from the RDB store.
> **NOTE**<br/> > **NOTE**
> >
> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version. > The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
...@@ -30,7 +30,7 @@ Obtains an RDB store. This API uses an asynchronous callback to return the resul ...@@ -30,7 +30,7 @@ Obtains an RDB store. This API uses an asynchronous callback to return the resul
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ---------------------------------------------- | ---- | ------------------------------------------------------------ | | -------- | ---------------------------------------------- | ---- | ------------------------------------------------------------ |
| context | Context | Yes | Application context.<br>For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).<br>For details about the application context of the stage model, see [Context](js-apis-ability-context.md).| | context | Context | Yes | Application context.<br>For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).<br>For details about the application context of the stage model, see [Context](js-apis-inner-application-uiAbilityContext.md).|
| config | [StoreConfig](#storeconfig) | Yes | Configuration of the RDB store. | | config | [StoreConfig](#storeconfig) | Yes | Configuration of the RDB store. |
| callback | AsyncCallback&lt;[RdbStore](#rdbstore)&gt; | Yes | Callback invoked to return the RDB store obtained. | | callback | AsyncCallback&lt;[RdbStore](#rdbstore)&gt; | Yes | Callback invoked to return the RDB store obtained. |
...@@ -108,7 +108,7 @@ Obtains an RDB store. This API uses a promise to return the result. You can set ...@@ -108,7 +108,7 @@ Obtains an RDB store. This API uses a promise to return the result. You can set
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ------- | -------------------------------- | ---- | ------------------------------------------------------------ | | ------- | -------------------------------- | ---- | ------------------------------------------------------------ |
| context | Context | Yes | Application context.<br>For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).<br>For details about the application context of the stage model, see [Context](js-apis-ability-context.md).| | context | Context | Yes | Application context.<br>For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).<br>For details about the application context of the stage model, see [Context](js-apis-inner-application-uiAbilityContext.md).|
| config | [StoreConfig](#storeconfig) | Yes | Configuration of the RDB store. | | config | [StoreConfig](#storeconfig) | Yes | Configuration of the RDB store. |
**Return value** **Return value**
...@@ -188,7 +188,7 @@ Deletes an RDB store. This API uses an asynchronous callback to return the resul ...@@ -188,7 +188,7 @@ Deletes an RDB store. This API uses an asynchronous callback to return the resul
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ------------------------------------------------------------ | | -------- | ------------------------- | ---- | ------------------------------------------------------------ |
| context | Context | Yes | Application context.<br>For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).<br>For details about the application context of the stage model, see [Context](js-apis-ability-context.md).| | context | Context | Yes | Application context.<br>For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).<br>For details about the application context of the stage model, see [Context](js-apis-inner-application-uiAbilityContext.md).|
| name | string | Yes | Name of the RDB store to delete. | | name | string | Yes | Name of the RDB store to delete. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result. | | callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result. |
...@@ -249,7 +249,7 @@ Deletes an RDB store. This API uses a promise to return the result. ...@@ -249,7 +249,7 @@ Deletes an RDB store. This API uses a promise to return the result.
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ------- | ------- | ---- | ------------------------------------------------------------ | | ------- | ------- | ---- | ------------------------------------------------------------ |
| context | Context | Yes | Application context.<br>For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).<br>For details about the application context of the stage model, see [Context](js-apis-ability-context.md).| | context | Context | Yes | Application context.<br>For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).<br>For details about the application context of the stage model, see [Context](js-apis-inner-application-uiAbilityContext.md).|
| name | string | Yes | Name of the RDB store to delete. | | name | string | Yes | Name of the RDB store to delete. |
**Return value** **Return value**
...@@ -2430,9 +2430,9 @@ Synchronizes data between devices. This API uses a promise to return the result. ...@@ -2430,9 +2430,9 @@ Synchronizes data between devices. This API uses a promise to return the result.
let predicates = new relationalStore.RdbPredicates('EMPLOYEE'); let predicates = new relationalStore.RdbPredicates('EMPLOYEE');
predicates.inDevices(['12345678abcde']); predicates.inDevices(['12345678abcde']);
let promise = store.sync(relationalStore.SyncMode.SYNC_MODE_PUSH, predicates); let promise = store.sync(relationalStore.SyncMode.SYNC_MODE_PUSH, predicates);
promise.then((resultSet) =>{ promise.then((result) =>{
console.info(`Sync done.`); console.info(`Sync done.`);
for (let i = 0; i < resultSet.length; i++) { for (let i = 0; i < result.length; i++) {
console.info(`device= ${result[i][0]}, status= ${result[i][1]}`); console.info(`device= ${result[i][0]}, status= ${result[i][1]}`);
} }
}).catch((err) => { }).catch((err) => {
...@@ -2511,10 +2511,12 @@ Provides APIs to access the result set obtained by querying the RDB store. A res ...@@ -2511,10 +2511,12 @@ Provides APIs to access the result set obtained by querying the RDB store. A res
Obtain the **resultSet** object first. Obtain the **resultSet** object first.
```js ```js
let resultSet = null;
let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.equalTo("AGE", 18); predicates.equalTo("AGE", 18);
let promise = store.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]); let promise = store.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]);
promise.then((resultSet) => { promise.then((result) => {
resultSet = result;
console.info(`resultSet columnNames: ${resultSet.columnNames}`); console.info(`resultSet columnNames: ${resultSet.columnNames}`);
console.info(`resultSet columnCount: ${resultSet.columnCount}`); console.info(`resultSet columnCount: ${resultSet.columnCount}`);
}); });
...@@ -2685,7 +2687,7 @@ For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode ...@@ -2685,7 +2687,7 @@ For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode
let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
let promise = store.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]); let promise = store.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]);
promise.then((resultSet) => { promise.then((resultSet) => {
resultSet.(5); resultSet.goToRow(5);
resultSet.close(); resultSet.close();
}).catch((err) => { }).catch((err) => {
console.error(`query failed, err: ${err}`); console.error(`query failed, err: ${err}`);
......
# Standard NFC # @ohos.nfc.controller (Standard NFC)
The **nfcController** module provides APIs for opening and closing Near-Field Communication (NFC) and reading the NFC state. The **nfcController** module provides APIs for opening and closing Near-Field Communication (NFC) and reading the NFC state.
> **NOTE**<br> > **NOTE**
>
> The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version. > The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## **Modules to Import** ## **Modules to Import**
``` ```js
import controller from '@ohos.nfc.controller'; import controller from '@ohos.nfc.controller';
``` ```
...@@ -18,7 +18,7 @@ Enumerates the NFC states. ...@@ -18,7 +18,7 @@ Enumerates the NFC states.
**System capability**: SystemCapability.Communication.NFC.Core **System capability**: SystemCapability.Communication.NFC.Core
| Name| Default Value| Description| | Name| Value| Description|
| -------- | -------- | -------- | | -------- | -------- | -------- |
| STATE_OFF | 1 | NFC is closed (OFF).| | STATE_OFF | 1 | NFC is closed (OFF).|
| STATE_TURNING_ON | 2 | NFC is turning on.| | STATE_TURNING_ON | 2 | NFC is turning on.|
...@@ -31,6 +31,9 @@ isNfcAvailable(): boolean ...@@ -31,6 +31,9 @@ isNfcAvailable(): boolean
Checks whether the device supports NFC. Checks whether the device supports NFC.
> **NOTE**
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use canIUse("SystemCapability.Communication.NFC.Core").
**System capability**: SystemCapability.Communication.NFC.Core **System capability**: SystemCapability.Communication.NFC.Core
**Return value** **Return value**
...@@ -46,6 +49,9 @@ openNfc(): boolean ...@@ -46,6 +49,9 @@ openNfc(): boolean
Opens NFC. Opens NFC.
> **NOTE**
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [enableNfc](#controllerenablenfc9).
**Required permissions**: ohos.permission.MANAGE_SECURE_SETTINGS **Required permissions**: ohos.permission.MANAGE_SECURE_SETTINGS
**System capability**: SystemCapability.Communication.NFC.Core **System capability**: SystemCapability.Communication.NFC.Core
...@@ -56,12 +62,33 @@ Opens NFC. ...@@ -56,12 +62,33 @@ Opens NFC.
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
## controller.enableNfc<sup>9+</sup>
enableNfc(): boolean
Opens NFC.
**Required permissions**: ohos.permission.MANAGE_SECURE_SETTINGS
**System capability**: SystemCapability.Communication.NFC.Core
**Error codes**
For details about the error codes, see [NFC Error Codes](../errorcodes/errorcode-nfc.md).
| ID| Error Message|
| ------- | -------|
| 3100101 | NFC state is abnormal in service. |
## controller.closeNfc ## controller.closeNfc
closeNfc(): boolean closeNfc(): boolean
Closes NFC. Closes NFC.
> **NOTE**
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [disableNfc](#controllerdisablenfc9).
**Required permissions**: ohos.permission.MANAGE_SECURE_SETTINGS **Required permissions**: ohos.permission.MANAGE_SECURE_SETTINGS
**System capability**: SystemCapability.Communication.NFC.Core **System capability**: SystemCapability.Communication.NFC.Core
...@@ -72,6 +99,24 @@ Closes NFC. ...@@ -72,6 +99,24 @@ Closes NFC.
| -------- | ------------------------------------------- | | -------- | ------------------------------------------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
## controller.disableNfc<sup>9+</sup>
disableNfc(): boolean
Closes NFC.
**Required permissions**: ohos.permission.MANAGE_SECURE_SETTINGS
**System capability**: SystemCapability.Communication.NFC.Core
**Error codes**
For details about the error codes, see [NFC Error Codes](../errorcodes/errorcode-nfc.md).
| ID| Error Message|
| ------- | -------|
| 3100101 | NFC state is abnormal in service. |
## controller.isNfcOpen ## controller.isNfcOpen
isNfcOpen(): boolean isNfcOpen(): boolean
...@@ -108,14 +153,12 @@ Subscribes to NFC state changes. A callback will be invoked to return the NFC st ...@@ -108,14 +153,12 @@ Subscribes to NFC state changes. A callback will be invoked to return the NFC st
**System capability**: SystemCapability.Communication.NFC.Core **System capability**: SystemCapability.Communication.NFC.Core
**Parameter** **Parameters**
| **Name**| **Type**| **Mandatory**| **Description**| | **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| type | string | Yes| Event type to subscribe to. The value is **nfcStateChange**.| | type | string | Yes| Event type to subscribe to. The value is **nfcStateChange**.|
| callback | Callback&lt;[NfcState](#nfcstate)&gt; | Yes| Callback invoked to return the NFC state.| | callback | Callback&lt;[NfcState](#nfcstate)&gt; | Yes| Callback invoked to return the NFC state.|
## controller.off('nfcStateChange') ## controller.off('nfcStateChange')
...@@ -125,42 +168,55 @@ Unsubscribes from the NFC state changes. The subscriber will not receive NFC sta ...@@ -125,42 +168,55 @@ Unsubscribes from the NFC state changes. The subscriber will not receive NFC sta
**System capability**: SystemCapability.Communication.NFC.Core **System capability**: SystemCapability.Communication.NFC.Core
**Parameter** **Parameters**
| **Name**| **Type**| **Mandatory**| **Description**| | **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| type | string | Yes| Event type to unsubscribe from. The value is **nfcStateChange**.| | type | string | Yes| Event type to unsubscribe from. The value is **nfcStateChange**.|
| callback | Callback&lt;[NfcState](#nfcstate)&gt; | No| Callback for the NFC state changes. This parameter can be left blank.| | callback | Callback&lt;[NfcState](#nfcstate)&gt; | No| Callback for the NFC state changes. This parameter can be left blank.|
**Example** **Example**
```js ```js
import controller from '@ohos.nfc.controller'; import controller from '@ohos.nfc.controller';
// Define a callback key.
var NFC_STATE_CALLBACK_KEY = "nfcStateChange";
// Register the callback to receive NFC state change notifications.
controller.on(NFC_STATE_CALLBACK_KEY, (err, nfcState)=> {
if (err) {
console.log("controller on callback err: " + err);
} else {
console.log("controller on callback nfcState: " + nfcState);
}
});
// Open NFC. Require permission: ohos.permission.MANAGE_SECURE_SETTINGS.
if (!controller.isNfcOpen()) {
var ret = controller.openNfc();
console.log("controller openNfc ret: " + ret);
}
// Close NFC. Require permission: ohos.permission.MANAGE_SECURE_SETTINGS. // Register the callback to receive NFC state change notifications.
if (controller.isNfcOpen()) { controller.on("nfcStateChange", (err, nfcState)=> {
var ret = controller.closeNfc(); if (err) {
console.log("controller closeNfc ret: " + ret); console.log("controller on callback err: " + err);
} else {
console.log("controller on callback nfcState: " + nfcState);
} }
});
// Unregister the callback. // Open NFC. Require permission: ohos.permission.MANAGE_SECURE_SETTINGS.
controller.off(NFC_STATE_CALLBACK_KEY); if (!controller.isNfcOpen()) {
``` var ret = controller.openNfc();
console.log("controller openNfc ret: " + ret);
}
// Use 'enableNfc' to enable NFC from API version 9.
try {
controller.enableNfc();
console.log("controller enableNfc success");
} catch (busiError) {
console.log("controller enableNfc busiError: " + busiError);
}
// Close NFC. Require permission: ohos.permission.MANAGE_SECURE_SETTINGS.
if (controller.isNfcOpen()) {
var ret = controller.closeNfc();
console.log("controller closeNfc ret: " + ret);
}
// Use 'disableNfc' to disable NFC from API version 9.
try {
controller.disableNfc();
console.log("controller disableNfc success");
} catch (busiError) {
console.log("controller disableNfc busiError: " + busiError);
}
// Unregister the callback.
controller.off("nfcStateChange");
```
...@@ -73,7 +73,7 @@ onCreate(want, launchParam) { ...@@ -73,7 +73,7 @@ onCreate(want, launchParam) {
try { try {
tagInfo = tag.getTagInfo(want); tagInfo = tag.getTagInfo(want);
} catch (error) { } catch (error) {
console.log("tag.getTagInfo catched error: " + error); console.log("tag.getTagInfo caught error: " + error);
} }
if (tagInfo == null || tagInfo == undefined) { if (tagInfo == null || tagInfo == undefined) {
console.log("no TagInfo to be created, ignore it."); console.log("no TagInfo to be created, ignore it.");
...@@ -100,7 +100,7 @@ onCreate(want, launchParam) { ...@@ -100,7 +100,7 @@ onCreate(want, launchParam) {
try { try {
nfcA = tag.getNfcATag(taginfo); nfcA = tag.getNfcATag(taginfo);
} catch (error) { } catch (error) {
console.log("tag.getNfcATag catched error: " + error); console.log("tag.getNfcATag caught error: " + error);
} }
// Other code to read or write this tag. // Other code to read or write this tag.
} }
...@@ -111,7 +111,7 @@ onCreate(want, launchParam) { ...@@ -111,7 +111,7 @@ onCreate(want, launchParam) {
try { try {
isoDep = tag.getIsoDep(taginfo); isoDep = tag.getIsoDep(taginfo);
} catch (error) { } catch (error) {
console.log("tag.getIsoDep catched error: " + error); console.log("tag.getIsoDep caught error: " + error);
} }
// Other code to read or write this tag. // Other code to read or write this tag.
} }
...@@ -126,64 +126,204 @@ getNfcATag(tagInfo: [TagInfo](#taginfo)): [NfcATag](js-apis-nfctech.md#nfcatag) ...@@ -126,64 +126,204 @@ getNfcATag(tagInfo: [TagInfo](#taginfo)): [NfcATag](js-apis-nfctech.md#nfcatag)
Obtains an **NfcATag** object, which allows access to the tags that use the NFC-A technology. Obtains an **NfcATag** object, which allows access to the tags that use the NFC-A technology.
**Required permissions**: ohos.permission.NFC_TAG > **NOTE**
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [tag.getNfcA](#taggetnfca9).
**System capability**: SystemCapability.Communication.NFC.Tag
**Parameters**
| 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)**.
**Return value**
| **Type**| **Description**|
| -------- | -------- |
| [NfcATag](js-apis-nfctech.md#nfcatag) | **NfcATag** object obtained.|
## tag.getNfcA<sup>9+</sup>
getNfcA(tagInfo: [TagInfo](#taginfo)): [NfcATag](js-apis-nfctech.md#nfcatag)
Obtains an **NfcATag** object, which allows access to the tags that use the NFC-A technology.
**System capability**: SystemCapability.Communication.NFC.Tag **System capability**: SystemCapability.Communication.NFC.Tag
**Parameters**
| 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)**.
**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**
For details about the error codes, see [NFC Error Codes](../errorcodes/errorcode-nfc.md).
| ID| Error Message|
| ------- | -------|
| 3100201 | Tag running state is abnormal in service. |
## tag.getNfcBTag ## tag.getNfcBTag
getNfcBTag(tagInfo: [TagInfo](#taginfo)): [NfcBTag](js-apis-nfctech.md#nfcbtag) getNfcBTag(tagInfo: [TagInfo](#taginfo)): [NfcBTag](js-apis-nfctech.md#nfcbtag)
Obtains an **NfcBTag** object, which allows access to the tags that use the NFC-B technology. Obtains an **NfcBTag** object, which allows access to the tags that use the NFC-B technology.
**Required permissions**: ohos.permission.NFC_TAG > **NOTE**
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [tag.getNfcB](#taggetnfcb9).
**System capability**: SystemCapability.Communication.NFC.Tag
**Parameters**
| 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)**.
**Return value**
| **Type**| **Description** |
| -------- | ---------------- |
| [NfcBTag](js-apis-nfctech.md#nfcbtag) | **NfcBTag** object obtained.|
## tag.getNfcB<sup>9+</sup>
getNfcB(tagInfo: [TagInfo](#taginfo)): [NfcBTag](js-apis-nfctech.md#nfcbtag)
Obtains an **NfcBTag** object, which allows access to the tags that use the NFC-B technology.
**System capability**: SystemCapability.Communication.NFC.Tag **System capability**: SystemCapability.Communication.NFC.Tag
**Parameters**
| 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)**.
**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**
For details about the error codes, see [NFC Error Codes](../errorcodes/errorcode-nfc.md).
| ID| Error Message|
| ------- | -------|
| 3100201 | Tag running state is abnormal in service. |
## tag.getNfcFTag ## tag.getNfcFTag
getNfcFTag(tagInfo: [TagInfo](#taginfo)): [NfcFTag](js-apis-nfctech.md#nfcftag) getNfcFTag(tagInfo: [TagInfo](#taginfo)): [NfcFTag](js-apis-nfctech.md#nfcftag)
Obtains an **NfcFTag** object, which allows access to the tags that use the NFC-F technology. Obtains an **NfcFTag** object, which allows access to the tags that use the NFC-F technology.
**Required permissions**: ohos.permission.NFC_TAG > **NOTE**
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [tag.getNfcF](#taggetnfcf9).
**System capability**: SystemCapability.Communication.NFC.Tag
**Parameters**
| 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)**.
**Return value**
| **Type**| **Description** |
| -------- | ---------------- |
| [NfcFTag](js-apis-nfctech.md#nfcftag) | **NfcFTag** object obtained.|
## tag.getNfcF<sup>9+</sup>
getNfcF(tagInfo: [TagInfo](#taginfo)): [NfcFTag](js-apis-nfctech.md#nfcftag)
Obtains an **NfcFTag** object, which allows access to the tags that use the NFC-F technology.
**System capability**: SystemCapability.Communication.NFC.Tag **System capability**: SystemCapability.Communication.NFC.Tag
**Parameters**
| 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)**.
**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**
For details about the error codes, see [NFC Error Codes](../errorcodes/errorcode-nfc.md).
| ID| Error Message|
| ------- | -------|
| 3100201 | Tag running state is abnormal in service. |
## tag.getNfcVTag ## tag.getNfcVTag
getNfcVTag(tagInfo: [TagInfo](#taginfo)): [NfcVTag](js-apis-nfctech.md#nfcvtag) getNfcVTag(tagInfo: [TagInfo](#taginfo)): [NfcVTag](js-apis-nfctech.md#nfcvtag)
Obtains an **NfcVTag** object, which allows access to the tags that use the NFC-V technology. Obtains an **NfcVTag** object, which allows access to the tags that use the NFC-V technology.
**Required permissions**: ohos.permission.NFC_TAG > **NOTE**
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [tag.getNfcV](#taggetnfcv9).
**System capability**: SystemCapability.Communication.NFC.Tag
**Parameters**
| 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)**.
**Return value**
| **Type**| **Description** |
| -------- | ---------------- |
| [NfcVTag](js-apis-nfctech.md#nfcvtag) | **NfcVTag** object obtained.|
## tag.getNfcV<sup>9+</sup>
getNfcV(tagInfo: [TagInfo](#taginfo)): [NfcVTag](js-apis-nfctech.md#nfcvtag)
Obtains an **NfcVTag** object, which allows access to the tags that use the NFC-V technology.
**System capability**: SystemCapability.Communication.NFC.Tag **System capability**: SystemCapability.Communication.NFC.Tag
**Parameters**
| 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)**.
**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**
For details about the error codes, see [NFC Error Codes](../errorcodes/errorcode-nfc.md).
| ID| Error Message|
| ------- | -------|
| 3100201 | Tag running state is abnormal in service. |
## tag.getIsoDep<sup>9+</sup> ## tag.getIsoDep<sup>9+</sup>
getIsoDep(tagInfo: [TagInfo](#taginfo)): [IsoDepTag](js-apis-nfctech.md#isoDepTag9 ) getIsoDep(tagInfo: [TagInfo](#taginfo)): [IsoDepTag](js-apis-nfctech.md#isoDepTag9 )
......
...@@ -26,8 +26,6 @@ getSak(): number ...@@ -26,8 +26,6 @@ getSak(): number
Obtains the SAK value of this NFC-A tag. Obtains the SAK value of this NFC-A tag.
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC.Tag **System capability**: SystemCapability.Communication.NFC.Tag
**Return value** **Return value**
...@@ -52,8 +50,6 @@ getAtqa(): number[] ...@@ -52,8 +50,6 @@ getAtqa(): number[]
Obtains the ATQA value of this NFC-A tag. Obtains the ATQA value of this NFC-A tag.
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC.Tag **System capability**: SystemCapability.Communication.NFC.Tag
**Return value** **Return value**
...@@ -86,8 +82,6 @@ getRespAppData(): number[] ...@@ -86,8 +82,6 @@ getRespAppData(): number[]
Obtains the application data of this NFC-B tag. Obtains the application data of this NFC-B tag.
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC.Tag **System capability**: SystemCapability.Communication.NFC.Tag
**Return value** **Return value**
...@@ -112,8 +106,6 @@ getRespProtocol(): number[] ...@@ -112,8 +106,6 @@ getRespProtocol(): number[]
Obtains the protocol information of this NFC-B tag. Obtains the protocol information of this NFC-B tag.
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC.Tag **System capability**: SystemCapability.Communication.NFC.Tag
**Return value** **Return value**
...@@ -146,8 +138,6 @@ getSystemCode(): number[] ...@@ -146,8 +138,6 @@ getSystemCode(): number[]
Obtains the system code from this NFC-F tag. Obtains the system code from this NFC-F tag.
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC.Tag **System capability**: SystemCapability.Communication.NFC.Tag
**Return value** **Return value**
...@@ -172,8 +162,6 @@ getPmm(): number[] ...@@ -172,8 +162,6 @@ getPmm(): number[]
Obtains the PMm (consisting of the IC code and manufacturer parameters) information from this NFC-F tag. Obtains the PMm (consisting of the IC code and manufacturer parameters) information from this NFC-F tag.
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC.Tag **System capability**: SystemCapability.Communication.NFC.Tag
**Return value** **Return value**
...@@ -206,8 +194,6 @@ getResponseFlags(): number ...@@ -206,8 +194,6 @@ getResponseFlags(): number
Obtains the response flags from this NFC-V tag. Obtains the response flags from this NFC-V tag.
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC.Tag **System capability**: SystemCapability.Communication.NFC.Tag
**Return value** **Return value**
...@@ -232,8 +218,6 @@ getDsfId(): number ...@@ -232,8 +218,6 @@ getDsfId(): number
Obtains the data storage format identifier (DSFID) from this NFC-V tag. Obtains the data storage format identifier (DSFID) from this NFC-V tag.
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC.Tag **System capability**: SystemCapability.Communication.NFC.Tag
**Return value** **Return value**
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
**Error Message** **Error Message**
NFC opening or closing state is abnormal in service. NFC state is abnormal in service.
**Description** **Description**
...@@ -12,11 +12,13 @@ The NFC service fails to enable or disable NFC. ...@@ -12,11 +12,13 @@ The NFC service fails to enable or disable NFC.
**Possible Causes** **Possible Causes**
Communication with the NFC service failed. 1. Communication with the NFC service failed.
2. The NFC chip communication is abnormal.
**Solution** **Solution**
Enable or disable NFC again. 1. Enable or disable NFC again.
2. Enable or disable NFC again or restart the device, and try again.
## 3100201 ## 3100201
...@@ -30,7 +32,7 @@ An error occurs when the NFC service executes the tag service logic. ...@@ -30,7 +32,7 @@ An error occurs when the NFC service executes the tag service logic.
**Possible Causes** **Possible Causes**
1. The tag parameters do not match the API to invoke. 1. The tag parameters do not match the API to invoke.
2. The NFC is disabled. 2. NFC is disabled.
3. The tag is disconnected before the tag operation. 3. The tag is disconnected before the tag operation.
4. The tag chip returns an error status or response timeout. 4. The tag chip returns an error status or response timeout.
5. Binding with the NFC service has not been established. 5. Binding with the NFC service has not been established.
......
# Changelog of NFC JS APIs in the Communication Subsystem
Compared with OpenHarmony 3.2 Beta4, OpenHarmony 3.2.10.2(Mr) has the following changes in NFC APIs:
## cl.nfc.1 API Change
Deprecated some NFC JS APIs in API versions 6 to 8 because the APIs cannot throw error codes, and added new APIs in API version 9 instead.
You need to adapt your application.
**Change Impact**
The deprecated JS APIs in API versions 6 to 8 are affected. Your application needs to adapt new APIs so that it can properly implement functions in the SDK environment of the new version.
**Key API/Component Changes**
| Module | Class | Method/Attribute/Enum/Constant | Change Type|
| ------------------------- | ------------------- | ------------------------------------------------------------ | -------- |
| api/@ohos.nfc.cardEmulation.d.ts | cardEmulation | FeatureType | Deprecated |
| api/@ohos.nfc.cardEmulation.d.ts | cardEmulation | isSupported | Deprecated |
| api/@ohos.nfc.cardEmulation.d.ts | cardEmulation | hasHceCapability | Added |
| api/@ohos.nfc.controller.d.ts | nfcController | isNfcAvailable | Deprecated |
| api/@ohos.nfc.controller.d.ts | nfcController | openNfc | Deprecated |
| api/@ohos.nfc.controller.d.ts | nfcController | closeNfc | Deprecated |
| api/@ohos.nfc.controller.d.ts | nfcController | enableNfc | Added |
| api/@ohos.nfc.controller.d.ts | nfcController | disableNfc | Added |
| api/@ohos.nfc.tag.d.ts | tag | getNfcATag | Deprecated |
| api/@ohos.nfc.tag.d.ts | tag | getNfcBTag | Deprecated |
| api/@ohos.nfc.tag.d.ts | tag | getNfcFTag | Deprecated |
| api/@ohos.nfc.tag.d.ts | tag | getNfcVTag | Deprecated |
| api/@ohos.nfc.tag.d.ts | tag | getNfcA | Added |
| api/@ohos.nfc.tag.d.ts | tag | getNfcB | Added |
| api/@ohos.nfc.tag.d.ts | tag | getNfcF | Added |
| api/@ohos.nfc.tag.d.ts | tag | getNfcV | Added |
| api/tag/tagSession.d.ts | TagSession | getTagInfo | Deprecated |
| api/tag/tagSession.d.ts | TagSession | connectTag | Deprecated |
| api/tag/tagSession.d.ts | TagSession | reset | Deprecated |
| api/tag/tagSession.d.ts | TagSession | isTagConnected | Deprecated |
| api/tag/tagSession.d.ts | TagSession | setSendDataTimeout | Deprecated |
| api/tag/tagSession.d.ts | TagSession | getSendDataTimeout | Deprecated |
| api/tag/tagSession.d.ts | TagSession | sendData | Deprecated |
| api/tag/tagSession.d.ts | TagSession | getMaxSendLength | Deprecated |
| api/tag/tagSession.d.ts | TagSession | connect | Added |
| api/tag/tagSession.d.ts | TagSession | resetConnection | Added |
| api/tag/tagSession.d.ts | TagSession | isConnected | Added |
| api/tag/tagSession.d.ts | TagSession | setTimeout | Added |
| api/tag/tagSession.d.ts | TagSession | getTimeout | Added |
| api/tag/tagSession.d.ts | TagSession | transmit | Added |
| api/tag/tagSession.d.ts | TagSession | getMaxTransmitSize | Added |
**Adaptation Guide**
See the following:
[@ohos.nfc.cardEmulation (Standard NFC Card Emulation)](../../../application-dev/reference/apis/js-apis-cardEmulation.md)
[@ohos.nfc.controller (Standard NFC)](../../../application-dev/reference/apis/js-apis-nfcController.md)
[@ohos.nfc.tag (Standard NFC Tags)](../../../application-dev/reference/apis/js-apis-nfcTag.md)
[tagSession (Standard NFC Tag Session)](../../../application-dev/reference/apis/js-apis-tagSession.md)
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册