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

!19558 [翻译完成】#I73Q5N (18430+17576+18630)

Merge pull request !19558 from Annie_wang/PR18269
...@@ -461,7 +461,7 @@ For details about the error codes, see [Application Access Control Error Codes]( ...@@ -461,7 +461,7 @@ For details about the error codes, see [Application Access Control Error Codes](
**Example** **Example**
```js ```js
import abilityAccessCtrl, {Permissions} from '@ohos.abilityAccessCtrl'; import {Permissions} from '@ohos.abilityAccessCtrl';
import bundleManager from '@ohos.bundle.bundleManager'; import bundleManager from '@ohos.bundle.bundleManager';
let atManager = abilityAccessCtrl.createAtManager(); let atManager = abilityAccessCtrl.createAtManager();
...@@ -512,7 +512,7 @@ For details about the error codes, see [Application Access Control Error Codes]( ...@@ -512,7 +512,7 @@ For details about the error codes, see [Application Access Control Error Codes](
**Example** **Example**
```js ```js
import abilityAccessCtrl, {Permissions} from '@ohos.abilityAccessCtrl'; import {Permissions} from '@ohos.abilityAccessCtrl';
import bundleManager from '@ohos.bundle.bundleManager'; import bundleManager from '@ohos.bundle.bundleManager';
let atManager = abilityAccessCtrl.createAtManager(); let atManager = abilityAccessCtrl.createAtManager();
......
...@@ -893,7 +893,7 @@ try { ...@@ -893,7 +893,7 @@ try {
on(type: "stateChange", callback: Callback<BluetoothState>): void on(type: "stateChange", callback: Callback<BluetoothState>): void
Subscribes to the Bluetooth connection state change events. Subscribes to Bluetooth state events.
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
...@@ -932,7 +932,7 @@ try { ...@@ -932,7 +932,7 @@ try {
off(type: "stateChange", callback?: Callback<BluetoothState>): void off(type: "stateChange", callback?: Callback<BluetoothState>): void
Unsubscribes from the Bluetooth connection state change events. Unsubscribes from Bluetooth state events.
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
...@@ -1994,7 +1994,7 @@ Subscribes to the HFP connection state change events. ...@@ -1994,7 +1994,7 @@ Subscribes to the HFP connection state change events.
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- | | -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type | string | Yes | Event type. The value **connectionStateChange** indicates an HFP connection state change event. | | type | string | Yes | Event type. The value **connectionStateChange** indicates an HFP connection state change event.|
| callback | Callback<[StateChangeParam](#StateChangeParam)> | Yes | Callback invoked to return the HFP connection state change event. | | callback | Callback<[StateChangeParam](#StateChangeParam)> | Yes | Callback invoked to return the HFP connection state change event. |
**Example** **Example**
...@@ -2075,7 +2075,7 @@ For details about the error codes, see [Bluetooth Error Codes](../errorcodes/err ...@@ -2075,7 +2075,7 @@ For details about the error codes, see [Bluetooth Error Codes](../errorcodes/err
```js ```js
try { try {
let hidHostProfile = bluetoothManager.getProfileInst(bluetoothManager.ProfileId.PROFILE_HID_HOST) as bluetoothManager.HidHostProfile; let hidHostProfile = bluetoothManager.getProfileInstance(bluetoothManager.ProfileId.PROFILE_HID_HOST) as bluetoothManager.HidHostProfile;
hidHostProfile.connect('XX:XX:XX:XX:XX:XX'); hidHostProfile.connect('XX:XX:XX:XX:XX:XX');
} catch (err) { } catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message); console.error("errCode:" + err.code + ",errMessage:" + err.message);
...@@ -2116,7 +2116,7 @@ For details about the error codes, see [Bluetooth Error Codes](../errorcodes/err ...@@ -2116,7 +2116,7 @@ For details about the error codes, see [Bluetooth Error Codes](../errorcodes/err
```js ```js
try { try {
let hidHostProfile = bluetoothManager.getProfileInst(bluetoothManager.ProfileId.PROFILE_HID_HOST) as bluetoothManager.HidHostProfile; let hidHostProfile = bluetoothManager.getProfileInstance(bluetoothManager.ProfileId.PROFILE_HID_HOST) as bluetoothManager.HidHostProfile;
hidHostProfile.disconnect('XX:XX:XX:XX:XX:XX'); hidHostProfile.disconnect('XX:XX:XX:XX:XX:XX');
} catch (err) { } catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message); console.error("errCode:" + err.code + ",errMessage:" + err.message);
...@@ -2145,7 +2145,7 @@ Subscribes to the HidHost connection state change events. ...@@ -2145,7 +2145,7 @@ Subscribes to the HidHost connection state change events.
function onReceiveEvent(data) { function onReceiveEvent(data) {
console.info('hidHost state = '+ JSON.stringify(data)); console.info('hidHost state = '+ JSON.stringify(data));
} }
let hidHost = bluetoothManager.getProfileInst(bluetoothManager.ProfileId.PROFILE_HID_HOST) as bluetoothManager.HidHostProfile; let hidHost = bluetoothManager.getProfileInstance(bluetoothManager.ProfileId.PROFILE_HID_HOST) as bluetoothManager.HidHostProfile;
hidHost.on('connectionStateChange', onReceiveEvent); hidHost.on('connectionStateChange', onReceiveEvent);
``` ```
...@@ -2171,7 +2171,7 @@ Unsubscribes from the HidHost connection state change events. ...@@ -2171,7 +2171,7 @@ Unsubscribes from the HidHost connection state change events.
function onReceiveEvent(data) { function onReceiveEvent(data) {
console.info('hidHost state = '+ JSON.stringify(data)); console.info('hidHost state = '+ JSON.stringify(data));
} }
let hidHost = bluetoothManager.getProfileInst(bluetoothManager.ProfileId.PROFILE_HID_HOST) as bluetoothManager.HidHostProfile; let hidHost = bluetoothManager.getProfileInstance(bluetoothManager.ProfileId.PROFILE_HID_HOST) as bluetoothManager.HidHostProfile;
hidHost.on('connectionStateChange', onReceiveEvent); hidHost.on('connectionStateChange', onReceiveEvent);
hidHost.off('connectionStateChange', onReceiveEvent); hidHost.off('connectionStateChange', onReceiveEvent);
``` ```
...@@ -2215,7 +2215,7 @@ For details about the error codes, see [Bluetooth Error Codes](../errorcodes/err ...@@ -2215,7 +2215,7 @@ For details about the error codes, see [Bluetooth Error Codes](../errorcodes/err
```js ```js
try { try {
let panProfile = bluetoothManager.getProfileInst(bluetoothManager.ProfileId.PROFILE_PAN_NETWORK) as bluetoothManager.PanProfile; let panProfile = bluetoothManager.getProfileInstance(bluetoothManager.ProfileId.PROFILE_PAN_NETWORK) as bluetoothManager.PanProfile;
panProfile.disconnect('XX:XX:XX:XX:XX:XX'); panProfile.disconnect('XX:XX:XX:XX:XX:XX');
} catch (err) { } catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message); console.error("errCode:" + err.code + ",errMessage:" + err.message);
...@@ -2244,7 +2244,7 @@ Subscribes to the PAN connection state change events. ...@@ -2244,7 +2244,7 @@ Subscribes to the PAN connection state change events.
function onReceiveEvent(data) { function onReceiveEvent(data) {
console.info('pan state = '+ JSON.stringify(data)); console.info('pan state = '+ JSON.stringify(data));
} }
let panProfile = bluetoothManager.getProfileInst(bluetoothManager.ProfileId.PROFILE_PAN_NETWORK) as bluetoothManager.PanProfile; let panProfile = bluetoothManager.getProfileInstance(bluetoothManager.ProfileId.PROFILE_PAN_NETWORK) as bluetoothManager.PanProfile;
panProfile.on('connectionStateChange', onReceiveEvent); panProfile.on('connectionStateChange', onReceiveEvent);
``` ```
...@@ -2270,7 +2270,7 @@ Unsubscribes from the PAN connection state change events. ...@@ -2270,7 +2270,7 @@ Unsubscribes from the PAN connection state change events.
function onReceiveEvent(data) { function onReceiveEvent(data) {
console.info('pan state = '+ JSON.stringify(data)); console.info('pan state = '+ JSON.stringify(data));
} }
let panProfile = bluetoothManager.getProfileInst(bluetoothManager.ProfileId.PROFILE_PAN_NETWORK) as bluetoothManager.PanProfile; let panProfile = bluetoothManager.getProfileInstance(bluetoothManager.ProfileId.PROFILE_PAN_NETWORK) as bluetoothManager.PanProfile;
panProfile.on('connectionStateChange', onReceiveEvent); panProfile.on('connectionStateChange', onReceiveEvent);
panProfile.off('connectionStateChange', onReceiveEvent); panProfile.off('connectionStateChange', onReceiveEvent);
``` ```
...@@ -2309,7 +2309,7 @@ For details about the error codes, see [Bluetooth Error Codes](../errorcodes/err ...@@ -2309,7 +2309,7 @@ For details about the error codes, see [Bluetooth Error Codes](../errorcodes/err
```js ```js
try { try {
let panProfile = bluetoothManager.getProfileInst(bluetoothManager.ProfileId.PROFILE_PAN_NETWORK) as bluetoothManager.PanProfile; let panProfile = bluetoothManager.getProfileInstance(bluetoothManager.ProfileId.PROFILE_PAN_NETWORK) as bluetoothManager.PanProfile;
panProfile.setTethering(true); panProfile.setTethering(true);
} catch (err) { } catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message); console.error("errCode:" + err.code + ",errMessage:" + err.message);
...@@ -2337,7 +2337,7 @@ Obtains the network sharing status. ...@@ -2337,7 +2337,7 @@ Obtains the network sharing status.
```js ```js
try { try {
let panProfile = bluetoothManager.getProfileInst(bluetoothManager.ProfileId.PROFILE_PAN_NETWORK) as bluetoothManager.PanProfile; let panProfile = bluetoothManager.getProfileInstance(bluetoothManager.ProfileId.PROFILE_PAN_NETWORK) as bluetoothManager.PanProfile;
let ret = panProfile.isTetheringOn(); let ret = panProfile.isTetheringOn();
} catch (err) { } catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message); console.error("errCode:" + err.code + ",errMessage:" + err.message);
......
# @ohos.connectedTag # @ohos.connectedTag (Active Tags)
The **connectedTag** module provides APIs for using active tags. You can use the APIs to initialize the active tag chip and read and write active tags. The **connectedTag** module provides APIs for using active tags. You can use the APIs to initialize the active tag chip and read and write active tags.
...@@ -28,6 +28,23 @@ Initializes the active tag chip. ...@@ -28,6 +28,23 @@ Initializes the active tag chip.
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
## connectedTag.initialize<sup>9+</sup>
initialize(): void
Initializes the active tag chip.
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.ConnectedTag
**Error codes**
For details about the error codes, see [NFC Error Codes](../errorcodes/errorcode-nfc.md).
| ID| Error Message|
| -------- | -------- |
| 3200101 | Connected NFC tag running state is abnormal in service. |
## connectedTag.uninit ## connectedTag.uninit
uninit(): boolean uninit(): boolean
...@@ -44,6 +61,23 @@ Uninitializes the active tag resources. ...@@ -44,6 +61,23 @@ Uninitializes the active tag resources.
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
## connectedTag.uninitialize<sup>9+</sup>
uninitialize(): void
Uninitializes the active tag resources.
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.ConnectedTag
**Error codes**
For details about the error codes, see [NFC Error Codes](../errorcodes/errorcode-nfc.md).
| ID| Error Message|
| -------- | -------- |
| 3200101 | Connected NFC tag running state is abnormal in service. |
## connectedTag.readNdefTag ## connectedTag.readNdefTag
readNdefTag(): Promise&lt;string&gt; readNdefTag(): Promise&lt;string&gt;
...@@ -72,6 +106,41 @@ connectedTag.readNdefTag().then((data) => { ...@@ -72,6 +106,41 @@ connectedTag.readNdefTag().then((data) => {
}); });
``` ```
## connectedTag.read<sup>9+</sup>
read(): Promise&lt;number[]&gt;
Reads the content of this active tag. This API uses a promise to return the result.
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.ConnectedTag
**Return value**
| **Type**| **Description**|
| -------- | -------- |
| Promise&lt;number[]&gt; | Promise used to return the content of the active tag.|
**Error codes**
For details about the error codes, see [NFC Error Codes](../errorcodes/errorcode-nfc.md).
| ID| Error Message|
| -------- | -------- |
| 3200101 | Connected NFC tag running state is abnormal in service. |
**Example**
```js
import connectedTag from '@ohos.connectedTag';
connectedTag.read().then((data) => {
console.log("connectedTag read Promise data = " + data);
}).catch((err)=> {
console.log("connectedTag read Promise err: " + err);
});
```
## connectedTag.readNdefTag ## connectedTag.readNdefTag
readNdefTag(callback: AsyncCallback&lt;string&gt;): void readNdefTag(callback: AsyncCallback&lt;string&gt;): void
...@@ -102,6 +171,43 @@ connectedTag.readNdefTag((err, data)=> { ...@@ -102,6 +171,43 @@ connectedTag.readNdefTag((err, data)=> {
}); });
``` ```
## connectedTag.read<sup>9+</sup>
read(callback: AsyncCallback&lt;number[]&gt;): void
Reads the content of this active tag. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.ConnectedTag
**Parameters**
| **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;number[]&gt; | Yes| Callback invoked to return the active tag content obtained.|
**Error codes**
For details about the error codes, see [NFC Error Codes](../errorcodes/errorcode-nfc.md).
| ID| Error Message|
| -------- | -------- |
| 3200101 | Connected NFC tag running state is abnormal in service. |
**Example**
```js
import connectedTag from '@ohos.connectedTag';
connectedTag.read((err, data)=> {
if (err) {
console.log("connectedTag read AsyncCallback err: " + err);
} else {
console.log("connectedTag read AsyncCallback data: " + data);
}
});
```
## connectedTag.writeNdefTag ## connectedTag.writeNdefTag
writeNdefTag(data: string): Promise&lt;void&gt; writeNdefTag(data: string): Promise&lt;void&gt;
...@@ -129,7 +235,7 @@ Writes data to this active tag. This API uses a promise to return the result. ...@@ -129,7 +235,7 @@ Writes data to this active tag. This API uses a promise to return the result.
```js ```js
import connectedTag from '@ohos.connectedTag'; import connectedTag from '@ohos.connectedTag';
var rawData = "010203"; // change it tobe correct. var rawData = "010203"; // Set it as required.
connectedTag.writeNdefTag(rawData).then(() => { connectedTag.writeNdefTag(rawData).then(() => {
console.log("connectedTag writeNdefTag Promise success."); console.log("connectedTag writeNdefTag Promise success.");
}).catch((err)=> { }).catch((err)=> {
...@@ -137,6 +243,48 @@ connectedTag.writeNdefTag(rawData).then(() => { ...@@ -137,6 +243,48 @@ connectedTag.writeNdefTag(rawData).then(() => {
}); });
``` ```
## connectedTag.write<sup>9+</sup>
write(data: number[]): Promise&lt;void&gt;
Writes data to this active tag. This API uses a promise to return the result.
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.ConnectedTag
**Parameters**
| **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- |
| data | number[] | Yes| Data to be written to the active tag. The value is a hexadecimal number ranging from 0x00 to 0xFF.|
**Return value**
| **Type**| **Description**|
| -------- | -------- |
| Promise&lt;void&gt; | Promise that returns no value.|
**Error codes**
For details about the error codes, see [NFC Error Codes](../errorcodes/errorcode-nfc.md).
| ID| Error Message|
| -------- | -------- |
| 3200101 | Connected NFC tag running state is abnormal in service. |
**Example**
```js
import connectedTag from '@ohos.connectedTag';
var rawData = [0x01, 0x02, 0x03]; // change it tobe correct.
connectedTag.write(rawData).then(() => {
console.log("connectedTag write NdefTag Promise success.");
}).catch((err)=> {
console.log("connectedTag write NdefTag Promise err: " + err);
});
```
## connectedTag.writeNdefTag ## connectedTag.writeNdefTag
writeNdefTag(data: string, callback: AsyncCallback&lt;void&gt;): void writeNdefTag(data: string, callback: AsyncCallback&lt;void&gt;): void
...@@ -159,7 +307,7 @@ Writes data to this active tag. This API uses an asynchronous callback to return ...@@ -159,7 +307,7 @@ Writes data to this active tag. This API uses an asynchronous callback to return
```js ```js
import connectedTag from '@ohos.connectedTag'; import connectedTag from '@ohos.connectedTag';
var rawData = "010203"; // change it tobe correct. var rawData = "010203"; // Set it as required.
connectedTag.writeNdefTag(rawData, (err)=> { connectedTag.writeNdefTag(rawData, (err)=> {
if (err) { if (err) {
console.log("connectedTag writeNdefTag AsyncCallback err: " + err); console.log("connectedTag writeNdefTag AsyncCallback err: " + err);
...@@ -169,6 +317,45 @@ connectedTag.writeNdefTag(rawData, (err)=> { ...@@ -169,6 +317,45 @@ connectedTag.writeNdefTag(rawData, (err)=> {
}); });
``` ```
## connectedTag.write<sup>9+</sup>
write(data: number[], callback: AsyncCallback&lt;void&gt;): void
Writes data to this active tag. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.ConnectedTag
**Parameters**
| **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- |
| data | number[] | Yes| Data to be written to the active tag. The value is a hexadecimal number ranging from 0x00 to 0xFF.|
| callback | AsyncCallback&lt;void&gt; | Yes| Callback invoked to return the active tag content obtained.|
**Error codes**
For details about the error codes, see [NFC Error Codes](../errorcodes/errorcode-nfc.md).
| ID| Error Message|
| -------- | -------- |
| 3200101 | Connected NFC tag running state is abnormal in service. |
**Example**
```js
import connectedTag from '@ohos.connectedTag';
var rawData = [0x01, 0x02, 0x03]; // change it tobe correct.
connectedTag.write(rawData, (err)=> {
if (err) {
console.log("connectedTag write NdefTag AsyncCallback err: " + err);
} else {
console.log("connectedTag write NdefTag AsyncCallback success.");
}
});
```
## connectedTag.on('notify') ## connectedTag.on('notify')
on(type: "notify", callback: Callback&lt;number&gt;): void on(type: "notify", callback: Callback&lt;number&gt;): void
...@@ -220,7 +407,7 @@ connectedTag.on("notify", (err, rfState)=> { ...@@ -220,7 +407,7 @@ connectedTag.on("notify", (err, rfState)=> {
var initStatus = connectedTag.init(); var initStatus = connectedTag.init();
console.log("connectedTag init status: " + initStatus); console.log("connectedTag init status: " + initStatus);
// Add nfc connecected tag business oprations here... // Add NFC connected tag business operations here.
// connectedTag.writeNdefTag(rawData) // connectedTag.writeNdefTag(rawData)
// connectedTag.readNdefTag() // connectedTag.readNdefTag()
......
...@@ -176,7 +176,7 @@ Unsubscribes from the NFC state changes. The subscriber will not receive NFC sta ...@@ -176,7 +176,7 @@ Unsubscribes from the NFC state changes. The subscriber will not receive NFC sta
| **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. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.|
**Example** **Example**
......
...@@ -47,3 +47,21 @@ An error occurs when the NFC service executes the tag service logic. ...@@ -47,3 +47,21 @@ An error occurs when the NFC service executes the tag service logic.
3. Connect to the tag and then perform the read and write operations. 3. Connect to the tag and then perform the read and write operations.
4. Touch and read the card again. 4. Touch and read the card again.
5. Exit the app and read the card again. 5. Exit the app and read the card again.
## 3200101
**Error Message**
Connected NFC tag running state is abnormal in service.
**Description**
An error occurs when the service logic of the active NFC tag is executed.
**Possible Causes**
1. The parameter values of the active NFC tag does not match the API called.
2. The active NFC tag chip does not respond within the specified time or returns an error state.
**Solution**
1. Check that the active NFC tag parameters match the API called.
2. Touch and read the card again.
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册