提交 b49ad74f 编写于 作者: A Annie_wang

update docs

Signed-off-by: NAnnie_wang <annie.wangli@huawei.com>
上级 9a9e637f
...@@ -268,7 +268,7 @@ ...@@ -268,7 +268,7 @@
- [@ohos.request (Upload and Download)](js-apis-request.md) - [@ohos.request (Upload and Download)](js-apis-request.md)
- Connectivity - Connectivity
- [@ohos.bluetooth (Bluetooth)](js-apis-bluetooth.md) - [@ohos.bluetoothManager (Bluetooth)(js-apis-bluetoothManager.md)
- [@ohos.connectedTag (Active Tags)](js-apis-connectedTag.md) - [@ohos.connectedTag (Active Tags)](js-apis-connectedTag.md)
- [@ohos.nfc.cardEmulation (Standard NFC Card Emulation)](js-apis-cardEmulation.md) - [@ohos.nfc.cardEmulation (Standard NFC Card Emulation)](js-apis-cardEmulation.md)
- [@ohos.nfc.controller (Standard NFC)](js-apis-nfcController.md) - [@ohos.nfc.controller (Standard NFC)](js-apis-nfcController.md)
...@@ -392,6 +392,7 @@ ...@@ -392,6 +392,7 @@
- APIs No Longer Maintained - APIs No Longer Maintained
- [@ohos.backgroundTaskManager (Background Task Management)](js-apis-backgroundTaskManager.md) - [@ohos.backgroundTaskManager (Background Task Management)](js-apis-backgroundTaskManager.md)
- [@ohos.bluetooth (Bluetooth)](js-apis-bluetooth.md)
- [@ohos.bundle (Bundle)](js-apis-Bundle.md) - [@ohos.bundle (Bundle)](js-apis-Bundle.md)
- [@ohos.bundle.innerBundleManager (innerBundleManager)](js-apis-Bundle-InnerBundleManager.md) - [@ohos.bundle.innerBundleManager (innerBundleManager)](js-apis-Bundle-InnerBundleManager.md)
- [@ohos.bundleState (Device Usage Statistics)](js-apis-deviceUsageStatistics.md) - [@ohos.bundleState (Device Usage Statistics)](js-apis-deviceUsageStatistics.md)
......
...@@ -4,7 +4,8 @@ The **Bluetooth** module provides classic Bluetooth capabilities and Bluetooth L ...@@ -4,7 +4,8 @@ The **Bluetooth** module provides classic Bluetooth capabilities and Bluetooth L
> **NOTE** > **NOTE**
> >
> The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version. > - The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> - The APIs provided by this module are no longer maintained since API version 9. You are advised to use [bluetoothManager](js-apis-bluetoothManager.md).
...@@ -15,12 +16,15 @@ import bluetooth from '@ohos.bluetooth'; ...@@ -15,12 +16,15 @@ import bluetooth from '@ohos.bluetooth';
``` ```
## bluetooth.enableBluetooth<sup>8+</sup><a name="enableBluetooth"></a> ## bluetooth.enableBluetooth<sup>8+</sup><sup>(deprecated)</sup><a name="enableBluetooth"></a>
enableBluetooth(): boolean enableBluetooth(): boolean
Enables Bluetooth. Enables Bluetooth.
> **NOTE**
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.enableBluetooth](js-apis-bluetoothManager.md#bluetoothmanagerenablebluetooth).
**Required permissions**: ohos.permission.DISCOVER_BLUETOOTH **Required permissions**: ohos.permission.DISCOVER_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -38,12 +42,15 @@ let enable = bluetooth.enableBluetooth(); ...@@ -38,12 +42,15 @@ let enable = bluetooth.enableBluetooth();
``` ```
## bluetooth.disableBluetooth<sup>8+</sup><a name="disableBluetooth"></a> ## bluetooth.disableBluetooth<sup>8+</sup><sup>(deprecated)</sup><a name="disableBluetooth"></a>
disableBluetooth(): boolean disableBluetooth(): boolean
Disables Bluetooth. Disables Bluetooth.
> **NOTE**<br>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.disableBluetooth](js-apis-bluetoothManager.md#bluetoothmanagerdisablebluetooth).
**Required permissions**: ohos.permission.DISCOVER_BLUETOOTH **Required permissions**: ohos.permission.DISCOVER_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -61,12 +68,15 @@ let disable = bluetooth.disableBluetooth(); ...@@ -61,12 +68,15 @@ let disable = bluetooth.disableBluetooth();
``` ```
## bluetooth.getLocalName<sup>8+</sup><a name="getLocalName"></a> ## bluetooth.getLocalName<sup>8+</sup><sup>(deprecated)</sup><a name="getLocalName"></a>
getLocalName(): string getLocalName(): string
Obtains the name of the local Bluetooth device. Obtains the name of the local Bluetooth device.
> **NOTE**<br>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.getLocalName](js-apis-bluetoothManager.md#bluetoothmanagergetlocalname).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -84,12 +94,15 @@ let localName = bluetooth.getLocalName(); ...@@ -84,12 +94,15 @@ let localName = bluetooth.getLocalName();
``` ```
## bluetooth.getState ## bluetooth.getState<sup>(deprecated)</sup><a name="getState"></a>
getState(): BluetoothState getState(): BluetoothState
Obtains the Bluetooth state. Obtains the Bluetooth state.
> **NOTE**<br>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.getState](js-apis-bluetoothManager.md#bluetoothmanagergetstate).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -107,11 +120,14 @@ let state = bluetooth.getState(); ...@@ -107,11 +120,14 @@ let state = bluetooth.getState();
``` ```
## bluetooth.getBtConnectionState ## bluetooth.getBtConnectionState<sup>(deprecated)</sup><a name="getBtConnectionState"></a>
getBtConnectionState(): ProfileConnectionState getBtConnectionState(): ProfileConnectionState
Obtains the profile connection state of this Bluetooth device. Obtains the local profile connection state.
> **NOTE**<br>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.getBtConnectionState](js-apis-bluetoothManager.md#bluetoothmanagergetbtconnectionstate).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
...@@ -130,12 +146,15 @@ let connectionState = bluetooth.getBtConnectionState(); ...@@ -130,12 +146,15 @@ let connectionState = bluetooth.getBtConnectionState();
``` ```
## bluetooth.setLocalName<sup>8+</sup><a name="setLocalName"></a> ## bluetooth.setLocalName<sup>8+</sup><sup>(deprecated)</sup><a name="setLocalName"></a>
setLocalName(name: string): boolean setLocalName(name: string): boolean
Sets the name of the local Bluetooth device. Sets the name of the local Bluetooth device.
> **NOTE**<br>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.setLocalName](js-apis-bluetoothManager.md#bluetoothmanagersetlocalname).
**Required permissions**: ohos.permission.DISCOVER_BLUETOOTH **Required permissions**: ohos.permission.DISCOVER_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -159,12 +178,15 @@ let ret = bluetooth.setLocalName('device_name'); ...@@ -159,12 +178,15 @@ let ret = bluetooth.setLocalName('device_name');
``` ```
## bluetooth.pairDevice ## bluetooth.pairDevice<sup>(deprecated)</sup><a name="pairDevice"></a>
pairDevice(deviceId: string): boolean pairDevice(deviceId: string): boolean
Initiates Bluetooth pairing. Initiates Bluetooth pairing.
> **NOTE**<br>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.pairDevice](js-apis-bluetoothManager.md#bluetoothmanagerpairdevice).
**Required permissions**: ohos.permission.DISCOVER_BLUETOOTH **Required permissions**: ohos.permission.DISCOVER_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -189,11 +211,14 @@ let result = bluetooth.pairDevice("XX:XX:XX:XX:XX:XX"); ...@@ -189,11 +211,14 @@ let result = bluetooth.pairDevice("XX:XX:XX:XX:XX:XX");
``` ```
## bluetooth.getProfileConnState<sup>8+</sup><a name="getProfileConnState"></a> ## bluetooth.getProfileConnState<sup>8+</sup><sup>(deprecated)</sup><a name="getProfileConnState"></a>
getProfileConnState(profileId: ProfileId): ProfileConnectionState getProfileConnState(profileId: ProfileId): ProfileConnectionState
Obtains the connection state of a profile. Obtains the connection status of a specified profile.
> **NOTE**
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.getProfileConnectionState](js-apis-bluetoothManager.md#bluetoothmanagergetprofileconnectionstate).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
...@@ -218,12 +243,15 @@ let result = bluetooth.getProfileConnState(bluetooth.ProfileId.PROFILE_A2DP_SOUR ...@@ -218,12 +243,15 @@ let result = bluetooth.getProfileConnState(bluetooth.ProfileId.PROFILE_A2DP_SOUR
``` ```
## bluetooth.cancelPairedDevice<sup>8+</sup><a name="cancelPairedDevice"></a> ## bluetooth.cancelPairedDevice<sup>8+</sup><sup>(deprecated)</sup><a name="cancelPairedDevice"></a>
cancelPairedDevice(deviceId: string): boolean cancelPairedDevice(deviceId: string): boolean
Cancels a paired remote device. Cancels a paired remote device.
> **NOTE**<br>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.cancelPairedDevice](js-apis-bluetoothManager.md#bluetoothmanagercancelpaireddevice).
**System API**: This is a system API. **System API**: This is a system API.
**Required permissions**: ohos.permission.DISCOVER_BLUETOOTH **Required permissions**: ohos.permission.DISCOVER_BLUETOOTH
...@@ -249,12 +277,15 @@ let result = bluetooth.cancelPairedDevice("XX:XX:XX:XX:XX:XX"); ...@@ -249,12 +277,15 @@ let result = bluetooth.cancelPairedDevice("XX:XX:XX:XX:XX:XX");
``` ```
## bluetooth.getRemoteDeviceName<sup>8+</sup><a name="getRemoteDeviceName"></a> ## bluetooth.getRemoteDeviceName<sup>8+</sup><sup>(deprecated)</sup><a name="getRemoteDeviceName"></a>
getRemoteDeviceName(deviceId: string): string getRemoteDeviceName(deviceId: string): string
Obtains the name of the remote Bluetooth device. Obtains the name of the remote Bluetooth device.
> **NOTE**<br>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.getRemoteDeviceName](js-apis-bluetoothManager.md#bluetoothmanagergetremotedevicename).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -278,12 +309,15 @@ let remoteDeviceName = bluetooth.getRemoteDeviceName("XX:XX:XX:XX:XX:XX"); ...@@ -278,12 +309,15 @@ let remoteDeviceName = bluetooth.getRemoteDeviceName("XX:XX:XX:XX:XX:XX");
``` ```
## bluetooth.getRemoteDeviceClass<sup>8+</sup><a name="getRemoteDeviceClass"></a> ## bluetooth.getRemoteDeviceClass<sup>8+</sup><sup>(deprecated)</sup><a name="getRemoteDeviceClass"></a>
getRemoteDeviceClass(deviceId: string): DeviceClass getRemoteDeviceClass(deviceId: string): DeviceClass
Obtains the class of the remote Bluetooth device. Obtains the class of the remote Bluetooth device.
> **NOTE**<br>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.getRemoteDeviceClass](js-apis-bluetoothManager.md#bluetoothmanagergetremotedeviceclass).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -307,12 +341,15 @@ let remoteDeviceClass = bluetooth.getRemoteDeviceClass("XX:XX:XX:XX:XX:XX"); ...@@ -307,12 +341,15 @@ let remoteDeviceClass = bluetooth.getRemoteDeviceClass("XX:XX:XX:XX:XX:XX");
``` ```
## bluetooth.getPairedDevices<sup>8+</sup><a name="getPairedDevices"></a> ## bluetooth.getPairedDevices<sup>8+</sup><sup>(deprecated)</sup><a name="getPairedDevices"></a>
getPairedDevices(): Array&lt;string&gt; getPairedDevices(): Array&lt;string&gt;
Obtains the paired devices. Obtains the paired devices.
> **NOTE**<br>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.getPairedDevices](js-apis-bluetoothManager.md#bluetoothmanagergetpaireddevices).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -330,12 +367,15 @@ let devices = bluetooth.getPairedDevices(); ...@@ -330,12 +367,15 @@ let devices = bluetooth.getPairedDevices();
``` ```
## bluetooth.setBluetoothScanMode<sup>8+</sup><a name="setBluetoothScanMode"></a> ## bluetooth.setBluetoothScanMode<sup>8+</sup><sup>(deprecated)</sup><a name="setBluetoothScanMode"></a>
setBluetoothScanMode(mode: ScanMode, duration: number): boolean setBluetoothScanMode(mode: ScanMode, duration: number): boolean
Sets the Bluetooth scan mode so that the device can be discovered by a remote device. Sets the Bluetooth scan mode so that the device can be discovered by a remote device.
> **NOTE**<br>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.setBluetoothScanMode](js-apis-bluetoothManager.md#bluetoothmanagersetbluetoothscanmode).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -361,12 +401,15 @@ let result = bluetooth.setBluetoothScanMode(bluetooth.ScanMode.SCAN_MODE_CONNECT ...@@ -361,12 +401,15 @@ let result = bluetooth.setBluetoothScanMode(bluetooth.ScanMode.SCAN_MODE_CONNECT
``` ```
## bluetooth.getBluetoothScanMode<sup>8+</sup><a name="getBluetoothScanMode"></a> ## bluetooth.getBluetoothScanMode<sup>8+</sup><sup>(deprecated)</sup><a name="getBluetoothScanMode"></a>
getBluetoothScanMode(): ScanMode getBluetoothScanMode(): ScanMode
Obtains the Bluetooth scan mode. Obtains the Bluetooth scan mode.
> **NOTE**<br>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.getBluetoothScanMode](js-apis-bluetoothManager.md#bluetoothmanagergetbluetoothscanmode).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -384,12 +427,15 @@ let scanMode = bluetooth.getBluetoothScanMode(); ...@@ -384,12 +427,15 @@ let scanMode = bluetooth.getBluetoothScanMode();
``` ```
## bluetooth.startBluetoothDiscovery<sup>8+</sup><a name="startBluetoothDiscovery"></a> ## bluetooth.startBluetoothDiscovery<sup>8+</sup><sup>(deprecated)</sup><a name="startBluetoothDiscovery"></a>
startBluetoothDiscovery(): boolean startBluetoothDiscovery(): boolean
Starts Bluetooth scan to discover remote devices. Starts Bluetooth scan to discover remote devices.
> **NOTE**<br>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.startBluetoothDiscovery](js-apis-bluetoothManager.md#bluetoothmanagerstartbluetoothdiscovery).
**Required permissions**: ohos.permission.DISCOVER_BLUETOOTH and ohos.permission.LOCATION **Required permissions**: ohos.permission.DISCOVER_BLUETOOTH and ohos.permission.LOCATION
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -412,12 +458,15 @@ let result = bluetooth.startBluetoothDiscovery(); ...@@ -412,12 +458,15 @@ let result = bluetooth.startBluetoothDiscovery();
``` ```
## bluetooth.stopBluetoothDiscovery<sup>8+</sup><a name="stopBluetoothDiscovery"></a> ## bluetooth.stopBluetoothDiscovery<sup>8+</sup><sup>(deprecated)</sup><a name="stopBluetoothDiscovery"></a>
stopBluetoothDiscovery(): boolean stopBluetoothDiscovery(): boolean
Stops Bluetooth scan. Stops Bluetooth scan.
> **NOTE**<br>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.stopBluetoothDiscovery](js-apis-bluetoothManager.md#bluetoothmanagerstopbluetoothdiscovery).
**Required permissions**: ohos.permission.DISCOVER_BLUETOOTH **Required permissions**: ohos.permission.DISCOVER_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -435,12 +484,15 @@ let result = bluetooth.stopBluetoothDiscovery(); ...@@ -435,12 +484,15 @@ let result = bluetooth.stopBluetoothDiscovery();
``` ```
## bluetooth.setDevicePairingConfirmation<sup>8+</sup><a name="setDevicePairingConfirmation"></a> ## bluetooth.setDevicePairingConfirmation<sup>8+</sup><sup>(deprecated)</sup><a name="setDevicePairingConfirmation"></a>
setDevicePairingConfirmation(device: string, accept: boolean): boolean setDevicePairingConfirmation(device: string, accept: boolean): boolean
Sets the device pairing confirmation. Sets the device pairing confirmation.
> **NOTE**<br>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.setDevicePairingConfirmation](js-apis-bluetoothManager.md#bluetoothmanagersetdevicepairingconfirmation).
**Required permissions**: ohos.permission.MANAGE_BLUETOOTH **Required permissions**: ohos.permission.MANAGE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -470,12 +522,15 @@ bluetooth.on("pinRequired", onReceivePinRequiredEvent); ...@@ -470,12 +522,15 @@ bluetooth.on("pinRequired", onReceivePinRequiredEvent);
``` ```
## bluetooth.on('bluetoothDeviceFind')<sup>8+</sup> ## bluetooth.on('bluetoothDeviceFind')<sup>8+</sup><sup>(deprecated)</sup><a name="bluetoothDeviceFind"></a>
on(type: "bluetoothDeviceFind", callback: Callback&lt;Array&lt;string&gt;&gt;): void on(type: "bluetoothDeviceFind", callback: Callback&lt;Array&lt;string&gt;&gt;): void
Subscribes to the Bluetooth device discovery events. Subscribes to the Bluetooth device discovery events.
> **NOTE**<br>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.on('bluetoothDeviceFind')](js-apis-bluetoothManager.md#bluetoothmanageronbluetoothdevicefind).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -501,12 +556,15 @@ bluetooth.on('bluetoothDeviceFind', onReceiveEvent); ...@@ -501,12 +556,15 @@ bluetooth.on('bluetoothDeviceFind', onReceiveEvent);
``` ```
## bluetooth.off('bluetoothDeviceFind')<sup>8+</sup> ## bluetooth.off('bluetoothDeviceFind')<sup>8+</sup><sup>(deprecated)</sup>
off(type: "bluetoothDeviceFind", callback?: Callback&lt;Array&lt;string&gt;&gt;): void off(type: "bluetoothDeviceFind", callback?: Callback&lt;Array&lt;string&gt;&gt;): void
Unsubscribes from the Bluetooth device discovery events. Unsubscribes from the Bluetooth device discovery events.
> **NOTE**<br>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.off('bluetoothDeviceFind')](js-apis-bluetoothManager.md#bluetoothmanageroffbluetoothdevicefind).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -533,12 +591,15 @@ bluetooth.off('bluetoothDeviceFind', onReceiveEvent); ...@@ -533,12 +591,15 @@ bluetooth.off('bluetoothDeviceFind', onReceiveEvent);
``` ```
## bluetooth.on('pinRequired')<sup>8+</sup> ## bluetooth.on('pinRequired')<sup>8+</sup><sup>(deprecated)</sup>
on(type: "pinRequired", callback: Callback&lt;PinRequiredParam&gt;): void on(type: "pinRequired", callback: Callback&lt;PinRequiredParam&gt;): void
Subscribes to the pairing request events of the remote Bluetooth device. Subscribes to the pairing request events of the remote Bluetooth device.
> **NOTE**<br>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.on('pinRequired')](js-apis-bluetoothManager.md#bluetoothmanageronpinrequired).
**Required permissions**: ohos.permission.DISCOVER_BLUETOOTH **Required permissions**: ohos.permission.DISCOVER_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -564,12 +625,15 @@ bluetooth.on('pinRequired', onReceiveEvent); ...@@ -564,12 +625,15 @@ bluetooth.on('pinRequired', onReceiveEvent);
``` ```
## bluetooth.off('pinRequired')<sup>8+</sup> ## bluetooth.off('pinRequired')<sup>8+</sup><sup>(deprecated)</sup>
off(type: "pinRequired", callback?: Callback&lt;PinRequiredParam&gt;): void off(type: "pinRequired", callback?: Callback&lt;PinRequiredParam&gt;): void
Unsubscribes from the pairing request events of the remote Bluetooth device. Unsubscribes from the pairing request events of the remote Bluetooth device.
> **NOTE**<br>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.off('pinRequired')](js-apis-bluetoothManager.md#bluetoothmanageroffpinrequired).
**Required permissions**: ohos.permission.DISCOVER_BLUETOOTH **Required permissions**: ohos.permission.DISCOVER_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -596,12 +660,15 @@ bluetooth.off('pinRequired', onReceiveEvent); ...@@ -596,12 +660,15 @@ bluetooth.off('pinRequired', onReceiveEvent);
``` ```
## bluetooth.on('bondStateChange')<sup>8+</sup> ## bluetooth.on('bondStateChange')<sup>8+</sup><sup>(deprecated)</sup>
on(type: "bondStateChange", callback: Callback&lt;BondStateParam&gt;): void on(type: "bondStateChange", callback: Callback&lt;BondStateParam&gt;): void
Subscribes to the Bluetooth pairing state change events. Subscribes to the Bluetooth pairing state change events.
> **NOTE**<br>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.on('bondStateChange')](js-apis-bluetoothManager.md#bluetoothmanageronbondstatechange).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -627,12 +694,15 @@ bluetooth.on('bondStateChange', onReceiveEvent); ...@@ -627,12 +694,15 @@ bluetooth.on('bondStateChange', onReceiveEvent);
``` ```
## bluetooth.off('bondStateChange')<sup>8+</sup> ## bluetooth.off('bondStateChange')<sup>8+</sup><sup>(deprecated)</sup>
off(type: "bondStateChange", callback?: Callback&lt;BondStateParam&gt;): void off(type: "bondStateChange", callback?: Callback&lt;BondStateParam&gt;): void
Unsubscribes from the Bluetooth pairing state change events. Unsubscribes from the Bluetooth pairing state change events.
> **NOTE**<br>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.off('bondStateChange')](js-apis-bluetoothManager.md#bluetoothmanageroffbondstatechange).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -659,12 +729,15 @@ bluetooth.off('bondStateChange', onReceiveEvent); ...@@ -659,12 +729,15 @@ bluetooth.off('bondStateChange', onReceiveEvent);
``` ```
## bluetooth.on('stateChange')<sup>8+</sup> ## bluetooth.on('stateChange')<sup>8+</sup><sup>(deprecated)</sup>
on(type: "stateChange", callback: Callback&lt;BluetoothState&gt;): void on(type: "stateChange", callback: Callback&lt;BluetoothState&gt;): void
Subscribes to the Bluetooth connection state change events. Subscribes to the Bluetooth connection state change events.
> **NOTE**<br>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.on('stateChange')](js-apis-bluetoothManager.md#bluetoothmanageronstatechange).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -690,12 +763,15 @@ bluetooth.on('stateChange', onReceiveEvent); ...@@ -690,12 +763,15 @@ bluetooth.on('stateChange', onReceiveEvent);
``` ```
## bluetooth.off('stateChange')<sup>8+</sup> ## bluetooth.off('stateChange')<sup>8+</sup><sup>(deprecated)</sup>
off(type: "stateChange", callback?: Callback&lt;BluetoothState&gt;): void off(type: "stateChange", callback?: Callback&lt;BluetoothState&gt;): void
Unsubscribes from the Bluetooth connection state change events. Unsubscribes from the Bluetooth connection state change events.
> **NOTE**<br>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.off('stateChange')](js-apis-bluetoothManager.md#bluetoothmanageroffstatechange).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -722,12 +798,15 @@ bluetooth.off('stateChange', onReceiveEvent); ...@@ -722,12 +798,15 @@ bluetooth.off('stateChange', onReceiveEvent);
``` ```
## bluetooth.sppListen<sup>8+</sup><a name="sppListen"></a> ## bluetooth.sppListen<sup>8+</sup><sup>(deprecated)</sup><a name="sppListen"></a>
sppListen(name: string, option: SppOption, callback: AsyncCallback&lt;number&gt;): void sppListen(name: string, option: SppOption, callback: AsyncCallback&lt;number&gt;): void
Creates a server listening socket. Creates a server listening socket.
> **NOTE**<br>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.sppListen](js-apis-bluetoothManager.md#bluetoothmanagerspplisten).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -757,12 +836,15 @@ bluetooth.sppListen('server1', sppOption, serverSocket); ...@@ -757,12 +836,15 @@ bluetooth.sppListen('server1', sppOption, serverSocket);
``` ```
## bluetooth.sppAccept<sup>8+</sup><a name="sppAccept"></a> ## bluetooth.sppAccept<sup>8+</sup><sup>(deprecated)</sup><a name="sppAccept"></a>
sppAccept(serverSocket: number, callback: AsyncCallback&lt;number&gt;): void sppAccept(serverSocket: number, callback: AsyncCallback&lt;number&gt;): void
Listens for a connection to be made to this socket from the client and accepts it. Listens for a connection to be made to this socket from the client and accepts it.
> **NOTE**<br>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.sppAccept](js-apis-bluetoothManager.md#bluetoothmanagersppaccept).
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters** **Parameters**
...@@ -796,12 +878,15 @@ bluetooth.sppAccept(serverNumber, acceptClientSocket); ...@@ -796,12 +878,15 @@ bluetooth.sppAccept(serverNumber, acceptClientSocket);
``` ```
## bluetooth.sppConnect<sup>8+</sup><a name="sppConnect"></a> ## bluetooth.sppConnect<sup>8+</sup><sup>(deprecated)</sup><a name="sppConnect"></a>
sppConnect(device: string, option: SppOption, callback: AsyncCallback&lt;number&gt;): void sppConnect(device: string, option: SppOption, callback: AsyncCallback&lt;number&gt;): void
Initiates an SPP connection to a remote device from the client. Initiates an SPP connection to a remote device from the client.
> **NOTE**<br>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.sppConnect](js-apis-bluetoothManager.md#bluetoothmanagersppconnect).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -832,12 +917,15 @@ bluetooth.sppConnect('XX:XX:XX:XX:XX:XX', sppOption, clientSocket); ...@@ -832,12 +917,15 @@ bluetooth.sppConnect('XX:XX:XX:XX:XX:XX', sppOption, clientSocket);
``` ```
## bluetooth.sppCloseServerSocket<sup>8+</sup><a name="sppCloseServerSocket"></a> ## bluetooth.sppCloseServerSocket<sup>8+</sup><sup>(deprecated)</sup><a name="sppCloseServerSocket"></a>
sppCloseServerSocket(socket: number): void sppCloseServerSocket(socket: number): void
Closes the listening socket of the server. Closes the listening socket of the server.
> **NOTE**<br>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.sppCloseServerSocket](js-apis-bluetoothManager.md#bluetoothmanagersppcloseserversocket).
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters** **Parameters**
...@@ -861,12 +949,15 @@ bluetooth.sppCloseServerSocket(serverNumber); ...@@ -861,12 +949,15 @@ bluetooth.sppCloseServerSocket(serverNumber);
``` ```
## bluetooth.sppCloseClientSocket<sup>8+</sup><a name="sppCloseClientSocket"></a> ## bluetooth.sppCloseClientSocket<sup>8+</sup><sup>(deprecated)</sup><a name="sppCloseClientSocket"></a>
sppCloseClientSocket(socket: number): void sppCloseClientSocket(socket: number): void
Closes the client socket. Closes the client socket.
> **NOTE**<br>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.sppCloseClientSocket](js-apis-bluetoothManager.md#bluetoothmanagersppcloseclientsocket).
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters** **Parameters**
...@@ -892,12 +983,15 @@ bluetooth.sppCloseClientSocket(clientNumber); ...@@ -892,12 +983,15 @@ bluetooth.sppCloseClientSocket(clientNumber);
``` ```
## bluetooth.sppWrite<sup>8+</sup><a name="sppWrite"></a> ## bluetooth.sppWrite<sup>8+</sup><sup>(deprecated)</sup><a name="sppWrite"></a>
sppWrite(clientSocket: number, data: ArrayBuffer): boolean sppWrite(clientSocket: number, data: ArrayBuffer): boolean
Writes data to the remote device through the socket. Writes data to the remote device through the socket.
> **NOTE**<br>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.sppWrite](js-apis-bluetoothManager.md#bluetoothmanagersppwrite).
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters** **Parameters**
...@@ -937,10 +1031,13 @@ if (ret) { ...@@ -937,10 +1031,13 @@ if (ret) {
``` ```
## bluetooth.on('sppRead')<sup>8+</sup> ## bluetooth.on('sppRead')<sup>8+</sup><sup>(deprecated)</sup>
on(type: "sppRead", clientSocket: number, callback: Callback&lt;ArrayBuffer&gt;): void on(type: "sppRead", clientSocket: number, callback: Callback&lt;ArrayBuffer&gt;): void
> **NOTE**<br>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.on('sppRead')](js-apis-bluetoothManager.md#bluetoothmanageronsppread).
Subscribes to the SPP read request events. Subscribes to the SPP read request events.
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -977,12 +1074,15 @@ bluetooth.on('sppRead', clientNumber, dataRead); ...@@ -977,12 +1074,15 @@ bluetooth.on('sppRead', clientNumber, dataRead);
``` ```
## bluetooth.off('sppRead')<sup>8+</sup> ## bluetooth.off('sppRead')<sup>8+</sup><sup>(deprecated)</sup>
off(type: "sppRead", clientSocket: number, callback?: Callback&lt;ArrayBuffer&gt;): void off(type: "sppRead", clientSocket: number, callback?: Callback&lt;ArrayBuffer&gt;): void
Unsubscribes from the SPP read request events. Unsubscribes from the SPP read request events.
> **NOTE**<br>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.off('sppRead')](js-apis-bluetoothManager.md#bluetoothmanageroffsppread).
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters** **Parameters**
...@@ -1013,12 +1113,15 @@ bluetooth.off('sppRead', clientNumber); ...@@ -1013,12 +1113,15 @@ bluetooth.off('sppRead', clientNumber);
``` ```
## bluetooth.getProfile<sup>8+</sup><a name="bt-getProfile"></a> ## bluetooth.getProfile<sup>8+</sup><sup>(deprecated)</sup><a name="bt-getProfile"></a>
getProfile(profileId: ProfileId): A2dpSourceProfile | HandsFreeAudioGatewayProfile getProfile(profileId: ProfileId): A2dpSourceProfile | HandsFreeAudioGatewayProfile
Obtains a profile object. Obtains a profile object.
> **NOTE**<br>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.getProfileInstance](js-apis-bluetoothManager.md#bluetoothmanagergetprofileinstance).
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters** **Parameters**
...@@ -1039,41 +1142,18 @@ Obtains a profile object. ...@@ -1039,41 +1142,18 @@ Obtains a profile object.
let a2dpSrc = bluetooth.getProfile(bluetooth.ProfileId.PROFILE_A2DP_SOURCE); let a2dpSrc = bluetooth.getProfile(bluetooth.ProfileId.PROFILE_A2DP_SOURCE);
``` ```
## bluetooth.getProfileInst<sup>9+</sup><a name="getProfileInst"></a>
getProfileInst(profileId: ProfileId): A2dpSourceProfile | HandsFreeAudioGatewayProfile | HidHostProfile | PanProfile
Obtains a profile instance. API version 9 is added with **HidHostProfile** and **PanProfile**.
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| --------- | --------- | ---- | ------------------------------------- |
| profileId | [ProfileId](#ProfileId) | Yes | ID of the profile to obtain, for example, **PROFILE_A2DP_SOURCE**.|
**Return value**
| Type | Description |
| ------------------------------------------------------------ | ------------------------------------------------------------ |
| [A2dpSourceProfile](#a2dpsourceprofile), [HandsFreeAudioGatewayProfile](#handsfreeaudiogatewayprofile), [HidHostProfile](#hidhostprofile), or [PanProfile](#panprofile)| Profile instance obtained, which can be **A2dpSourceProfile**, **HandsFreeAudioGatewayProfile**, **HidHostProfile**, or **PanProfile**.|
**Example**
```js
let hidHost = bluetooth.getProfileInst(bluetooth.ProfileId.PROFILE_HID_HOST);
```
## bluetooth.BLE ## bluetooth.BLE
### bluetooth.BLE.createGattServer ### bluetooth.BLE.createGattServer<sup>(deprecated)</sup>
createGattServer(): GattServer createGattServer(): GattServer
Creates a **GattServer** instance. Creates a **GattServer** instance.
> **NOTE**<br>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.BLE.createGattServer](js-apis-bluetoothManager.md#bluetoothmanagerblecreategattserver).
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
**Return value** **Return value**
...@@ -1089,12 +1169,15 @@ let gattServer = bluetooth.BLE.createGattServer(); ...@@ -1089,12 +1169,15 @@ let gattServer = bluetooth.BLE.createGattServer();
``` ```
### bluetooth.BLE.createGattClientDevice ### bluetooth.BLE.createGattClientDevice<sup>(deprecated)</sup>
createGattClientDevice(deviceId: string): GattClientDevice createGattClientDevice(deviceId: string): GattClientDevice
Creates a **GattClientDevice** instance. Creates a **GattClientDevice** instance.
> **NOTE**<br>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.BLE.createGattClientDevice](js-apis-bluetoothManager.md#bluetoothmanagerblecreategattclientdevice).
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters** **Parameters**
...@@ -1116,12 +1199,15 @@ let device = bluetooth.BLE.createGattClientDevice('XX:XX:XX:XX:XX:XX'); ...@@ -1116,12 +1199,15 @@ let device = bluetooth.BLE.createGattClientDevice('XX:XX:XX:XX:XX:XX');
``` ```
### bluetooth.BLE.getConnectedBLEDevices ### bluetooth.BLE.getConnectedBLEDevices<sup>(deprecated)</sup>
getConnectedBLEDevices(): Array&lt;string&gt; getConnectedBLEDevices(): Array&lt;string&gt;
Obtains the BLE devices connected to this device. Obtains the BLE devices connected to this device.
> **NOTE**<br>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.BLE.getConnectedBLEDevices](js-apis-bluetoothManager.md#bluetoothmanagerblegetconnectedbledevices).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -1139,12 +1225,15 @@ let result = bluetooth.BLE.getConnectedBLEDevices(); ...@@ -1139,12 +1225,15 @@ let result = bluetooth.BLE.getConnectedBLEDevices();
``` ```
### bluetooth.BLE.startBLEScan ### bluetooth.BLE.startBLEScan<sup>(deprecated)</sup>
startBLEScan(filters: Array&lt;ScanFilter&gt;, options?: ScanOptions): void startBLEScan(filters: Array&lt;ScanFilter&gt;, options?: ScanOptions): void
Starts a BLE scan. Starts a BLE scan.
> **NOTE**<br>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.BLE.startBLEScan](js-apis-bluetoothManager.md#bluetoothmanagerblestartblescan).
**Required permissions**: ohos.permission.DISCOVER_BLUETOOTH, ohos.permission.MANAGE_BLUETOOTH, and ohos.permission.LOCATION **Required permissions**: ohos.permission.DISCOVER_BLUETOOTH, ohos.permission.MANAGE_BLUETOOTH, and ohos.permission.LOCATION
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -1182,12 +1271,15 @@ bluetooth.BLE.startBLEScan( ...@@ -1182,12 +1271,15 @@ bluetooth.BLE.startBLEScan(
``` ```
### bluetooth.BLE.stopBLEScan ### bluetooth.BLE.stopBLEScan<sup>(deprecated)</sup>
stopBLEScan(): void stopBLEScan(): void
Stops the BLE scan. Stops the BLE scan.
> **NOTE**<br>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.BLE.stopBLEScan](js-apis-bluetoothManager.md#bluetoothmanagerblestopblescan).
**Required permissions**: ohos.permission.DISCOVER_BLUETOOTH **Required permissions**: ohos.permission.DISCOVER_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -1203,12 +1295,15 @@ bluetooth.BLE.stopBLEScan(); ...@@ -1203,12 +1295,15 @@ bluetooth.BLE.stopBLEScan();
``` ```
### bluetooth.BLE.on('BLEDeviceFind') ### bluetooth.BLE.on('BLEDeviceFind')<sup>(deprecated)</sup>
on(type: "BLEDeviceFind", callback: Callback&lt;Array&lt;ScanResult&gt;&gt;): void on(type: "BLEDeviceFind", callback: Callback&lt;Array&lt;ScanResult&gt;&gt;): void
Subscribe to the BLE device discovery events. Subscribe to the BLE device discovery events.
> **NOTE**<br>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.BLE.on('BLEDeviceFind')](js-apis-bluetoothManager.md#bluetoothmanagerbleonbledevicefind).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -1234,12 +1329,15 @@ bluetooth.BLE.on('BLEDeviceFind', onReceiveEvent); ...@@ -1234,12 +1329,15 @@ bluetooth.BLE.on('BLEDeviceFind', onReceiveEvent);
``` ```
### bluetooth.BLE.off('BLEDeviceFind') ### bluetooth.BLE.off('BLEDeviceFind')<sup>(deprecated)</sup>
off(type: "BLEDeviceFind", callback?: Callback&lt;Array&lt;ScanResult&gt;&gt;): void off(type: "BLEDeviceFind", callback?: Callback&lt;Array&lt;ScanResult&gt;&gt;): void
Unsubscribes from the BLE device discovery events. Unsubscribes from the BLE device discovery events.
> **NOTE**<br>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.BLE.off('BLEDeviceFind')](js-apis-bluetoothManager.md#bluetoothmanagerbleoffbledevicefind).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -1271,12 +1369,15 @@ bluetooth.BLE.off('BLEDeviceFind', onReceiveEvent); ...@@ -1271,12 +1369,15 @@ bluetooth.BLE.off('BLEDeviceFind', onReceiveEvent);
Provides the profile base class. Provides the profile base class.
### getConnectionDevices<sup>8+</sup><a name="getConnectionDevices"></a> ### getConnectionDevices<sup>8+</sup><sup>(deprecated)</sup><a name="getConnectionDevices"></a>
getConnectionDevices(): Array&lt;string&gt; getConnectionDevices(): Array&lt;string&gt;
Obtains the connected devices. Obtains the connected devices.
> **NOTE**<br>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.BaseProfile.getConnectionDevices](js-apis-bluetoothManager.md#getconnectiondevices).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -1294,12 +1395,15 @@ let a2dpSrc = bluetooth.getProfile(bluetooth.ProfileId.PROFILE_A2DP_SOURCE) as b ...@@ -1294,12 +1395,15 @@ let a2dpSrc = bluetooth.getProfile(bluetooth.ProfileId.PROFILE_A2DP_SOURCE) as b
let retArray = a2dpSrc.getConnectionDevices(); let retArray = a2dpSrc.getConnectionDevices();
``` ```
### getDeviceState<sup>8+</sup><a name="getDeviceState"></a> ### getDeviceState<sup>8+</sup><sup>(deprecated)</sup><a name="getDeviceState"></a>
getDeviceState(device: string): ProfileConnectionState getDeviceState(device: string): ProfileConnectionState
Obtains the connection state of the profile. Obtains the connection state of the profile.
> **NOTE**<br>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.BaseProfile.getDeviceState](js-apis-bluetoothManager.md#getdevicestate).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -1328,12 +1432,15 @@ let ret = a2dpSrc.getDeviceState('XX:XX:XX:XX:XX:XX'); ...@@ -1328,12 +1432,15 @@ let ret = a2dpSrc.getDeviceState('XX:XX:XX:XX:XX:XX');
Before using a method of **A2dpSourceProfile**, you need to create an instance of this class by using the **getProfile()** method. Before using a method of **A2dpSourceProfile**, you need to create an instance of this class by using the **getProfile()** method.
### connect<sup>8+</sup><a name="a2dp-connect"></a> ### connect<sup>8+</sup><sup>(deprecated)</sup><a name="a2dp-connect"></a>
connect(device: string): boolean connect(device: string): boolean
Sets up an Advanced Audio Distribution Profile (A2DP) connection. Sets up an Advanced Audio Distribution Profile (A2DP) connection.
> **NOTE**<br>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.A2dpSourceProfile.connect](js-apis-bluetoothManager.md#connect).
**Required permissions**: ohos.permission.DISCOVER_BLUETOOTH **Required permissions**: ohos.permission.DISCOVER_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -1358,12 +1465,15 @@ let ret = a2dpSrc.connect('XX:XX:XX:XX:XX:XX'); ...@@ -1358,12 +1465,15 @@ let ret = a2dpSrc.connect('XX:XX:XX:XX:XX:XX');
``` ```
### disconnect<sup>8+</sup><a name="a2dp-disconnect"></a> ### disconnect<sup>8+</sup><sup>(deprecated)</sup><a name="a2dp-disconnect"></a>
disconnect(device: string): boolean disconnect(device: string): boolean
Disconnects an A2DP connection. Disconnects an A2DP connection.
> **NOTE**<br>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.A2dpSourceProfile.disconnect](js-apis-bluetoothManager.md#disconnect).
**Required permissions**: ohos.permission.DISCOVER_BLUETOOTH **Required permissions**: ohos.permission.DISCOVER_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -1388,12 +1498,15 @@ let ret = a2dpSrc.disconnect('XX:XX:XX:XX:XX:XX'); ...@@ -1388,12 +1498,15 @@ let ret = a2dpSrc.disconnect('XX:XX:XX:XX:XX:XX');
``` ```
### on('connectionStateChange')<sup>8+</sup> ### on('connectionStateChange')<sup>8+</sup><sup>(deprecated)</sup>
on(type: "connectionStateChange", callback: Callback&lt;[StateChangeParam](#StateChangeParam)&gt;): void on(type: "connectionStateChange", callback: Callback&lt;[StateChangeParam](#StateChangeParam)&gt;): void
Subscribes to the A2DP connection state change events. Subscribes to the A2DP connection state change events.
> **NOTE**<br>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.A2dpSourceProfile.on('connectionStateChange')](js-apis-bluetoothManager.md#onconnectionstatechange).
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters** **Parameters**
...@@ -1418,12 +1531,15 @@ a2dpSrc.on('connectionStateChange', onReceiveEvent); ...@@ -1418,12 +1531,15 @@ a2dpSrc.on('connectionStateChange', onReceiveEvent);
``` ```
### off('connectionStateChange')<sup>8+</sup> ### off('connectionStateChange')<sup>8+</sup><sup>(deprecated)</sup>
off(type: "connectionStateChange", callback?: Callback&lt;[StateChangeParam](#StateChangeParam)&gt;): void off(type: "connectionStateChange", callback?: Callback&lt;[StateChangeParam](#StateChangeParam)&gt;): void
Unsubscribes from the A2DP connection state change events. Unsubscribes from the A2DP connection state change events.
> **NOTE**<br>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.A2dpSourceProfile.off('connectionStateChange')](js-apis-bluetoothManager.md#offconnectionstatechange).
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters** **Parameters**
...@@ -1431,7 +1547,7 @@ Unsubscribes from the A2DP connection state change events. ...@@ -1431,7 +1547,7 @@ Unsubscribes from the A2DP connection state change events.
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- | | -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type | string | Yes | Event type. The value **connectionStateChange** indicates an A2DP connection state change event.| | type | string | Yes | Event type. The value **connectionStateChange** indicates an A2DP connection state change event.|
| callback | Callback&lt;[StateChangeParam](#StateChangeParam)&gt; | No | Callback used to return the A2DP connection state change event. | | callback | Callback&lt;[StateChangeParam](#StateChangeParam)&gt; | No | Callback for the A2DP connection state change event. |
**Return value** **Return value**
...@@ -1449,12 +1565,15 @@ a2dpSrc.off('connectionStateChange', onReceiveEvent); ...@@ -1449,12 +1565,15 @@ a2dpSrc.off('connectionStateChange', onReceiveEvent);
``` ```
### getPlayingState<sup>8+</sup> ### getPlayingState<sup>8+</sup><sup>(deprecated)</sup>
getPlayingState(device: string): PlayingState getPlayingState(device: string): PlayingState
Obtains the playing state of a device. Obtains the playing state of a device.
> **NOTE**<br>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.A2dpSourceProfile.getPlayingState](js-apis-bluetoothManager.md#getplayingstate).
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters** **Parameters**
...@@ -1482,12 +1601,15 @@ let state = a2dpSrc.getPlayingState('XX:XX:XX:XX:XX:XX'); ...@@ -1482,12 +1601,15 @@ let state = a2dpSrc.getPlayingState('XX:XX:XX:XX:XX:XX');
Before using a method of **HandsFreeAudioGatewayProfile**, you need to create an instance of this class by using the **getProfile()** method. Before using a method of **HandsFreeAudioGatewayProfile**, you need to create an instance of this class by using the **getProfile()** method.
### connect<sup>8+</sup><a name="hfp-connect"></a> ### connect<sup>8+</sup><sup>(deprecated)</sup><a name="hfp-connect"></a>
connect(device: string): boolean connect(device: string): boolean
Sets up a Hands-free Profile (HFP) connection of a device. Sets up a Hands-free Profile (HFP) connection of a device.
> **NOTE**<br>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.HandsFreeAudioGatewayProfile.connect](js-apis-bluetoothManager.md#connect-1).
**Required permissions**: ohos.permission.DISCOVER_BLUETOOTH **Required permissions**: ohos.permission.DISCOVER_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -1513,12 +1635,15 @@ let ret = hfpAg.connect('XX:XX:XX:XX:XX:XX'); ...@@ -1513,12 +1635,15 @@ let ret = hfpAg.connect('XX:XX:XX:XX:XX:XX');
``` ```
### disconnect<sup>8+</sup><a name="hfp-disconnect"></a> ### disconnect<sup>8+</sup><sup>(deprecated)</sup><a name="hfp-disconnect"></a>
disconnect(device: string): boolean disconnect(device: string): boolean
Disconnects the HFP connection of a device. Disconnects the HFP connection of a device.
> **NOTE**<br>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.HandsFreeAudioGatewayProfile.disconnect](js-apis-bluetoothManager.md#disconnect-1).
**Required permissions**: ohos.permission.DISCOVER_BLUETOOTH **Required permissions**: ohos.permission.DISCOVER_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -1544,12 +1669,15 @@ let ret = hfpAg.disconnect('XX:XX:XX:XX:XX:XX'); ...@@ -1544,12 +1669,15 @@ let ret = hfpAg.disconnect('XX:XX:XX:XX:XX:XX');
``` ```
### on('connectionStateChange')<sup>8+</sup> ### on('connectionStateChange')<sup>8+</sup><sup>(deprecated)</sup>
on(type: "connectionStateChange", callback: Callback&lt;[StateChangeParam](#StateChangeParam)&gt;): void on(type: "connectionStateChange", callback: Callback&lt;[StateChangeParam](#StateChangeParam)&gt;): void
Subscribes to the HFP connection state change events. Subscribes to the HFP connection state change events.
> **NOTE**<br>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.HandsFreeAudioGatewayProfile.on('connectionStateChange')](js-apis-bluetoothManager.md#onconnectionstatechange-1).
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters** **Parameters**
...@@ -1575,12 +1703,15 @@ hfpAg.on('connectionStateChange', onReceiveEvent); ...@@ -1575,12 +1703,15 @@ hfpAg.on('connectionStateChange', onReceiveEvent);
``` ```
### off('connectionStateChange')<sup>8+</sup> ### off('connectionStateChange')<sup>8+</sup><sup>(deprecated)</sup>
off(type: "connectionStateChange", callback?: Callback&lt;[StateChangeParam](#StateChangeParam)&gt;): void off(type: "connectionStateChange", callback?: Callback&lt;[StateChangeParam](#StateChangeParam)&gt;): void
Unsubscribes from the HFP connection state change events. Unsubscribes from the HFP connection state change events.
> **NOTE**<br>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.HandsFreeAudioGatewayProfile.off('connectionStateChange')](js-apis-bluetoothManager.md#offconnectionstatechange-1).
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters** **Parameters**
...@@ -1607,301 +1738,20 @@ hfpAg.off('connectionStateChange', onReceiveEvent); ...@@ -1607,301 +1738,20 @@ hfpAg.off('connectionStateChange', onReceiveEvent);
``` ```
## HidHostProfile
Before using a method of **HidHostProfile**, you need to create an instance of this class by using the **getProfile()** method.
### connect<sup>9+</sup><a name="HidHost-connect"></a>
connect(device: string): boolean
Connects to the HidHost service of a device.
**System API**: This is a system API.
**Required permissions**: ohos.permission.DISCOVER_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | ------- |
| device | string | Yes | Address of the target device.|
**Return value**
| Type | Description |
| --------------------- | --------------------------------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
**Example**
```js
let hidHostProfile = bluetooth.getProfileInst(bluetooth.ProfileId.PROFILE_HID_HOST) as bluetooth.HidHostProfile;
let ret = hidHostProfile.connect('XX:XX:XX:XX:XX:XX');
```
### disconnect<sup>9+</sup><a name="HidHost-disconnect"></a>
disconnect(device: string): boolean
Disconnects from the HidHost service of a device.
**System API**: This is a system API.
**Required permissions**: ohos.permission.DISCOVER_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | ------- |
| device | string | Yes | Address of the target device.|
**Return value**
| Type | Description |
| --------------------- | --------------------------------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
**Example**
```js
let hidHostProfile = bluetooth.getProfileInst(bluetooth.ProfileId.PROFILE_HID_HOST) as bluetooth.HidHostProfile;
let ret = hidHostProfile.disconnect('XX:XX:XX:XX:XX:XX');
```
### on('connectionStateChange')<sup>9+</sup>
on(type: "connectionStateChange", callback: Callback&lt;[StateChangeParam](#StateChangeParam)&gt;): void
Subscribes to the HidHost connection state change events.
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type | string | Yes | Event type. The value **connectionStateChange** indicates a HidHost connection state change event.|
| callback | Callback&lt;[StateChangeParam](#StateChangeParam)&gt; | Yes | Callback invoked to return the HidHost connection state change event. |
**Return value**
No value is returned.
**Example**
```js
function onReceiveEvent(data) {
console.info('hidHost state = '+ JSON.stringify(data));
}
let hidHost = bluetooth.getProfileInst(bluetooth.ProfileId.PROFILE_HID_HOST) as bluetooth.HidHostProfile;
hidHost.on('connectionStateChange', onReceiveEvent);
```
### off('connectionStateChange')<sup>9+</sup>
off(type: "connectionStateChange", callback?: Callback&lt;[StateChangeParam](#StateChangeParam)&gt;): void
Unsubscribes from the HidHost connection state change events.
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------------------------------------- | ---- | --------------------------------------------------------- |
| type | string | Yes | Event type. The value **connectionStateChange** indicates a HidHost connection state change event.|
| callback | Callback&lt;[StateChangeParam](#StateChangeParam)&gt; | No | Callback for the HidHost connection state change event. |
**Return value**
No value is returned.
**Example**
```js
function onReceiveEvent(data) {
console.info('hidHost state = '+ JSON.stringify(data));
}
let hidHost = bluetooth.getProfileInst(bluetooth.ProfileId.PROFILE_HID_HOST) as bluetooth.HidHostProfile;
hidHost.on('connectionStateChange', onReceiveEvent);
hidHost.off('connectionStateChange', onReceiveEvent);
```
## PanProfile
Before using a method of **PanProfile**, you need to create an instance of this class by using the **getProfile()** method.
### disconnect<sup>9+</sup><a name="PanP-disconnect"></a>
disconnect(device: string): boolean
Disconnects from the Personal Area Network (PAN) service of a device.
**System API**: This is a system API.
**Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | ------- |
| device | string | Yes | Address of the target device.|
**Return value**
| Type | Description |
| --------------------- | --------------------------------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
**Example**
```js
let panProfile = bluetooth.getProfileInst(bluetooth.ProfileId.PROFILE_PAN_NETWORK) as bluetooth.PanProfile;
let ret = panProfile.disconnect('XX:XX:XX:XX:XX:XX');
```
### on('connectionStateChange')<sup>9+</sup>
on(type: "connectionStateChange", callback: Callback&lt;[StateChangeParam](#StateChangeParam)&gt;): void
Subscribes to the PAN connection state change events.
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type | string | Yes | Event type. The value **connectionStateChange** indicates a PAN connection state change event.|
| callback | Callback&lt;[StateChangeParam](#StateChangeParam)&gt; | Yes | Callback invoked to return the PAN connection state change event. |
**Return value**
No value is returned.
**Example**
```js
function onReceiveEvent(data) {
console.info('pan state = '+ JSON.stringify(data));
}
let panProfile = bluetooth.getProfileInst(bluetooth.ProfileId.PROFILE_PAN_NETWORK) as bluetooth.PanProfile;
panProfile.on('connectionStateChange', onReceiveEvent);
```
### off('connectionStateChange')<sup>9+</sup>
off(type: "connectionStateChange", callback?: Callback&lt;[StateChangeParam](#StateChangeParam)&gt;): void
Unsubscribes from the PAN connection state change events.
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------------------------------------- | ---- | --------------------------------------------------------- |
| type | string | Yes | Event type. The value **connectionStateChange** indicates a PAN connection state change event.|
| callback | Callback&lt;[StateChangeParam](#StateChangeParam)&gt; | No | Callback for the PAN connection state change event. |
**Return value**
No value is returned.
**Example**
```js
function onReceiveEvent(data) {
console.info('pan state = '+ JSON.stringify(data));
}
let panProfile = bluetooth.getProfileInst(bluetooth.ProfileId.PROFILE_PAN_NETWORK) as bluetooth.PanProfile;
panProfile.on('connectionStateChange', onReceiveEvent);
panProfile.off('connectionStateChange', onReceiveEvent);
```
### setTethering<sup>9+</sup><a name="setTethering"></a>
setTethering(enable: boolean): void
Sets tethering.
**System API**: This is a system API.
**Required permissions**: ohos.permission.DISCOVER_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | ------- |
| value | boolean | Yes | Whether to set tethering over a Bluetooth PAN.|
**Return value**
| Type | Description |
| --------------------- | --------------------------------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
**Example**
```js
let panProfile = bluetooth.getProfileInst(bluetooth.ProfileId.PROFILE_PAN_NETWORK) as bluetooth.PanProfile;
let ret = panProfile.setTethering(true);
```
### isTetheringOn<sup>9+</sup><a name="isTetheringOn"></a>
isTetheringOn(): boolean
Obtains the tethering state.
**System API**: This is a system API.
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Return value**
| Type | Description |
| --------------------- | --------------------------------- |
| boolean | Returns **true** if tethering is available over a Bluetooth PAN; return **false** otherwise.|
**Example**
```js
let panProfile = bluetooth.getProfileInst(bluetooth.ProfileId.PROFILE_PAN_NETWORK) as bluetooth.PanProfile;
let ret = panProfile.isTetheringOn();
```
## GattServer ## GattServer
Implements the Generic Attribute Profile (GATT) server. Before using a method of this class, you need to create a **GattServer** instance using the **createGattServer()** method. Implements the Generic Attribute Profile (GATT) server. Before using a method of this class, you need to create a **GattServer** instance using the **createGattServer()** method.
### startAdvertising ### startAdvertising<sup>(deprecated)</sup>
startAdvertising(setting: AdvertiseSetting, advData: AdvertiseData, advResponse?: AdvertiseData): void startAdvertising(setting: AdvertiseSetting, advData: AdvertiseData, advResponse?: AdvertiseData): void
Starts BLE advertising. Starts BLE advertising.
> **NOTE**<br>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.GattServer.startAdvertising](js-apis-bluetoothManager.md#startadvertising).
**Required permissions**: ohos.permission.DISCOVER_BLUETOOTH **Required permissions**: ohos.permission.DISCOVER_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -1963,12 +1813,15 @@ gattServer.startAdvertising({ ...@@ -1963,12 +1813,15 @@ gattServer.startAdvertising({
``` ```
### stopAdvertising ### stopAdvertising<sup>(deprecated)</sup>
stopAdvertising(): void stopAdvertising(): void
Stops BLE advertising. Stops BLE advertising.
> **NOTE**<br>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.GattServer.stopAdvertising](js-apis-bluetoothManager.md#stopadvertising).
**Required permissions**: ohos.permission.DISCOVER_BLUETOOTH **Required permissions**: ohos.permission.DISCOVER_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -1985,12 +1838,15 @@ server.stopAdvertising(); ...@@ -1985,12 +1838,15 @@ server.stopAdvertising();
``` ```
### addService ### addService<sup>(deprecated)</sup>
addService(service: GattService): boolean addService(service: GattService): boolean
Adds a service to this GATT server. Adds a service to this GATT server.
> **NOTE**<br>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.GattServer.addService](js-apis-bluetoothManager.md#addservice).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -2044,12 +1900,15 @@ if (ret) { ...@@ -2044,12 +1900,15 @@ if (ret) {
``` ```
### removeService ### removeService<sup>(deprecated)</sup>
removeService(serviceUuid: string): boolean removeService(serviceUuid: string): boolean
Removes a service from this GATT server. Removes a service from this GATT server.
> **NOTE**<br>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.GattServer.removeService](js-apis-bluetoothManager.md#removeservice).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -2074,12 +1933,15 @@ server.removeService('00001810-0000-1000-8000-00805F9B34FB'); ...@@ -2074,12 +1933,15 @@ server.removeService('00001810-0000-1000-8000-00805F9B34FB');
``` ```
### close ### close<sup>(deprecated)</sup>
close(): void close(): void
Closes this GATT server to unregister it from the protocol stack. After this method is called, this [GattServer](#gattserver) cannot be used. Closes this GATT server to unregister it from the protocol stack. After this method is called, this [GattServer](#gattserver) cannot be used.
> **NOTE**<br>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.GattServer.close](js-apis-bluetoothManager.md#close).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -2092,12 +1954,15 @@ server.close(); ...@@ -2092,12 +1954,15 @@ server.close();
``` ```
### notifyCharacteristicChanged ### notifyCharacteristicChanged<sup>(deprecated)</sup>
notifyCharacteristicChanged(deviceId: string, notifyCharacteristic: NotifyCharacteristic): boolean notifyCharacteristicChanged(deviceId: string, notifyCharacteristic: NotifyCharacteristic): boolean
Notifies the connected client device when a characteristic value changes. Notifies the connected client device when a characteristic value changes.
> **NOTE**<br>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.GattServer.notifyCharacteristicChanged](js-apis-bluetoothManager.md#notifycharacteristicchanged).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -2137,12 +2002,15 @@ server.notifyCharacteristicChanged('XX:XX:XX:XX:XX:XX', notifyCharacteristic); ...@@ -2137,12 +2002,15 @@ server.notifyCharacteristicChanged('XX:XX:XX:XX:XX:XX', notifyCharacteristic);
``` ```
### sendResponse ### sendResponse<sup>(deprecated)</sup>
sendResponse(serverResponse: ServerResponse): boolean sendResponse(serverResponse: ServerResponse): boolean
Sends a response to a read or write request from the GATT client. Sends a response to a read or write request from the GATT client.
> **NOTE**<br>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.GattServer.sendResponse](js-apis-bluetoothManager.md#sendresponse).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -2184,12 +2052,15 @@ if (ret) { ...@@ -2184,12 +2052,15 @@ if (ret) {
``` ```
### on('characteristicRead') ### on('characteristicRead')<sup>(deprecated)</sup>
on(type: "characteristicRead", callback: Callback&lt;CharacteristicReadReq&gt;): void on(type: "characteristicRead", callback: Callback&lt;CharacteristicReadReq&gt;): void
Subscribes to the characteristic read request events. Subscribes to the characteristic read request events.
> **NOTE**<br>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.GattServer.on('characteristicRead')](js-apis-bluetoothManager.md#oncharacteristicread).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -2232,12 +2103,15 @@ gattServer.on("characteristicRead", ReadCharacteristicReq); ...@@ -2232,12 +2103,15 @@ gattServer.on("characteristicRead", ReadCharacteristicReq);
``` ```
### off('characteristicRead') ### off('characteristicRead')<sup>(deprecated)</sup>
off(type: "characteristicRead", callback?: Callback&lt;CharacteristicReadReq&gt;): void off(type: "characteristicRead", callback?: Callback&lt;CharacteristicReadReq&gt;): void
Unsubscribes from the characteristic read request events. Unsubscribes from the characteristic read request events.
> **NOTE**<br>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.GattServer.off('characteristicRead')](js-apis-bluetoothManager.md#offcharacteristicread).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -2261,12 +2135,15 @@ gattServer.off("characteristicRead"); ...@@ -2261,12 +2135,15 @@ gattServer.off("characteristicRead");
``` ```
### on('characteristicWrite') ### on('characteristicWrite')<sup>(deprecated)</sup>
on(type: "characteristicWrite", callback: Callback&lt;CharacteristicWriteReq&gt;): void on(type: "characteristicWrite", callback: Callback&lt;CharacteristicWriteReq&gt;): void
Subscribes to the characteristic write request events. Subscribes to the characteristic write request events.
> **NOTE**<br>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.GattServer.on('characteristicWrite')](js-apis-bluetoothManager.md#oncharacteristicwrite).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -2312,12 +2189,15 @@ gattServer.on("characteristicWrite", WriteCharacteristicReq); ...@@ -2312,12 +2189,15 @@ gattServer.on("characteristicWrite", WriteCharacteristicReq);
``` ```
### off('characteristicWrite') ### off('characteristicWrite')<sup>(deprecated)</sup>
off(type: "characteristicWrite", callback?: Callback&lt;CharacteristicWriteReq&gt;): void off(type: "characteristicWrite", callback?: Callback&lt;CharacteristicWriteReq&gt;): void
Unsubscribes from the characteristic write request events. Unsubscribes from the characteristic write request events.
> **NOTE**<br>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.GattServer.off('characteristicWrite')](js-apis-bluetoothManager.md#offcharacteristicwrite).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -2341,12 +2221,15 @@ gattServer.off("characteristicWrite"); ...@@ -2341,12 +2221,15 @@ gattServer.off("characteristicWrite");
``` ```
### on('descriptorRead') ### on('descriptorRead')<sup>(deprecated)</sup>
on(type: "descriptorRead", callback: Callback&lt;DescriptorReadReq&gt;): void on(type: "descriptorRead", callback: Callback&lt;DescriptorReadReq&gt;): void
Subscribes to the descriptor read request events. Subscribes to the descriptor read request events.
> **NOTE**<br>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.GattServer.on('descriptorRead')](js-apis-bluetoothManager.md#ondescriptorread).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -2389,12 +2272,15 @@ gattServer.on("descriptorRead", ReadDescriptorReq); ...@@ -2389,12 +2272,15 @@ gattServer.on("descriptorRead", ReadDescriptorReq);
``` ```
### off('descriptorRead') ### off('descriptorRead')<sup>(deprecated)</sup>
off(type: "descriptorRead", callback?: Callback&lt;DescriptorReadReq&gt;): void off(type: "descriptorRead", callback?: Callback&lt;DescriptorReadReq&gt;): void
Unsubscribes from the descriptor read request events. Unsubscribes from the descriptor read request events.
> **NOTE**<br>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.GattServer.off('descriptorRead')](js-apis-bluetoothManager.md#offdescriptorread).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -2418,12 +2304,15 @@ gattServer.off("descriptorRead"); ...@@ -2418,12 +2304,15 @@ gattServer.off("descriptorRead");
``` ```
### on('descriptorWrite') ### on('descriptorWrite')<sup>(deprecated)</sup>
on(type: "descriptorWrite", callback: Callback&lt;DescriptorWriteReq&gt;): void on(type: "descriptorWrite", callback: Callback&lt;DescriptorWriteReq&gt;): void
Subscribes to the descriptor write request events. Subscribes to the descriptor write request events.
> **NOTE**<br>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.GattServer.on('descriptorWrite')](js-apis-bluetoothManager.md#ondescriptorwrite).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -2469,12 +2358,15 @@ gattServer.on("descriptorRead", WriteDescriptorReq); ...@@ -2469,12 +2358,15 @@ gattServer.on("descriptorRead", WriteDescriptorReq);
``` ```
### off('descriptorWrite') ### off('descriptorWrite')<sup>(deprecated)</sup>
off(type: "descriptorWrite", callback?: Callback&lt;DescriptorWriteReq&gt;): void off(type: "descriptorWrite", callback?: Callback&lt;DescriptorWriteReq&gt;): void
Unsubscribes from the descriptor write request events. Unsubscribes from the descriptor write request events.
> **NOTE**<br>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.GattServer.off('descriptorWrite')](js-apis-bluetoothManager.md#offdescriptorwrite).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -2498,12 +2390,15 @@ gattServer.off("descriptorWrite"); ...@@ -2498,12 +2390,15 @@ gattServer.off("descriptorWrite");
``` ```
### on('connectStateChange') ### on('connectStateChange')<sup>(deprecated)</sup>
on(type: "connectStateChange", callback: Callback&lt;BLEConnectChangedState&gt;): void on(type: "connectStateChange", callback: Callback&lt;BLEConnectChangedState&gt;): void
Subscribes to the BLE connection state change events. Subscribes to the BLE connection state change events.
> **NOTE**<br>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.GattServer.on('connectStateChange')](js-apis-bluetoothManager.md#onconnectstatechange).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -2532,12 +2427,15 @@ gattServer.on("connectStateChange", Connected); ...@@ -2532,12 +2427,15 @@ gattServer.on("connectStateChange", Connected);
``` ```
### off('connectStateChange') ### off('connectStateChange')<sup>(deprecated)</sup>
off(type: "connectStateChange", callback?: Callback&lt;BLEConnectChangedState&gt;): void off(type: "connectStateChange", callback?: Callback&lt;BLEConnectChangedState&gt;): void
Unsubscribes from the BLE connection state change events. Unsubscribes from the BLE connection state change events.
> **NOTE**<br>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.GattServer.off('connectStateChange')](js-apis-bluetoothManager.md#offconnectstatechange).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -2566,12 +2464,15 @@ gattServer.off("connectStateChange"); ...@@ -2566,12 +2464,15 @@ gattServer.off("connectStateChange");
Implements the GATT client. Before using a method of this class, you must create a **GattClientDevice** instance using the **createGattClientDevice(deviceId: string)** method. Implements the GATT client. Before using a method of this class, you must create a **GattClientDevice** instance using the **createGattClientDevice(deviceId: string)** method.
### connect ### connect<sup>(deprecated)</sup>
connect(): boolean connect(): boolean
Initiates a connection to the remote BLE device. Initiates a connection to the remote BLE device.
> **NOTE**<br>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.GattClientDevice.connect](js-apis-bluetoothManager.md#connect-3).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -2590,12 +2491,15 @@ let ret = device.connect(); ...@@ -2590,12 +2491,15 @@ let ret = device.connect();
``` ```
### disconnect ### disconnect<sup>(deprecated)</sup>
disconnect(): boolean disconnect(): boolean
Disconnects from the remote BLE device. Disconnects from the remote BLE device.
> **NOTE**<br>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.GattClientDevice.disconnect](js-apis-bluetoothManager.md#disconnect-4).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -2614,12 +2518,15 @@ let ret = device.disconnect(); ...@@ -2614,12 +2518,15 @@ let ret = device.disconnect();
``` ```
### close ### close<sup>(deprecated)</sup>
close(): boolean close(): boolean
Closes this GATT client to unregister it from the protocol stack. After this method is called, this [GattClientDevice](#gattclientdevice) instance cannot be used. Closes this GATT client to unregister it from the protocol stack. After this method is called, this [GattClientDevice](#gattclientdevice) instance cannot be used.
> **NOTE**<br>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.GattClientDevice.close](js-apis-bluetoothManager.md#close-1).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -2640,12 +2547,15 @@ let ret = device.close(); ...@@ -2640,12 +2547,15 @@ let ret = device.close();
### getServices ### getServices<sup>(deprecated)</sup>
getServices(callback: AsyncCallback&lt;Array&lt;GattService&gt;&gt;): void getServices(callback: AsyncCallback&lt;Array&lt;GattService&gt;&gt;): void
Obtains all services of the remote BLE device. This API uses an asynchronous callback to return the result. Obtains all services of the remote BLE device. This API uses an asynchronous callback to return the result.
> **NOTE**<br>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.GattClientDevice.getServices](js-apis-bluetoothManager.md#getservices).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -2682,12 +2592,15 @@ device.getServices(getServices); ...@@ -2682,12 +2592,15 @@ device.getServices(getServices);
``` ```
### getServices ### getServices<sup>(deprecated)</sup>
getServices(): Promise&lt;Array&lt;GattService&gt;&gt; getServices(): Promise&lt;Array&lt;GattService&gt;&gt;
Obtains all services of the remote BLE device. This API uses a promise to return the result. Obtains all services of the remote BLE device. This API uses a promise to return the result.
> **NOTE**<br>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.GattClientDevice.getServices](js-apis-bluetoothManager.md#getservices-1).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -2710,12 +2623,15 @@ device.getServices().then(result => { ...@@ -2710,12 +2623,15 @@ device.getServices().then(result => {
``` ```
### readCharacteristicValue ### readCharacteristicValue<sup>(deprecated)</sup>
readCharacteristicValue(characteristic: BLECharacteristic, callback: AsyncCallback&lt;BLECharacteristic&gt;): void readCharacteristicValue(characteristic: BLECharacteristic, callback: AsyncCallback&lt;BLECharacteristic&gt;): void
Reads the characteristic value of the specific service of the remote BLE device. This API uses an asynchronous callback to return the result. Reads the characteristic value of the specific service of the remote BLE device. This API uses an asynchronous callback to return the result.
> **NOTE**<br>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.GattClientDevice.readCharacteristicValue](js-apis-bluetoothManager.md#readcharacteristicvalue).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -2764,12 +2680,15 @@ device.readCharacteristicValue(characteristic, readCcc); ...@@ -2764,12 +2680,15 @@ device.readCharacteristicValue(characteristic, readCcc);
``` ```
### readCharacteristicValue ### readCharacteristicValue<sup>(deprecated)</sup>
readCharacteristicValue(characteristic: BLECharacteristic): Promise&lt;BLECharacteristic&gt; readCharacteristicValue(characteristic: BLECharacteristic): Promise&lt;BLECharacteristic&gt;
Reads the characteristic value of the specific service of the remote BLE device. This API uses a promise to return the result. Reads the characteristic value of the specific service of the remote BLE device. This API uses a promise to return the result.
> **NOTE**<br>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.GattClientDevice.readCharacteristicValue](js-apis-bluetoothManager.md#readcharacteristicvalue-1).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -2810,12 +2729,15 @@ device.readCharacteristicValue(characteristic); ...@@ -2810,12 +2729,15 @@ device.readCharacteristicValue(characteristic);
``` ```
### readDescriptorValue ### readDescriptorValue<sup>(deprecated)</sup>
readDescriptorValue(descriptor: BLEDescriptor, callback: AsyncCallback&lt;BLEDescriptor&gt;): void readDescriptorValue(descriptor: BLEDescriptor, callback: AsyncCallback&lt;BLEDescriptor&gt;): void
Reads the descriptor contained in the specific characteristic of the remote BLE device. This API uses an asynchronous callback to return the result. Reads the descriptor contained in the specific characteristic of the remote BLE device. This API uses an asynchronous callback to return the result.
> **NOTE**<br>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.GattClientDevice.readDescriptorValue](js-apis-bluetoothManager.md#readdescriptorvalue).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -2854,12 +2776,15 @@ device.readDescriptorValue(descriptor, readDesc); ...@@ -2854,12 +2776,15 @@ device.readDescriptorValue(descriptor, readDesc);
``` ```
### readDescriptorValue ### readDescriptorValue<sup>(deprecated)</sup>
readDescriptorValue(descriptor: BLEDescriptor): Promise&lt;BLEDescriptor&gt; readDescriptorValue(descriptor: BLEDescriptor): Promise&lt;BLEDescriptor&gt;
Reads the descriptor contained in the specific characteristic of the remote BLE device. This API uses a promise to return the result. Reads the descriptor contained in the specific characteristic of the remote BLE device. This API uses a promise to return the result.
> **NOTE**<br>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.GattClientDevice.readDescriptorValue](js-apis-bluetoothManager.md#readdescriptorvalue-1).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -2890,12 +2815,15 @@ device.readDescriptorValue(descriptor); ...@@ -2890,12 +2815,15 @@ device.readDescriptorValue(descriptor);
``` ```
### writeCharacteristicValue ### writeCharacteristicValue<sup>(deprecated)</sup>
writeCharacteristicValue(characteristic: BLECharacteristic): boolean writeCharacteristicValue(characteristic: BLECharacteristic): boolean
Writes a characteristic value to the remote BLE device. Writes a characteristic value to the remote BLE device.
> **NOTE**<br>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.GattClientDevice.writeCharacteristicValue](js-apis-bluetoothManager.md#writecharacteristicvalue).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -2940,12 +2868,15 @@ if (retWriteCcc) { ...@@ -2940,12 +2868,15 @@ if (retWriteCcc) {
``` ```
### writeDescriptorValue ### writeDescriptorValue<sup>(deprecated)</sup>
writeDescriptorValue(descriptor: BLEDescriptor): boolean writeDescriptorValue(descriptor: BLEDescriptor): boolean
Writes binary data to the specific descriptor of the remote BLE device. Writes binary data to the specific descriptor of the remote BLE device.
> **NOTE**<br>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.GattClientDevice.writeDescriptorValue](js-apis-bluetoothManager.md#writedescriptorvalue).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -2981,12 +2912,15 @@ if (retWriteDesc) { ...@@ -2981,12 +2912,15 @@ if (retWriteDesc) {
``` ```
### setBLEMtuSize ### setBLEMtuSize<sup>(deprecated)</sup>
setBLEMtuSize(mtu: number): boolean setBLEMtuSize(mtu: number): boolean
Sets the maximum transmission unit (MTU) that can be transmitted between the GATT client and its remote BLE device. This API can be used only after a connection is set up by calling [connect](#connect). Sets the maximum transmission unit (MTU) that can be transmitted between the GATT client and its remote BLE device. This API can be used only after a connection is set up by calling [connect](#connect).
> **NOTE**<br>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.GattClientDevice.setBLEMtuSize](js-apis-bluetoothManager.md#setblemtusize).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -3011,12 +2945,15 @@ device.setBLEMtuSize(128); ...@@ -3011,12 +2945,15 @@ device.setBLEMtuSize(128);
``` ```
### setNotifyCharacteristicChanged ### setNotifyCharacteristicChanged<sup>(deprecated)</sup>
setNotifyCharacteristicChanged(characteristic: BLECharacteristic, enable: boolean): boolean setNotifyCharacteristicChanged(characteristic: BLECharacteristic, enable: boolean): boolean
Sets the function of notifying the GATT client when the characteristic value of the remote BLE device changes. Sets the function of notifying the GATT client when the characteristic value of the remote BLE device changes.
> **NOTE**<br>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.GattClientDevice.setNotifyCharacteristicChanged](js-apis-bluetoothManager.md#setnotifycharacteristicchanged).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -3054,12 +2991,15 @@ device.setNotifyCharacteristicChanged(characteristic, false); ...@@ -3054,12 +2991,15 @@ device.setNotifyCharacteristicChanged(characteristic, false);
``` ```
### on('BLECharacteristicChange') ### on('BLECharacteristicChange')<sup>(deprecated)</sup>
on(type: "BLECharacteristicChange", callback: Callback&lt;BLECharacteristic&gt;): void on(type: "BLECharacteristicChange", callback: Callback&lt;BLECharacteristic&gt;): void
Subscribes to the BLE characteristic change events. The client can receive a notification from the server only after the **setNotifyCharacteristicChanged** method is called. Subscribes to the BLE characteristic change events. The client can receive a notification from the server only after the **setNotifyCharacteristicChanged** method is called.
> **NOTE**<br>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.GattClientDevice.on('BLECharacteristicChange')](js-apis-bluetoothManager.md#onblecharacteristicchange).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -3088,12 +3028,15 @@ device.on('BLECharacteristicChange', CharacteristicChange); ...@@ -3088,12 +3028,15 @@ device.on('BLECharacteristicChange', CharacteristicChange);
``` ```
### off('BLECharacteristicChange') ### off('BLECharacteristicChange')<sup>(deprecated)</sup>
off(type: "BLECharacteristicChange", callback?: Callback&lt;BLECharacteristic&gt;): void off(type: "BLECharacteristicChange", callback?: Callback&lt;BLECharacteristic&gt;): void
Unsubscribes from the BLE characteristic change events. Unsubscribes from the BLE characteristic change events.
> **NOTE**<br>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.GattClientDevice.off('BLECharacteristicChange')](js-apis-bluetoothManager.md#offblecharacteristicchange).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -3117,12 +3060,15 @@ device.off('BLECharacteristicChange'); ...@@ -3117,12 +3060,15 @@ device.off('BLECharacteristicChange');
``` ```
### on('BLEConnectionStateChange') ### on('BLEConnectionStateChange')<sup>(deprecated)</sup>
on(type: "BLEConnectionStateChange", callback: Callback&lt;BLEConnectChangedState&gt;): void on(type: "BLEConnectionStateChange", callback: Callback&lt;BLEConnectChangedState&gt;): void
Subscribes to the BLE connection state change events. Subscribes to the BLE connection state change events.
> **NOTE**<br>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.GattClientDevice.on('BLEConnectionStateChange')](js-apis-bluetoothManager.md#onbleconnectionstatechange).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -3150,12 +3096,15 @@ device.on('BLEConnectionStateChange', ConnectStateChanged); ...@@ -3150,12 +3096,15 @@ device.on('BLEConnectionStateChange', ConnectStateChanged);
``` ```
### off('BLEConnectionStateChange') ### off('BLEConnectionStateChange')<sup>(deprecated)</sup>
off(type: "BLEConnectionStateChange", callback?: Callback&lt;BLEConnectChangedState&gt;): void off(type: "BLEConnectionStateChange", callback?: Callback&lt;BLEConnectChangedState&gt;): void
Unsubscribes from the BLE connection state change events. Unsubscribes from the BLE connection state change events.
> **NOTE**<br>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.GattClientDevice.off('BLEConnectionStateChange')](js-apis-bluetoothManager.md#offbleconnectionstatechange).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -3179,12 +3128,15 @@ device.off('BLEConnectionStateChange'); ...@@ -3179,12 +3128,15 @@ device.off('BLEConnectionStateChange');
``` ```
### getDeviceName ### getDeviceName<sup>(deprecated)</sup>
getDeviceName(callback: AsyncCallback&lt;string&gt;): void getDeviceName(callback: AsyncCallback&lt;string&gt;): void
Obtains the name of the remote BLE device. This API uses an asynchronous callback to return the result. Obtains the name of the remote BLE device. This API uses an asynchronous callback to return the result.
> **NOTE**<br>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.GattClientDevice.getDeviceName](js-apis-bluetoothManager.md#getdevicename).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -3211,12 +3163,15 @@ let deviceName = gattClient.getDeviceName((err, data)=> { ...@@ -3211,12 +3163,15 @@ let deviceName = gattClient.getDeviceName((err, data)=> {
``` ```
### getDeviceName ### getDeviceName<sup>(deprecated)</sup>
getDeviceName(): Promise&lt;string&gt; getDeviceName(): Promise&lt;string&gt;
Obtains the name of the remote BLE device. This API uses a promise to return the result. Obtains the name of the remote BLE device. This API uses a promise to return the result.
> **NOTE**<br>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.GattClientDevice.getDeviceName](js-apis-bluetoothManager.md#getdevicename-1).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -3239,12 +3194,15 @@ let deviceName = gattClient.getDeviceName().then((data) => { ...@@ -3239,12 +3194,15 @@ let deviceName = gattClient.getDeviceName().then((data) => {
``` ```
### getRssiValue ### getRssiValue<sup>(deprecated)</sup>
getRssiValue(callback: AsyncCallback&lt;number&gt;): void getRssiValue(callback: AsyncCallback&lt;number&gt;): void
Obtains the received signal strength indication (RSSI) of the remote BLE device. This API uses an asynchronous callback to return the result. It can be used only after a connection is set up by calling [connect](#connect). Obtains the received signal strength indication (RSSI) of the remote BLE device. This API uses an asynchronous callback to return the result. It can be used only after a connection is set up by calling [connect](#connect).
> **NOTE**<br>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.GattClientDevice.getRssiValue](js-apis-bluetoothManager.md#getrssivalue).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -3272,12 +3230,15 @@ let rssi = gattClient.getRssiValue((err, data)=> { ...@@ -3272,12 +3230,15 @@ let rssi = gattClient.getRssiValue((err, data)=> {
``` ```
### getRssiValue ### getRssiValue<sup>(deprecated)</sup>
getRssiValue(): Promise&lt;number&gt; getRssiValue(): Promise&lt;number&gt;
Obtains the RSSI of the remote BLE device. This API uses a promise to return the result. It can be used only after a connection is set up by calling [connect](#connect). Obtains the RSSI of the remote BLE device. This API uses a promise to return the result. It can be used only after a connection is set up by calling [connect](#connect).
> **NOTE**<br>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.GattClientDevice.getRssiValue](js-apis-bluetoothManager.md#getrssivalue-1).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -3298,10 +3259,13 @@ let rssi = gattClient.getRssiValue().then((data) => { ...@@ -3298,10 +3259,13 @@ let rssi = gattClient.getRssiValue().then((data) => {
}) })
``` ```
## ScanMode<sup>8+</sup><a name="ScanMode"></a> ## ScanMode<sup>8+</sup><sup>(deprecated)</sup><a name="ScanMode"></a>
Enumerates the scan modes. Enumerates the scan modes.
> **NOTE**<br>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.ScanMode](js-apis-bluetoothManager.md#scanmode).
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Value | Description | | Name | Value | Description |
...@@ -3313,10 +3277,13 @@ Enumerates the scan modes. ...@@ -3313,10 +3277,13 @@ Enumerates the scan modes.
| SCAN_MODE_CONNECTABLE_GENERAL_DISCOVERABLE | 4 | General connectable and discoverable mode.| | SCAN_MODE_CONNECTABLE_GENERAL_DISCOVERABLE | 4 | General connectable and discoverable mode.|
| SCAN_MODE_CONNECTABLE_LIMITED_DISCOVERABLE | 5 | Limited connectable and discoverable mode.| | SCAN_MODE_CONNECTABLE_LIMITED_DISCOVERABLE | 5 | Limited connectable and discoverable mode.|
## BondState<sup>8+</sup><a name="BondState"></a> ## BondState<sup>8+</sup><sup>(deprecated)</sup><a name="BondState"></a>
Enumerates the pairing states. Enumerates the pairing states.
> **NOTE**<br>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.BondState](js-apis-bluetoothManager.md#bondstate).
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Value | Description | | Name | Value | Description |
...@@ -3326,10 +3293,13 @@ Enumerates the pairing states. ...@@ -3326,10 +3293,13 @@ Enumerates the pairing states.
| BOND_STATE_BONDED | 2 | Paired. | | BOND_STATE_BONDED | 2 | Paired. |
## SppOption<sup>8+</sup><a name="SppOption"></a> ## SppOption<sup>8+</sup><sup>(deprecated)</sup><a name="SppOption"></a>
Defines the SPP configuration parameters. Defines the SPP configuration parameters.
> **NOTE**<br>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.SppOption](js-apis-bluetoothManager.md#sppoption).
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Type | Readable | Writable | Description | | Name | Type | Readable | Writable | Description |
...@@ -3339,10 +3309,13 @@ Defines the SPP configuration parameters. ...@@ -3339,10 +3309,13 @@ Defines the SPP configuration parameters.
| type | [SppType](#spptype) | Yes | Yes | Type of the SPP link. | | type | [SppType](#spptype) | Yes | Yes | Type of the SPP link. |
## SppType<sup>8+</sup><a name="SppType"></a> ## SppType<sup>8+</sup><sup>(deprecated)</sup><a name="SppType"></a>
Enumerates the SPP link types. Enumerates the SPP link types.
> **NOTE**<br>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.SppType](js-apis-bluetoothManager.md#spptype).
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Value | Description | | Name | Value | Description |
...@@ -3350,10 +3323,13 @@ Enumerates the SPP link types. ...@@ -3350,10 +3323,13 @@ Enumerates the SPP link types.
| SPP_RFCOMM | 0 | Radio frequency communication (RFCOMM) link type.| | SPP_RFCOMM | 0 | Radio frequency communication (RFCOMM) link type.|
## GattService ## GattService<sup>(deprecated)</sup>
Defines the GATT service API parameters. Defines the GATT service API parameters.
> **NOTE**<br>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.GattService](js-apis-bluetoothManager.md#gattservice).
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Type | Readable | Writable | Description | | Name | Type | Readable | Writable | Description |
...@@ -3364,10 +3340,13 @@ Defines the GATT service API parameters. ...@@ -3364,10 +3340,13 @@ Defines the GATT service API parameters.
| includeServices | Array&lt;[GattService](#gattservice)&gt; | Yes | Yes | Services on which the service depends. | | includeServices | Array&lt;[GattService](#gattservice)&gt; | Yes | Yes | Services on which the service depends. |
## BLECharacteristic ## BLECharacteristic<sup>(deprecated)</sup>
Defines the characteristic API parameters. Defines the characteristic API parameters.
> **NOTE**<br>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.BLECharacteristic](js-apis-bluetoothManager.md#blecharacteristic).
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Type | Readable | Writable | Description | | Name | Type | Readable | Writable | Description |
...@@ -3378,10 +3357,13 @@ Defines the characteristic API parameters. ...@@ -3378,10 +3357,13 @@ Defines the characteristic API parameters.
| descriptors | Array&lt;[BLEDescriptor](#bledescriptor)&gt; | Yes | Yes | List of descriptors of the characteristic. | | descriptors | Array&lt;[BLEDescriptor](#bledescriptor)&gt; | Yes | Yes | List of descriptors of the characteristic. |
## BLEDescriptor ## BLEDescriptor<sup>(deprecated)</sup>
Defines the descriptor API parameters. Defines the descriptor API parameters.
> **NOTE**<br>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.BLEDescriptor](js-apis-bluetoothManager.md#bledescriptor).
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Type | Readable | Writable | Description | | Name | Type | Readable | Writable | Description |
...@@ -3392,10 +3374,13 @@ Defines the descriptor API parameters. ...@@ -3392,10 +3374,13 @@ Defines the descriptor API parameters.
| descriptorValue | ArrayBuffer | Yes | Yes | Binary value of the descriptor. | | descriptorValue | ArrayBuffer | Yes | Yes | Binary value of the descriptor. |
## NotifyCharacteristic ## NotifyCharacteristic<sup>(deprecated)</sup>
Defines the parameters in the notifications sent when the server characteristic value changes. Defines the parameters in the notifications sent when the server characteristic value changes.
> **NOTE**<br>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.NotifyCharacteristic](js-apis-bluetoothManager.md#notifycharacteristic).
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Type | Readable | Writable | Description | | Name | Type | Readable | Writable | Description |
...@@ -3406,10 +3391,13 @@ Defines the parameters in the notifications sent when the server characteristic ...@@ -3406,10 +3391,13 @@ Defines the parameters in the notifications sent when the server characteristic
| confirm | boolean | Yes | Yes | Whether the notification needs to be confirmed by the remote end. For a notification, set it to **true**. In this case, the remote end must confirm the receipt of the notification. For an indication, set it to **false**. In this case, the remote end does not need to confirm the receipt of the notification.| | confirm | boolean | Yes | Yes | Whether the notification needs to be confirmed by the remote end. For a notification, set it to **true**. In this case, the remote end must confirm the receipt of the notification. For an indication, set it to **false**. In this case, the remote end does not need to confirm the receipt of the notification.|
## CharacteristicReadReq ## CharacteristicReadReq<sup>(deprecated)</sup>
Defines the parameters of the **CharacteristicReadReq** event received by the server. Defines the parameters of the **CharacteristicReadReq** event received by the server.
> **NOTE**<br>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.CharacteristicReadRequest](js-apis-bluetoothManager.md#characteristicreadrequest).
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Type | Readable | Writable | Description | | Name | Type | Readable | Writable | Description |
...@@ -3421,10 +3409,13 @@ Defines the parameters of the **CharacteristicReadReq** event received by the se ...@@ -3421,10 +3409,13 @@ Defines the parameters of the **CharacteristicReadReq** event received by the se
| serviceUuid | string | Yes | No | UUID of the service, for example, **00001888-0000-1000-8000-00805f9b34fb**.| | serviceUuid | string | Yes | No | UUID of the service, for example, **00001888-0000-1000-8000-00805f9b34fb**.|
## CharacteristicWriteReq ## CharacteristicWriteReq<sup>(deprecated)</sup>
Defines the parameters of the **CharacteristicWriteReq** event received by the server. Defines the parameters of the **CharacteristicWriteReq** event received by the server.
> **NOTE**<br>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.CharacteristicWriteRequest](js-apis-bluetoothManager.md#characteristicwriterequest).
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Type | Readable | Writable | Description | | Name | Type | Readable | Writable | Description |
...@@ -3437,10 +3428,13 @@ Defines the parameters of the **CharacteristicWriteReq** event received by the s ...@@ -3437,10 +3428,13 @@ Defines the parameters of the **CharacteristicWriteReq** event received by the s
| serviceUuid | string | Yes | No | UUID of the service, for example, **00001888-0000-1000-8000-00805f9b34fb**.| | serviceUuid | string | Yes | No | UUID of the service, for example, **00001888-0000-1000-8000-00805f9b34fb**.|
## DescriptorReadReq ## DescriptorReadReq<sup>(deprecated)</sup>
Defines the parameters of the **DescriptorReadReq** event received by the server. Defines the parameters of the **DescriptorReadReq** event received by the server.
> **NOTE**<br>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.DescriptorReadRequest](js-apis-bluetoothManager.md#descriptorreadrequest).
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Type | Readable | Writable | Description | | Name | Type | Readable | Writable | Description |
...@@ -3453,10 +3447,13 @@ Defines the parameters of the **DescriptorReadReq** event received by the server ...@@ -3453,10 +3447,13 @@ Defines the parameters of the **DescriptorReadReq** event received by the server
| serviceUuid | string | Yes | No | UUID of the service, for example, **00001888-0000-1000-8000-00805f9b34fb**.| | serviceUuid | string | Yes | No | UUID of the service, for example, **00001888-0000-1000-8000-00805f9b34fb**.|
## DescriptorWriteReq ## DescriptorWriteReq<sup>(deprecated)</sup>
Defines the parameters of the **DescriptorWriteReq** event received by the server. Defines the parameters of the **DescriptorWriteReq** event received by the server.
> **NOTE**<br>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.DescriptorWriteRequest](js-apis-bluetoothManager.md#descriptorwriterequest).
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Type | Readable | Writable | Description | | Name | Type | Readable | Writable | Description |
...@@ -3472,10 +3469,13 @@ Defines the parameters of the **DescriptorWriteReq** event received by the serve ...@@ -3472,10 +3469,13 @@ Defines the parameters of the **DescriptorWriteReq** event received by the serve
| serviceUuid | string | Yes | No | UUID of the service, for example, **00001888-0000-1000-8000-00805f9b34fb**.| | serviceUuid | string | Yes | No | UUID of the service, for example, **00001888-0000-1000-8000-00805f9b34fb**.|
## ServerResponse ## ServerResponse<sup>(deprecated)</sup>
Defines the parameters of the server's response to the GATT client's read/write request. Defines the parameters of the server's response to the GATT client's read/write request.
> **NOTE**<br>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.ServerResponse](js-apis-bluetoothManager.md#serverresponse).
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Type | Readable | Writable | Description | | Name | Type | Readable | Writable | Description |
...@@ -3487,10 +3487,13 @@ Defines the parameters of the server's response to the GATT client's read/write ...@@ -3487,10 +3487,13 @@ Defines the parameters of the server's response to the GATT client's read/write
| value | ArrayBuffer | Yes | No | Binary data in the response. | | value | ArrayBuffer | Yes | No | Binary data in the response. |
## BLEConnectChangedState ## BLEConnectChangedState<sup>(deprecated)</sup>
Defines the parameters of **BLEConnectChangedState**. Defines the parameters of **BLEConnectChangedState**.
> **NOTE**<br>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.BLEConnectChangedState](js-apis-bluetoothManager.md#bleconnectchangedstate).
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Type | Readable| Writable| Description | | Name | Type | Readable| Writable| Description |
...@@ -3499,10 +3502,13 @@ Defines the parameters of **BLEConnectChangedState**. ...@@ -3499,10 +3502,13 @@ Defines the parameters of **BLEConnectChangedState**.
| state | [ProfileConnectionState](#profileconnectionstate) | Yes | Yes | BLE connection state. | | state | [ProfileConnectionState](#profileconnectionstate) | Yes | Yes | BLE connection state. |
## ProfileConnectionState ## ProfileConnectionState<sup>(deprecated)</sup>
Enumerates the profile connection states. Enumerates the profile connection states.
> **NOTE**<br>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.ProfileConnectionState](js-apis-bluetoothManager.md#profileconnectionstate).
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Value | Description | | Name | Value | Description |
...@@ -3513,10 +3519,13 @@ Enumerates the profile connection states. ...@@ -3513,10 +3519,13 @@ Enumerates the profile connection states.
| STATE_DISCONNECTING | 3 | Disconnecting.| | STATE_DISCONNECTING | 3 | Disconnecting.|
## ScanFilter ## ScanFilter<sup>(deprecated)</sup>
Defines the scan filter parameters. Defines the scan filter parameters.
> **NOTE**<br>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.ScanFilter](js-apis-bluetoothManager.md#scanfilter).
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Type | Readable| Writable| Description | | Name | Type | Readable| Writable| Description |
...@@ -3524,20 +3533,15 @@ Defines the scan filter parameters. ...@@ -3524,20 +3533,15 @@ Defines the scan filter parameters.
| deviceId | string | Yes | Yes | Address of the BLE device to filter, for example, XX:XX:XX:XX:XX:XX. | | deviceId | string | Yes | Yes | Address of the BLE device to filter, for example, XX:XX:XX:XX:XX:XX. |
| name | string | Yes | Yes | Name of the BLE device to filter. | | name | string | Yes | Yes | Name of the BLE device to filter. |
| serviceUuid | string | Yes | Yes | Service UUID of the device to filter, for example, **00001888-0000-1000-8000-00805f9b34fb**.| | serviceUuid | string | Yes | Yes | Service UUID of the device to filter, for example, **00001888-0000-1000-8000-00805f9b34fb**.|
| serviceUuidMask<sup>9+</sup> | string | Yes | Yes | Service UUID mask of the device to filter, for example, **FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF**.|
| serviceSolicitationUuid<sup>9+</sup> | string | Yes | Yes | Service solicitation UUID of the device to filter, for example, **00001888-0000-1000-8000-00805F9B34FB**.|
| serviceSolicitationUuidMask<sup>9+</sup> | string | Yes | Yes | Service solicitation UUID mask of the device to filter, for example, **FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF**.|
| serviceData<sup>9+</sup> | ArrayBuffer | Yes | Yes | Service data of the device to filter, for example, **[0x90, 0x00, 0xF1, 0xF2]**.|
| serviceDataMask<sup>9+</sup> | ArrayBuffer | Yes | Yes | Service data mask of the device to filter, for example, **[0xFF,0xFF,0xFF,0xFF]**.|
| manufactureId<sup>9+</sup> | number | Yes | Yes | Manufacturer ID of the device to filter, for example, **0x0006**. |
| manufactureData<sup>9+</sup> | ArrayBuffer | Yes | Yes | Manufacturer data of the device to filter, for example, **[0x1F,0x2F,0x3F]**.|
| manufactureDataMask<sup>9+</sup> | ArrayBuffer | Yes | Yes | Manufacturer data mask of the device to filter, for example, **[0xFF, 0xFF, 0xFF]**.|
## ScanOptions ## ScanOptions<sup>(deprecated)</sup>
Defines the scan configuration parameters. Defines the scan configuration parameters.
> **NOTE**<br>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.ScanOptions](js-apis-bluetoothManager.md#scanoptions).
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Type | Readable | Writable | Description | | Name | Type | Readable | Writable | Description |
...@@ -3547,10 +3551,13 @@ Defines the scan configuration parameters. ...@@ -3547,10 +3551,13 @@ Defines the scan configuration parameters.
| matchMode | [MatchMode](#matchmode) | Yes | Yes | Hardware filtering match mode. The default value is **MATCH_MODE_AGGRESSIVE**.| | matchMode | [MatchMode](#matchmode) | Yes | Yes | Hardware filtering match mode. The default value is **MATCH_MODE_AGGRESSIVE**.|
## ScanDuty ## ScanDuty<sup>(deprecated)</sup>
Enumerates the scan duty options. Enumerates the scan duty options.
> **NOTE**<br>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.ScanDuty](js-apis-bluetoothManager.md#scanduty).
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Value | Description | | Name | Value | Description |
...@@ -3560,10 +3567,13 @@ Enumerates the scan duty options. ...@@ -3560,10 +3567,13 @@ Enumerates the scan duty options.
| SCAN_MODE_LOW_LATENCY | 2 | Low-latency mode. | | SCAN_MODE_LOW_LATENCY | 2 | Low-latency mode. |
## MatchMode ## MatchMode<sup>(deprecated)</sup>
Enumerates the hardware match modes of BLE scan filters. Enumerates the hardware match modes of BLE scan filters.
> **NOTE**<br>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.MatchMode](js-apis-bluetoothManager.md#matchmode).
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Value | Description | | Name | Value | Description |
...@@ -3572,10 +3582,13 @@ Enumerates the hardware match modes of BLE scan filters. ...@@ -3572,10 +3582,13 @@ Enumerates the hardware match modes of BLE scan filters.
| MATCH_MODE_STICKY | 2 | Hardware reports the scan result with a higher threshold of signal strength and sightings. | | MATCH_MODE_STICKY | 2 | Hardware reports the scan result with a higher threshold of signal strength and sightings. |
## ScanResult ## ScanResult<sup>(deprecated)</sup>
Defines the scan result. Defines the scan result.
> **NOTE**<br>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.ScanResult](js-apis-bluetoothManager.md#scanresult).
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Type | Readable | Writable | Description | | Name | Type | Readable | Writable | Description |
...@@ -3585,10 +3598,13 @@ Defines the scan result. ...@@ -3585,10 +3598,13 @@ Defines the scan result.
| data | ArrayBuffer | Yes | No | Advertisement packets sent by the device. | | data | ArrayBuffer | Yes | No | Advertisement packets sent by the device. |
## BluetoothState ## BluetoothState<sup>(deprecated)</sup>
Enumerates the Bluetooth states. Enumerates the Bluetooth states.
> **NOTE**<br>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.BluetoothState](js-apis-bluetoothManager.md#bluetoothstate).
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Value | Description | | Name | Value | Description |
...@@ -3602,10 +3618,13 @@ Enumerates the Bluetooth states. ...@@ -3602,10 +3618,13 @@ Enumerates the Bluetooth states.
| STATE_BLE_TURNING_OFF | 6 | The LE-only mode is being turned off for Bluetooth.| | STATE_BLE_TURNING_OFF | 6 | The LE-only mode is being turned off for Bluetooth.|
## AdvertiseSetting ## AdvertiseSetting<sup>(deprecated)</sup>
Defines the BLE advertising parameters. Defines the BLE advertising parameters.
> **NOTE**<br>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.AdvertiseSetting](js-apis-bluetoothManager.md#advertisesetting).
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Type | Readable | Writable | Description | | Name | Type | Readable | Writable | Description |
...@@ -3615,10 +3634,13 @@ Defines the BLE advertising parameters. ...@@ -3615,10 +3634,13 @@ Defines the BLE advertising parameters.
| connectable | boolean | Yes | Yes | Whether the advertisement is connectable. The default value is **true**. | | connectable | boolean | Yes | Yes | Whether the advertisement is connectable. The default value is **true**. |
## AdvertiseData ## AdvertiseData<sup>(deprecated)</sup>
Defines the content of a BLE advertisement packet. Defines the content of a BLE advertisement packet.
> **NOTE**<br>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.AdvertiseData](js-apis-bluetoothManager.md#advertisedata).
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Type | Readable | Writable | Description | | Name | Type | Readable | Writable | Description |
...@@ -3628,10 +3650,13 @@ Defines the content of a BLE advertisement packet. ...@@ -3628,10 +3650,13 @@ Defines the content of a BLE advertisement packet.
| serviceData | Array&lt;[ServiceData](#servicedata)&gt; | Yes | Yes | List of service data to broadcast. | | serviceData | Array&lt;[ServiceData](#servicedata)&gt; | Yes | Yes | List of service data to broadcast. |
## ManufactureData ## ManufactureData<sup>(deprecated)</sup>
Defines the content of a BLE advertisement packet. Defines the content of a BLE advertisement packet.
> **NOTE**<br>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.ManufactureData](js-apis-bluetoothManager.md#manufacturedata).
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Type | Readable | Writable | Description | | Name | Type | Readable | Writable | Description |
...@@ -3640,10 +3665,13 @@ Defines the content of a BLE advertisement packet. ...@@ -3640,10 +3665,13 @@ Defines the content of a BLE advertisement packet.
| manufactureValue | ArrayBuffer | Yes | Yes | Manufacturer data. | | manufactureValue | ArrayBuffer | Yes | Yes | Manufacturer data. |
## ServiceData ## ServiceData<sup>(deprecated)</sup>
Defines the service data contained in an advertisement packet. Defines the service data contained in an advertisement packet.
> **NOTE**<br>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [bluetoothManager.ServiceData](js-apis-bluetoothManager.md#servicedata).
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Type | Readable | Writable | Description | | Name | Type | Readable | Writable | Description |
...@@ -3652,10 +3680,13 @@ Defines the service data contained in an advertisement packet. ...@@ -3652,10 +3680,13 @@ Defines the service data contained in an advertisement packet.
| serviceValue | ArrayBuffer | Yes | Yes | Service data. | | serviceValue | ArrayBuffer | Yes | Yes | Service data. |
## PinRequiredParam<sup>8+</sup><a name="PinRequiredParam"></a> ## PinRequiredParam<sup>8+</sup><sup>(deprecated)</sup><a name="PinRequiredParam"></a>
Defines the pairing request parameters. Defines the pairing request parameters.
> **NOTE**<br>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.PinRequiredParam](js-apis-bluetoothManager.md#pinrequiredparam).
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Type | Readable | Writable | Description | | Name | Type | Readable | Writable | Description |
...@@ -3664,10 +3695,13 @@ Defines the pairing request parameters. ...@@ -3664,10 +3695,13 @@ Defines the pairing request parameters.
| pinCode | string | Yes | No | Key for the device pairing. | | pinCode | string | Yes | No | Key for the device pairing. |
## BondStateParam<sup>8+</sup><a name="BondStateParam"></a> ## BondStateParam<sup>8+</sup><sup>(deprecated)</sup><a name="BondStateParam"></a>
Defines the pairing state parameters. Defines the pairing state parameters.
> **NOTE**<br>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.BondStateParam](js-apis-bluetoothManager.md#bondstateparam).
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Type | Readable | Writable | Description | | Name | Type | Readable | Writable | Description |
...@@ -3676,10 +3710,13 @@ Defines the pairing state parameters. ...@@ -3676,10 +3710,13 @@ Defines the pairing state parameters.
| state | BondState | Yes | No | State of the device.| | state | BondState | Yes | No | State of the device.|
## StateChangeParam<sup>8+</sup><a name="StateChangeParam"></a> ## StateChangeParam<sup>8+</sup><sup>(deprecated)</sup><a name="StateChangeParam"></a>
Defines the profile state change parameters. Defines the profile state change parameters.
> **NOTE**<br>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.StateChangeParam](js-apis-bluetoothManager.md#statechangeparam).
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Type | Readable| Writable| Description | | Name | Type | Readable| Writable| Description |
...@@ -3688,10 +3725,13 @@ Defines the profile state change parameters. ...@@ -3688,10 +3725,13 @@ Defines the profile state change parameters.
| state | [ProfileConnectionState](#profileconnectionstate) | Yes | No | Profile connection state of the device.| | state | [ProfileConnectionState](#profileconnectionstate) | Yes | No | Profile connection state of the device.|
## DeviceClass<sup>8+</sup><a name="DeviceClass"></a> ## DeviceClass<sup>8+</sup><sup>(deprecated)</sup><a name="DeviceClass"></a>
Defines the class of a Bluetooth device. Defines the class of a Bluetooth device.
> **NOTE**<br>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.DeviceClass](js-apis-bluetoothManager.md#deviceclass).
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Type | Readable | Writable | Description | | Name | Type | Readable | Writable | Description |
...@@ -3702,10 +3742,13 @@ Defines the class of a Bluetooth device. ...@@ -3702,10 +3742,13 @@ Defines the class of a Bluetooth device.
## MajorClass<sup>8+</sup><a name="MajorClass"></a> ## MajorClass<sup>8+</sup><sup>(deprecated)</sup><a name="MajorClass"></a>
Enumerates the major classes of Bluetooth devices. Enumerates the major classes of Bluetooth devices.
> **NOTE**<br>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.MajorClass](js-apis-bluetoothManager.md#majorclass).
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Value | Description | | Name | Value | Description |
...@@ -3723,10 +3766,13 @@ Enumerates the major classes of Bluetooth devices. ...@@ -3723,10 +3766,13 @@ Enumerates the major classes of Bluetooth devices.
| MAJOR_UNCATEGORIZED | 0x1F00 | Unclassified device. | | MAJOR_UNCATEGORIZED | 0x1F00 | Unclassified device. |
## MajorMinorClass<sup>8+</sup><a name="MajorMinorClass"></a> ## MajorMinorClass<sup>8+</sup><sup>(deprecated)</sup><a name="MajorMinorClass"></a>
Enumerates the major and minor classes of Bluetooth devices. Enumerates the major and minor classes of Bluetooth devices.
> **NOTE**<br>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.MajorMinorClass](js-apis-bluetoothManager.md#majorminorclass).
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Value | Description | | Name | Value | Description |
...@@ -3819,10 +3865,13 @@ Enumerates the major and minor classes of Bluetooth devices. ...@@ -3819,10 +3865,13 @@ Enumerates the major and minor classes of Bluetooth devices.
| HEALTH_PERSONAL_MOBILITY_DEVICE | 0x093C | Personal mobility device. | | HEALTH_PERSONAL_MOBILITY_DEVICE | 0x093C | Personal mobility device. |
## PlayingState<sup>8+</sup><a name="PlayingState"></a> ## PlayingState<sup>8+</sup><sup>(deprecated)</sup><a name="PlayingState"></a>
Enumerates the A2DP playing states. Enumerates the A2DP playing states.
> **NOTE**<br>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.PlayingState](js-apis-bluetoothManager.md#playingstate).
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Value | Description | | Name | Value | Description |
...@@ -3831,15 +3880,16 @@ Enumerates the A2DP playing states. ...@@ -3831,15 +3880,16 @@ Enumerates the A2DP playing states.
| STATE_PLAYING | 0x0001 | Playing.| | STATE_PLAYING | 0x0001 | Playing.|
## ProfileId<sup>8+</sup><a name="ProfileId"></a> ## ProfileId<sup>8+</sup><sup>(deprecated)</sup><a name="ProfileId"></a>
Enumerates the Bluetooth profiles. API version 9 is added with **PROFILE_HID_HOST** and **PROFILE_PAN_NETWORK**. Enumerates the Bluetooth profiles. API version 9 is added with **PROFILE_HID_HOST** and **PROFILE_PAN_NETWORK**.
> **NOTE**<br>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [bluetoothManager.ProfileId](js-apis-bluetoothManager.md#profileid).
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Value | Description | | Name | Value | Description |
| -------------------------------- | ------ | --------------- | | -------------------------------- | ------ | --------------- |
| PROFILE_A2DP_SOURCE | 1 | A2DP profile.| | PROFILE_A2DP_SOURCE | 1 | A2DP profile.|
| PROFILE_HANDS_FREE_AUDIO_GATEWAY | 4 | HFP profile. | | PROFILE_HANDS_FREE_AUDIO_GATEWAY | 4 | HFP profile. |
| PROFILE_HID_HOST<sup>9+</sup> | 6 | Human Interface Device (HID) profile. |
| PROFILE_PAN_NETWORK<sup>9+</sup> | 7 | PAN profile. |
# @ohos.bluetoothManager (Bluetooth)
The **Bluetooth** module provides classic Bluetooth capabilities and Bluetooth Low Energy (BLE) scan and advertising.
> **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.
## Modules to Import
```js
import bluetoothManager from '@ohos.bluetoothManager';
```
## bluetoothManager.enableBluetooth<a name="enableBluetooth"></a>
enableBluetooth(): void
Enables Bluetooth.
**Required permissions**: ohos.permission.DISCOVER_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900099 | Operation failed. |
**Example**
```js
try {
bluetoothManager.enableBluetooth();
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
```
## bluetoothManager.disableBluetooth<a name="disableBluetooth"></a>
disableBluetooth(): void
Disables Bluetooth.
**Required permissions**: ohos.permission.DISCOVER_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900099 | Operation failed. |
**Example**
```js
try {
bluetoothManager.disableBluetooth();
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
```
## bluetoothManager.getLocalName<a name="getLocalName"></a>
getLocalName(): string
Obtains the name of the local Bluetooth device.
**Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Return value**
| Type | Description |
| ------ | --------- |
| string | Name of the local Bluetooth device obtained.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900099 | Operation failed. |
**Example**
```js
try {
let localName = bluetoothManager.getLocalName();
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
```
## bluetoothManager.getState
getState(): BluetoothState
Obtains the Bluetooth state.
**Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Return value**
| Type | Description |
| --------------------------------- | --------- |
| [BluetoothState](#bluetoothstate) | Bluetooth state obtained.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900099 | Operation failed. |
**Example**
```js
try {
let state = bluetoothManager.getState();
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
```
## bluetoothManager.getBtConnectionState
getBtConnectionState(): ProfileConnectionState
Obtains the local profile connection status.
**Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Return value**
| Type | Description |
| ---------------------------------------- | ------------------- |
| [ProfileConnectionState](#profileconnectionstate) | Profile connection state obtained.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900003 | Bluetooth switch is off. |
|2900099 | Operation failed. |
**Example**
```js
try {
let connectionState = bluetoothManager.getBtConnectionState();
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
```
## bluetoothManager.setLocalName<a name="setLocalName"></a>
setLocalName(name: string): void
Sets the name of the local Bluetooth device.
**Required permissions**: ohos.permission.DISCOVER_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | --------------------- |
| name | string | Yes | Bluetooth device name to set. It cannot exceed 248 bytes.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900003 | Bluetooth switch is off. |
|2900099 | Operation failed. |
**Example**
```js
try {
bluetoothManager.setLocalName('device_name');
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
```
## bluetoothManager.pairDevice
pairDevice(deviceId: string): void
Initiates Bluetooth pairing.
**Required permissions**: ohos.permission.DISCOVER_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ------ | ---- | ----------------------------------- |
| deviceId | string | Yes | Address of the remote device to pair, for example, XX:XX:XX:XX:XX:XX.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900003 | Bluetooth switch is off. |
|2900099 | Operation failed. |
**Example**
```js
try {
// The address can be scanned.
bluetoothManager.pairDevice("XX:XX:XX:XX:XX:XX");
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
```
## bluetoothManager.getProfileConnectionState<a name="getProfileConnectionState"></a>
getProfileConnectionState(profileId: ProfileId): ProfileConnectionState
Obtains the connection status of the specified profile.
**Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| --------- | --------- | ---- | ------------------------------------- |
| ProfileId | profileId | Yes | ID of the profile to obtain, for example, **PROFILE_A2DP_SOURCE**.|
**Return value**
| Type | Description |
| ------------------------------------------------- | ------------------- |
| [ProfileConnectionState](#profileconnectionstate) | Profile connection state obtained.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900003 | Bluetooth switch is off. |
|2900004 | Profile is not supported. |
|2900099 | Operation failed. |
**Example**
```js
try {
let result = bluetoothManager.getProfileConnectionState(bluetoothManager.ProfileId.PROFILE_A2DP_SOURCE);
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
```
## bluetoothManager.cancelPairedDevice<a name="cancelPairedDevice"></a>
cancelPairedDevice(deviceId: string): void
Cancels a paired remote device.
**System API**: This is a system API.
**Required permissions**: ohos.permission.DISCOVER_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ------ | ---- | ------------------------------------- |
| deviceId | string | Yes | Address of the remote device to cancel, for example, XX:XX:XX:XX:XX:XX.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900003 | Bluetooth switch is off. |
|2900099 | Operation failed. |
**Example**
```js
try {
bluetoothManager.cancelPairedDevice("XX:XX:XX:XX:XX:XX");
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
```
## bluetoothManager.getRemoteDeviceName<a name="getRemoteDeviceName"></a>
getRemoteDeviceName(deviceId: string): string
Obtains the name of the remote Bluetooth device.
**Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ------ | ---- | --------------------------------- |
| deviceId | string | Yes | Address of the target remote device, for example, XX:XX:XX:XX:XX:XX.|
**Return value**
| Type | Description |
| ------ | ------------- |
| string | Device name (a string) obtained.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900003 | Bluetooth switch is off. |
|2900099 | Operation failed. |
**Example**
```js
try {
let remoteDeviceName = bluetoothManager.getRemoteDeviceName("XX:XX:XX:XX:XX:XX");
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
```
## bluetoothManager.getRemoteDeviceClass<a name="getRemoteDeviceClass"></a>
getRemoteDeviceClass(deviceId: string): DeviceClass
Obtains the class of the remote Bluetooth device.
**Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ------ | ---- | --------------------------------- |
| deviceId | string | Yes | Address of the target remote device, for example, XX:XX:XX:XX:XX:XX.|
**Return value**
| Type | Description |
| --------------------------- | -------- |
| [DeviceClass](#deviceclass) | Class of the remote device obtained.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900003 | Bluetooth switch is off. |
|2900099 | Operation failed. |
**Example**
```js
try {
let remoteDeviceClass = bluetoothManager.getRemoteDeviceClass("XX:XX:XX:XX:XX:XX");
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
```
## bluetoothManager.getPairedDevices<a name="getPairedDevices"></a>
getPairedDevices(): Array&lt;string&gt;
Obtains the paired devices.
**Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Return value**
| Type | Description |
| ------------------- | ------------- |
| Array&lt;string&gt; | Addresses of the paired Bluetooth devices.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900003 | Bluetooth switch is off. |
|2900099 | Operation failed. |
**Example**
```js
try {
let devices = bluetoothManager.getPairedDevices();
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
```
## bluetoothManager.setBluetoothScanMode<a name="setBluetoothScanMode"></a>
setBluetoothScanMode(mode: ScanMode, duration: number): void
Sets the Bluetooth scan mode so that the device can be discovered by a remote device.
**Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | --------------------- | ---- | ---------------------------- |
| mode | [ScanMode](#scanmode) | Yes | Bluetooth scan mode to set. |
| duration | number | Yes | Duration (in ms) in which the device can be discovered. The value **0** indicates unlimited time.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900003 | Bluetooth switch is off. |
|2900099 | Operation failed. |
**Example**
```js
try {
// The device can be discovered and connected only when the discoverable and connectable mode is used.
bluetoothManager.setBluetoothScanMode(bluetoothManager.ScanMode.SCAN_MODE_CONNECTABLE_GENERAL_DISCOVERABLE, 100);
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
```
## bluetoothManager.getBluetoothScanMode<a name="getBluetoothScanMode"></a>
getBluetoothScanMode(): ScanMode
Obtains the Bluetooth scan mode.
**Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Return value**
| Type | Description |
| --------------------- | ------- |
| [ScanMode](#scanmode) | Bluetooth scan mode to set.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900003 | Bluetooth switch is off. |
|2900099 | Operation failed. |
**Example**
```js
try {
let scanMode = bluetoothManager.getBluetoothScanMode();
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
```
## bluetoothManager.startBluetoothDiscovery<a name="startBluetoothDiscovery"></a>
startBluetoothDiscovery(): void
Starts Bluetooth scan to discover remote devices.
**Rquired permissions**: ohos.permission.DISCOVER_BLUETOOTH and ohos.permission.LOCATION and ohos.permission.APPROXIMATELY_LOCATION
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900003 | Bluetooth switch is off. |
|2900099 | Operation failed. |
**Example**
```js
let deviceId;
function onReceiveEvent(data) {
deviceId = data;
}
try {
bluetoothManager.on('bluetoothDeviceFind', onReceiveEvent);
bluetoothManager.startBluetoothDiscovery();
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
```
## bluetoothManager.stopBluetoothDiscovery<a name="stopBluetoothDiscovery"></a>
stopBluetoothDiscovery(): void
Stops Bluetooth scan.
**Required permissions**: ohos.permission.DISCOVER_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900003 | Bluetooth switch is off. |
|2900099 | Operation failed. |
**Example**
```js
try {
bluetoothManager.stopBluetoothDiscovery();
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
```
## bluetoothManager.setDevicePairingConfirmation<a name="setDevicePairingConfirmation"></a>
setDevicePairingConfirmation(device: string, accept: boolean): void
Sets the device pairing confirmation.
**Required permissions**: ohos.permission.MANAGE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ------ | ------- | ---- | -------------------------------- |
| device | string | Yes | Address of the remote device, for example, XX:XX:XX:XX:XX:XX.|
| accept | boolean | Yes | Whether to accept the pairing request. The value **true** means to accept the pairing request, and the value **false** means the opposite. |
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900003 | Bluetooth switch is off. |
|2900099 | Operation failed. |
**Example**
```js
try {
// Subscribe to the pinRequired event and configure the pairing confirmation after receiving a pairing request from the remote device.
function onReceivePinRequiredEvent(data) { // data is the input parameter for the pairing request.
console.info('pin required = '+ JSON.stringify(data));
bluetoothManager.setDevicePairingConfirmation(data.deviceId, true);
}
bluetoothManager.on("pinRequired", onReceivePinRequiredEvent);
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
```
## bluetoothManager.on('bluetoothDeviceFind')
on(type: "bluetoothDeviceFind", callback: Callback&lt;Array&lt;string&gt;&gt;): void
Subscribes to the Bluetooth device discovery events.
**Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ----------------------------------- | ---- | -------------------------------------- |
| type | string | Yes | Event type. The value **bluetoothDeviceFind** indicates an event reported when a Bluetooth device is discovered.|
| callback | Callback&lt;Array&lt;string&gt;&gt; | Yes | Callback invoked to return the discovered devices. You need to implement this callback. |
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900099 | Operation failed. |
**Example**
```js
function onReceiveEvent(data) { // data is a set of Bluetooth device addresses.
console.info('bluetooth device find = '+ JSON.stringify(data));
}
try {
bluetoothManager.on('bluetoothDeviceFind', onReceiveEvent);
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
```
## bluetoothManager.off('bluetoothDeviceFind')
off(type: "bluetoothDeviceFind", callback?: Callback&lt;Array&lt;string&gt;&gt;): void
Unsubscribes from the Bluetooth device discovery events.
**Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ----------------------------------- | ---- | ---------------------------------------- |
| type | string | Yes | Event type. The value **bluetoothDeviceFind** indicates an event reported when a Bluetooth device is discovered. |
| callback | Callback&lt;Array&lt;string&gt;&gt; | No | Callback for the **bluetoothDeviceFind** event. If this parameter is not set, this method unsubscribes from all callbacks corresponding to **type**.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900099 | Operation failed. |
**Example**
```js
function onReceiveEvent(data) {
console.info('bluetooth device find = '+ JSON.stringify(data));
}
try {
bluetoothManager.on('bluetoothDeviceFind', onReceiveEvent);
bluetoothManager.off('bluetoothDeviceFind', onReceiveEvent);
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
```
## bluetoothManager.on('pinRequired')
on(type: "pinRequired", callback: Callback&lt;PinRequiredParam&gt;): void
Subscribes to the pairing request events of the remote Bluetooth device.
**Required permissions**: ohos.permission.DISCOVER_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | -------------------------------- |
| type | string | Yes | Event type. The value **pinRequired** indicates a pairing request event. |
| callback | Callback&lt;[PinRequiredParam](#pinrequiredparam)&gt; | Yes | Callback invoked to return the pairing request. You need to implement this callback.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900099 | Operation failed. |
**Example**
```js
function onReceiveEvent(data) { // data is the pairing request parameter.
console.info('pin required = '+ JSON.stringify(data));
}
try {
bluetoothManager.on('pinRequired', onReceiveEvent);
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
```
## bluetoothManager.off('pinRequired')
off(type: "pinRequired", callback?: Callback&lt;PinRequiredParam&gt;): void
Unsubscribes from the pairing request events of the remote Bluetooth device.
**Required permissions**: ohos.permission.DISCOVER_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type | string | Yes | Event type. The value **pinRequired** indicates a pairing request event. |
| callback | Callback&lt;[PinRequiredParam](#pinrequiredparam)&gt; | No | Callback for the Bluetooth pairing request event. The input parameter is the pairing request parameter. If this parameter is not set, this method unsubscribes from all callbacks corresponding to **type**.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900099 | Operation failed. |
**Example**
```js
function onReceiveEvent(data) {
console.info('pin required = '+ JSON.stringify(data));
}
try {
bluetoothManager.on('pinRequired', onReceiveEvent);
bluetoothManager.off('pinRequired', onReceiveEvent);
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
```
## bluetoothManager.on('bondStateChange')
on(type: "bondStateChange", callback: Callback&lt;BondStateParam&gt;): void
Subscribes to the Bluetooth pairing state change events.
**Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ------------------------------------ |
| type | string | Yes | Event type. The value **bondStateChange** indicates a Bluetooth pairing state change event.|
| callback | Callback&lt;[BondStateParam](#BondStateParam)&gt; | Yes | Callback invoked to return the pairing state. You need to implement this callback. |
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900099 | Operation failed. |
**Example**
```js
function onReceiveEvent(data) { // data, as the input parameter of the callback, indicates the pairing state.
console.info('pair state = '+ JSON.stringify(data));
}
try {
bluetoothManager.on('bondStateChange', onReceiveEvent);
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
```
## bluetoothManager.off('bondStateChange')
off(type: "bondStateChange", callback?: Callback&lt;BondStateParam&gt;): void
Unsubscribes from the Bluetooth pairing state change events.
**Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type | string | Yes | Event type. The value **bondStateChange** indicates a Bluetooth pairing state change event. |
| callback | Callback&lt;[BondStateParam](#BondStateParam)&gt; | No | Callback for the change of the Bluetooth pairing state. If this parameter is not set, this method unsubscribes from all callbacks corresponding to **type**.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900099 | Operation failed. |
**Example**
```js
function onReceiveEvent(data) {
console.info('bond state = '+ JSON.stringify(data));
}
try {
bluetoothManager.on('bondStateChange', onReceiveEvent);
bluetoothManager.off('bondStateChange', onReceiveEvent);
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
```
## bluetoothManager.on('stateChange')
on(type: "stateChange", callback: Callback&lt;BluetoothState&gt;): void
Subscribes to the Bluetooth connection state change events.
**Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | -------------------------------- |
| type | string | Yes | Event type. The value **stateChange** indicates a Bluetooth connection state change event. |
| callback | Callback&lt;[BluetoothState](#bluetoothstate)&gt; | Yes | Callback invoked to return the Bluetooth connection state. You need to implement this callback.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900099 | Operation failed. |
**Example**
```js
function onReceiveEvent(data) {
console.info('bluetooth state = '+ JSON.stringify(data));
}
try {
bluetoothManager.on('stateChange', onReceiveEvent);
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
```
## bluetoothManager.off('stateChange')
off(type: "stateChange", callback?: Callback&lt;BluetoothState&gt;): void
Unsubscribes from the Bluetooth connection state change events.
**Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type | string | Yes | Event type. The value **stateChange** indicates a Bluetooth connection state change event. |
| callback | Callback&lt;[BluetoothState](#bluetoothstate)&gt; | No | Callback for the Bluetooth connection state change event. If this parameter is not set, this method unsubscribes from all callbacks corresponding to **type**.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900099 | Operation failed. |
**Example**
```js
function onReceiveEvent(data) {
console.info('bluetooth state = '+ JSON.stringify(data));
}
try {
bluetoothManager.on('stateChange', onReceiveEvent);
bluetoothManager.off('stateChange', onReceiveEvent);
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
```
## bluetoothManager.sppListen<a name="sppListen"></a>
sppListen(name: string, option: SppOption, callback: AsyncCallback&lt;number&gt;): void
Creates a server listening socket.
**Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | --------------------------- | ---- | ----------------------- |
| name | string | Yes | Name of the service. |
| option | [SppOption](#sppoption) | Yes | Serial port profile (SPP) listening configuration. |
| callback | AsyncCallback&lt;number&gt; | Yes | Callback invoked to return the server socket ID.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900003 | Bluetooth switch is off. |
|2900004 | Profile is not supported. |
|2900099 | Operation failed. |
**Example**
```js
let serverNumber = -1;
function serverSocket(code, number) {
console.log('bluetooth error code: ' + code.code);
if (code.code == 0) {
console.log('bluetooth serverSocket Number: ' + number);
serverNumber = number;
}
}
let sppOption = {uuid: '00001810-0000-1000-8000-00805F9B34FB', secure: false, type: 0};
try {
bluetoothManager.sppListen('server1', sppOption, serverSocket);
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
```
## bluetoothManager.sppAccept<a name="sppAccept"></a>
sppAccept(serverSocket: number, callback: AsyncCallback&lt;number&gt;): void
Listens for a connection to be made to this socket from the client and accepts it.
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ------------ | --------------------------- | ---- | ----------------------- |
| serverSocket | number | Yes | Server socket ID. |
| callback | AsyncCallback&lt;number&gt; | Yes | Callback invoked to return the client socket ID.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900003 | Bluetooth switch is off. |
|2900004 | Profile is not supported. |
|2900099 | Operation failed. |
**Example**
```js
let serverNumber = -1;
function serverSocket(code, number) {
console.log('bluetooth error code: ' + code.code);
if (code.code == 0) {
console.log('bluetooth serverSocket Number: ' + number);
serverNumber = number;
}
}
let clientNumber = -1;
function acceptClientSocket(code, number) {
console.log('bluetooth error code: ' + code.code);
if (code.code == 0) {
console.log('bluetooth clientSocket Number: ' + number);
// The obtained clientNumber is used as the socket ID for subsequent read/write operations on the server.
clientNumber = number;
}
}
try {
bluetoothManager.sppAccept(serverNumber, acceptClientSocket);
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
```
## bluetoothManager.sppConnect<a name="sppConnect"></a>
sppConnect(device: string, option: SppOption, callback: AsyncCallback&lt;number&gt;): void
Initiates an SPP connection to a remote device from the client.
**Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | --------------------------- | ---- | ------------------------------ |
| device | string | Yes | Address of the remote device, for example, XX:XX:XX:XX:XX:XX.|
| option | [SppOption](#sppoption) | Yes | Configuration for connecting to the SPP client. |
| callback | AsyncCallback&lt;number&gt; | Yes | Callback invoked to return the client socket ID. |
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900003 | Bluetooth switch is off. |
|2900004 | Profile is not supported. |
|2900099 | Operation failed. |
**Example**
```js
let clientNumber = -1;
function clientSocket(code, number) {
if (code.code != 0) {
return;
}
console.log('bluetooth serverSocket Number: ' + number);
// The obtained clientNumber is used as the socket ID for subsequent read/write operations on the client.
clientNumber = number;
}
let sppOption = {uuid: '00001810-0000-1000-8000-00805F9B34FB', secure: false, type: 0};
try {
bluetoothManager.sppConnect('XX:XX:XX:XX:XX:XX', sppOption, clientSocket);
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
```
## bluetoothManager.sppCloseServerSocket<a name="sppCloseServerSocket"></a>
sppCloseServerSocket(socket: number): void
Closes the listening socket of the server.
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | --------------- |
| socket | number | Yes | ID of the listening socket on the server. The ID is obtained by **sppListen**.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900099 | Operation failed. |
**Example**
```js
let serverNumber = -1;
function serverSocket(code, number) {
console.log('bluetooth error code: ' + code.code);
if (code.code == 0) {
console.log('bluetooth serverSocket Number: ' + number);
serverNumber = number;
}
}
try {
bluetoothManager.sppCloseServerSocket(serverNumber);
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
```
## bluetoothManager.sppCloseClientSocket<a name="sppCloseClientSocket"></a>
sppCloseClientSocket(socket: number): void
Closes the client socket.
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | ------------- |
| Name | Type | Mandatory | Description |
| socket | number | Yes | Client socket ID, which is obtained by **sppAccept** or **sppConnect**.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900099 | Operation failed. |
**Example**
```js
let clientNumber = -1;
function clientSocket(code, number) {
if (code.code != 0) {
return;
}
console.log('bluetooth serverSocket Number: ' + number);
// The obtained clientNumber is used as the socket ID for subsequent read/write operations on the client.
clientNumber = number;
}
try {
bluetoothManager.sppCloseClientSocket(clientNumber);
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
```
## bluetoothManager.sppWrite<a name="sppWrite"></a>
sppWrite(clientSocket: number, data: ArrayBuffer): void
Writes data to the remote device through the socket.
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ------------ | ----------- | ---- | ------------- |
| clientSocket | number | Yes | Client socket ID, which is obtained by **sppAccept** or **sppConnect**.|
| data | ArrayBuffer | Yes | Data to write. |
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2901054 | IO error. |
|2900099 | Operation failed. |
**Example**
```js
let clientNumber = -1;
function clientSocket(code, number) {
if (code.code != 0) {
return;
}
console.log('bluetooth serverSocket Number: ' + number);
// The obtained clientNumber is used as the socket ID for subsequent read/write operations on the client.
clientNumber = number;
}
let arrayBuffer = new ArrayBuffer(8);
let data = new Uint8Array(arrayBuffer);
data[0] = 123;
try {
bluetoothManager.sppWrite(clientNumber, arrayBuffer);
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
```
## bluetoothManager.on('sppRead')
on(type: "sppRead", clientSocket: number, callback: Callback&lt;ArrayBuffer&gt;): void
Subscribes to the SPP read request events.
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ------------ | --------------------------- | ---- | -------------------------- |
| type | string | Yes | Event type. The value **sppRead** indicates an SPP read request event.|
| clientSocket | number | Yes | Client socket ID, which is obtained by **sppAccept** or **sppConnect**. |
| callback | Callback&lt;ArrayBuffer&gt; | Yes | Callback invoked to return the data read. |
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2901054 | IO error. |
|2900099 | Operation failed. |
**Example**
```js
let clientNumber = -1;
function clientSocket(code, number) {
if (code.code != 0) {
return;
}
console.log('bluetooth serverSocket Number: ' + number);
// The obtained clientNumber is used as the socket ID for subsequent read/write operations on the client.
clientNumber = number;
}
function dataRead(dataBuffer) {
let data = new Uint8Array(dataBuffer);
console.log('bluetooth data is: ' + data[0]);
}
try {
bluetoothManager.on('sppRead', clientNumber, dataRead);
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
```
## bluetoothManager.off('sppRead')
off(type: "sppRead", clientSocket: number, callback?: Callback&lt;ArrayBuffer&gt;): void
Unsubscribes from the SPP read request events.
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ------------ | --------------------------- | ---- | ---------------------------------------- |
| type | string | Yes | Event type. The value **sppRead** indicates an SPP read request event. |
| clientSocket | number | Yes | Client socket ID, which is obtained by **sppAccept** or **sppConnect**. |
| callback | Callback&lt;ArrayBuffer&gt; | No | Callback for the SPP read request event. If this parameter is not set, this method unsubscribes from all callbacks corresponding to **type**.|
**Example**
```js
let clientNumber = -1;
function clientSocket(code, number) {
if (code.code != 0) {
return;
}
console.log('bluetooth serverSocket Number: ' + number);
// The obtained clientNumber is used as the socket ID for subsequent read/write operations on the client.
clientNumber = number;
}
try {
bluetoothManager.off('sppRead', clientNumber);
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
```
## bluetoothManager.getProfileInstance<a name="getProfileInstance"></a>
getProfileInstance(profileId: ProfileId): A2dpSourceProfile | HandsFreeAudioGatewayProfile | HidHostProfile | PanProfile
Obtains a profile instance. API version 9 is added with **HidHostProfile** and **PanProfile**.
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| --------- | --------- | ---- | ------------------------------------- |
| profileId | [ProfileId](#ProfileId) | Yes | ID of the profile to obtain, for example, **PROFILE_A2DP_SOURCE**.|
**Return value**
| Type | Description |
| ------------------------------------------------------------ | ------------------------------------------------------------ |
| [A2dpSourceProfile](#a2dpsourceprofile), [HandsFreeAudioGatewayProfile](#handsfreeaudiogatewayprofile), [HidHostProfile](#hidhostprofile), or [PanProfile](#panprofile)| Profile instance obtained, which can be **A2dpSourceProfile**, **HandsFreeAudioGatewayProfile**, **HidHostProfile**, or **PanProfile**.|
**Example**
```js
try {
let hidHost = bluetoothManager.getProfileInstance(bluetoothManager.ProfileId.PROFILE_HID_HOST);
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
```
## bluetoothManager.BLE
### bluetoothManager.BLE.createGattServer
createGattServer(): GattServer
Creates a **GattServer** instance.
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Return value**
| Type | Description |
| ------------------------- | ------------------------------------ |
| [GattServer](#gattserver) | **GattServer** instance created. Before using an API of the server, you must create a **GattSever** instance.|
**Example**
```js
let gattServer = bluetoothManager.BLE.createGattServer();
```
### bluetoothManager.BLE.createGattClientDevice
createGattClientDevice(deviceId: string): GattClientDevice
Creates a **GattClientDevice** instance.
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ------ | ---- | ------------------------------------ |
| deviceId | string | Yes | Address of the remote device, for example, XX:XX:XX:XX:XX:XX.|
**Return value**
| Type | Description |
| ------------------------------------- | ------------------------------------ |
| [GattClientDevice](#gattclientdevice) | **GattClientDevice** instance created. Before using an API of the client, you must create a **GattClientDevice** instance.|
**Example**
```js
try {
let device = bluetoothManager.BLE.createGattClientDevice('XX:XX:XX:XX:XX:XX');
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
```
### bluetoothManager.BLE.getConnectedBLEDevices
getConnectedBLEDevices(): Array&lt;string&gt;
Obtains the BLE devices connected to this device.
**Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Return value**
| Type | Description |
| ------------------- | ------------------- |
| Array&lt;string&gt; | Addresses of the BLE devices connected to this device.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900003 | Bluetooth switch is off. |
|2900099 | Operation failed. |
**Example**
```js
try {
let result = bluetoothManager.BLE.getConnectedBLEDevices();
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
```
### bluetoothManager.BLE.startBLEScan
startBLEScan(filters: Array&lt;ScanFilter&gt;, options?: ScanOptions): void
Starts a BLE scan.
**Required permissions**: ohos.permission.DISCOVER_BLUETOOTH, ohos.permission.MANAGE_BLUETOOTH, ohos.permission.LOCATION, and ohos.permission.APPROXIMATELY_LOCATION
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ------- | -------------------------------------- | ---- | ----------------------------------- |
| filters | Array&lt;[ScanFilter](#scanfilter)&gt; | Yes | Criteria for filtering the scan result. Set this parameter to **null** if you do not want to filter the scan result.|
| options | [ScanOptions](#scanoptions) | No | Scan options. |
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900003 | Bluetooth switch is off. |
|2900099 | Operation failed. |
**Example**
```js
function onReceiveEvent(data) {
console.info('BLE scan device find result = '+ JSON.stringify(data));
}
try {
bluetoothManager.BLE.on("BLEDeviceFind", onReceiveEvent);
bluetoothManager.BLE.startBLEScan(
[{
deviceId:"XX:XX:XX:XX:XX:XX",
name:"test",
serviceUuid:"00001888-0000-1000-8000-00805f9b34fb"
}],
{
interval: 500,
dutyMode: bluetoothManager.ScanDuty.SCAN_MODE_LOW_POWER,
matchMode: bluetoothManager.MatchMode.MATCH_MODE_AGGRESSIVE,
}
);
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
```
### bluetoothManager.BLE.stopBLEScan
stopBLEScan(): void
Stops the BLE scan.
**Required permissions**: ohos.permission.DISCOVER_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900003 | Bluetooth switch is off. |
|2900099 | Operation failed. |
**Example**
```js
try {
bluetoothManager.BLE.stopBLEScan();
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
```
### bluetoothManager.BLE.on('BLEDeviceFind')
on(type: "BLEDeviceFind", callback: Callback&lt;Array&lt;ScanResult&gt;&gt;): void
Subscribe to the BLE device discovery events.
**Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ----------------------------------- |
| type | string | Yes | Event type. The value **BLEDeviceFind** indicates an event reported when a BLE device is discovered. |
| callback | Callback&lt;Array&lt;[ScanResult](#scanresult)&gt;&gt; | Yes | Callback invoked to return the discovered devices. You need to implement this callback.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900099 | Operation failed. |
**Example**
```js
function onReceiveEvent(data) {
console.info('bluetooth device find = '+ JSON.stringify(data));
}
try {
bluetoothManager.BLE.on('BLEDeviceFind', onReceiveEvent);
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
```
### bluetoothManager.BLE.off('BLEDeviceFind')
off(type: "BLEDeviceFind", callback?: Callback&lt;Array&lt;ScanResult&gt;&gt;): void
Unsubscribes from the BLE device discovery events.
**Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type | string | Yes | Event type. The value **BLEDeviceFind** indicates an event reported when a BLE device is discovered. |
| callback | Callback&lt;Array&lt;[ScanResult](#scanresult)&gt;&gt; | No | Callback for the **BLEDeviceFind** event. If this parameter is not set, this method unsubscribes from all callbacks corresponding to **type**.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900099 | Operation failed. |
**Example**
```js
function onReceiveEvent(data) {
console.info('bluetooth device find = '+ JSON.stringify(data));
}
try {
bluetoothManager.BLE.on('BLEDeviceFind', onReceiveEvent);
bluetoothManager.BLE.off('BLEDeviceFind', onReceiveEvent);
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
```
## BaseProfile
Provides the profile base class.
### getConnectionDevices<a name="getConnectionDevices"></a>
getConnectionDevices(): Array&lt;string&gt;
Obtains the connected devices.
**Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Return value**
| Type | Description |
| ------------------- | ------------- |
| Array&lt;string&gt; | Addresses of the connected devices.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900003 | Bluetooth switch is off. |
|2900004 | Profile is not supported. |
|2900099 | Operation failed. |
**Example**
```js
try {
let a2dpSrc = bluetoothManager.getProfileInstance(bluetoothManager.ProfileId.PROFILE_A2DP_SOURCE) as bluetoothManager.A2dpSourceProfile;
let retArray = a2dpSrc.getConnectionDevices();
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
```
### getDeviceState<a name="getDeviceState"></a>
getDeviceState(device: string): ProfileConnectionState
Obtains the connection state of the profile.
**Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | ------- |
| device | string | Yes | Address of the target device.|
**Return value**
| Type | Description |
| ------------------------------------------------- | ----------------------- |
| [ProfileConnectionState](#profileconnectionstate) | Profile connection state obtained.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900003 | Bluetooth switch is off. |
|2900004 | Profile is not supported. |
|2900099 | Operation failed. |
**Example**
```js
try {
let a2dpSrc = bluetoothManager.getProfileInstance(bluetoothManager.ProfileId.PROFILE_A2DP_SOURCE) as bluetoothManager.A2dpSourceProfile;
let ret = a2dpSrc.getDeviceState('XX:XX:XX:XX:XX:XX');
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
```
## A2dpSourceProfile
Before using an API of **A2dpSourceProfile**, you need to create an instance of this class by using **getProfile()**.
### connect<a name="a2dp-connect"></a>
connect(device: string): void
Sets up an Advanced Audio Distribution Profile (A2DP) connection.
**Required permissions**: ohos.permission.DISCOVER_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | ------- |
| device | string | Yes | Address of the target device.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900003 | Bluetooth switch is off. |
|2900004 | Profile is not supported. |
|2900099 | Operation failed. |
**Example**
```js
try {
let a2dpSrc = bluetoothManager.getProfileInstance(bluetoothManager.ProfileId.PROFILE_A2DP_SOURCE) as bluetoothManager.A2dpSourceProfile;
a2dpSrc.connect('XX:XX:XX:XX:XX:XX');
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
```
### disconnect<a name="a2dp-disconnect"></a>
disconnect(device: string): void
Disconnects an A2DP connection.
**Required permissions**: ohos.permission.DISCOVER_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | ------- |
| device | string | Yes | Address of the target device.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900003 | Bluetooth switch is off. |
|2900004 | Profile is not supported. |
|2900099 | Operation failed. |
**Example**
```js
try {
let a2dpSrc = bluetoothManager.getProfileInstance(bluetoothManager.ProfileId.PROFILE_A2DP_SOURCE) as bluetoothManager.A2dpSourceProfile;
a2dpSrc.disconnect('XX:XX:XX:XX:XX:XX');
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
```
### on('connectionStateChange')
on(type: "connectionStateChange", callback: Callback&lt;[StateChangeParam](#StateChangeParam)&gt;): void
Subscribes to the A2DP connection state change events.
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type | string | Yes | Event type. The value **connectionStateChange** indicates an A2DP connection state change event.|
| callback | Callback&lt;[StateChangeParam](#StateChangeParam)&gt; | Yes | Callback invoked to return the A2DP connection state change event. |
**Return value**
No value is returned.
**Example**
```js
function onReceiveEvent(data) {
console.info('a2dp state = '+ JSON.stringify(data));
}
let a2dpSrc = bluetoothManager.getProfileInstance(bluetoothManager.ProfileId.PROFILE_A2DP_SOURCE) as bluetoothManager.A2dpSourceProfile;
a2dpSrc.on('connectionStateChange', onReceiveEvent);
```
### off('connectionStateChange')
off(type: "connectionStateChange", callback?: Callback&lt;[StateChangeParam](#StateChangeParam)&gt;): void
Unsubscribes from the A2DP connection state change events.
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type | string | Yes | Event type. The value **connectionStateChange** indicates an A2DP connection state change event.|
| callback | Callback&lt;[StateChangeParam](#StateChangeParam)&gt; | No | Callback for the A2DP connection state change event. |
**Return value**
No value is returned.
**Example**
```js
function onReceiveEvent(data) {
console.info('a2dp state = '+ JSON.stringify(data));
}
let a2dpSrc = bluetoothManager.getProfileInstance(bluetoothManager.ProfileId.PROFILE_A2DP_SOURCE) as bluetoothManager.A2dpSourceProfile;
a2dpSrc.on('connectionStateChange', onReceiveEvent);
a2dpSrc.off('connectionStateChange', onReceiveEvent);
```
### getPlayingState
getPlayingState(device: string): PlayingState
Obtains the playing state of a device.
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | ------- |
| device | string | Yes | Address of the target device.|
**Return value**
| Type | Description |
| ----------------------------- | ---------- |
| [PlayingState](#PlayingState) | Playing state of the remote device obtained.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900003 | Bluetooth switch is off. |
|2900004 | Profile is not supported. |
|2900099 | Operation failed. |
**Example**
```js
try {
let a2dpSrc = bluetoothManager.getProfileInstance(bluetoothManager.ProfileId.PROFILE_A2DP_SOURCE) as bluetoothManager.A2dpSourceProfile;
let state = a2dpSrc.getPlayingState('XX:XX:XX:XX:XX:XX');
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
```
## HandsFreeAudioGatewayProfile
Before using an API of **HandsFreeAudioGatewayProfile**, you need to create an instance of this class by using **getProfile()**.
### connect<a name="hfp-connect"></a>
connect(device: string): void
Sets up a Hands-free Profile (HFP) connection of a device.
**Required permissions**: ohos.permission.DISCOVER_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | ------- |
| device | string | Yes | Address of the target device.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900003 | Bluetooth switch is off. |
|2900004 | Profile is not supported. |
|2900099 | Operation failed. |
**Example**
```js
try {
let hfpAg = bluetoothManager.getProfileInstance(bluetoothManager.ProfileId.PROFILE_HANDS_FREE_AUDIO_GATEWAY) as bluetoothManager.HandsFreeAudioGatewayProfile;
hfpAg.connect('XX:XX:XX:XX:XX:XX');
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
```
### disconnect<a name="hfp-disconnect"></a>
disconnect(device: string): void
Disconnects the HFP connection of a device.
**Required permissions**: ohos.permission.DISCOVER_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | ------- |
| device | string | Yes | Address of the target device.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900003 | Bluetooth switch is off. |
|2900004 | Profile is not supported. |
|2900099 | Operation failed. |
**Example**
```js
try {
let hfpAg = bluetoothManager.getProfileInstance(bluetoothManager.ProfileId.PROFILE_HANDS_FREE_AUDIO_GATEWAY) as bluetoothManager.HandsFreeAudioGatewayProfile;
hfpAg.disconnect('XX:XX:XX:XX:XX:XX');
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
```
### on('connectionStateChange')
on(type: "connectionStateChange", callback: Callback&lt;[StateChangeParam](#StateChangeParam)&gt;): void
Subscribes to the HFP connection state change events.
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type | string | Yes | Event type. The value **connectionStateChange** indicates an HFP connection state change event. |
| callback | Callback&lt;[StateChangeParam](#StateChangeParam)&gt; | Yes | Callback invoked to return the HFP connection state change event. |
**Example**
```js
function onReceiveEvent(data) {
console.info('hfp state = '+ JSON.stringify(data));
}
let hfpAg = bluetoothManager.getProfileInstance(bluetoothManager.ProfileId.PROFILE_HANDS_FREE_AUDIO_GATEWAY) as
bluetoothManager.HandsFreeAudioGatewayProfile;
hfpAg.on('connectionStateChange', onReceiveEvent);
```
### off('connectionStateChange')
off(type: "connectionStateChange", callback?: Callback&lt;[StateChangeParam](#StateChangeParam)&gt;): void
Unsubscribes from the HFP connection state change events.
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type | string | Yes | Event type. The value **connectionStateChange** indicates an HFP connection state change event. |
| callback | Callback&lt;[StateChangeParam](#StateChangeParam)&gt; | No | Callback for the HFP connection state change event. |
**Example**
```js
function onReceiveEvent(data) {
console.info('hfp state = '+ JSON.stringify(data));
}
let hfpAg = bluetoothManager.getProfileInstance(bluetoothManager.ProfileId.PROFILE_HANDS_FREE_AUDIO_GATEWAY) as
bluetoothManager.HandsFreeAudioGatewayProfile;
hfpAg.on('connectionStateChange', onReceiveEvent);
hfpAg.off('connectionStateChange', onReceiveEvent);
```
## HidHostProfile
Before using an API of **HidHostProfile**, you need to create an instance of this class by using **getProfile()**.
### connect<a name="HidHost-connect"></a>
connect(device: string): void
Connects to the HidHost service of a device.
**System API**: This is a system API.
**Required permissions**: ohos.permission.DISCOVER_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | ------- |
| device | string | Yes | Address of the target device.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900003 | Bluetooth switch is off. |
|2900004 | Profile is not supported. |
|2900099 | Operation failed. |
**Example**
```js
try {
let hidHostProfile = bluetoothManager.getProfileInst(bluetoothManager.ProfileId.PROFILE_HID_HOST) as bluetoothManager.HidHostProfile;
hidHostProfile.connect('XX:XX:XX:XX:XX:XX');
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
```
### disconnect<a name="HidHost-disconnect"></a>
disconnect(device: string): void
Disconnects from the HidHost service of a device.
**System API**: This is a system API.
**Required permissions**: ohos.permission.DISCOVER_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | ------- |
| device | string | Yes | Address of the target device.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900003 | Bluetooth switch is off. |
|2900004 | Profile is not supported. |
|2900099 | Operation failed. |
**Example**
```js
try {
let hidHostProfile = bluetoothManager.getProfileInst(bluetoothManager.ProfileId.PROFILE_HID_HOST) as bluetoothManager.HidHostProfile;
hidHostProfile.disconnect('XX:XX:XX:XX:XX:XX');
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
```
### on('connectionStateChange')
on(type: "connectionStateChange", callback: Callback&lt;[StateChangeParam](#StateChangeParam)&gt;): void
Subscribes to the HidHost connection state change events.
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type | string | Yes | Event type. The value **connectionStateChange** indicates a HidHost connection state change event. |
| callback | Callback&lt;[StateChangeParam](#StateChangeParam)&gt; | Yes | Callback invoked to return the HidHost connection state change event. |
**Example**
```js
function onReceiveEvent(data) {
console.info('hidHost state = '+ JSON.stringify(data));
}
let hidHost = bluetoothManager.getProfileInst(bluetoothManager.ProfileId.PROFILE_HID_HOST) as bluetoothManager.HidHostProfile;
hidHost.on('connectionStateChange', onReceiveEvent);
```
### off('connectionStateChange')
off(type: "connectionStateChange", callback?: Callback&lt;[StateChangeParam](#StateChangeParam)&gt;): void
Unsubscribes from the HidHost connection state change events.
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------------------------------------- | ---- | --------------------------------------------------------- |
| type | string | Yes | Event type. The value **connectionStateChange** indicates a HidHost connection state change event. |
| callback | Callback&lt;[StateChangeParam](#StateChangeParam)&gt; | No | Callback for the HidHost connection state change event. |
**Example**
```js
function onReceiveEvent(data) {
console.info('hidHost state = '+ JSON.stringify(data));
}
let hidHost = bluetoothManager.getProfileInst(bluetoothManager.ProfileId.PROFILE_HID_HOST) as bluetoothManager.HidHostProfile;
hidHost.on('connectionStateChange', onReceiveEvent);
hidHost.off('connectionStateChange', onReceiveEvent);
```
## PanProfile
Before using an API of **PanProfile**, you need to create an instance of this class by using **getProfile()**.
### disconnect<a name="PanP-disconnect"></a>
disconnect(device: string): void
Disconnects from the Personal Area Network (PAN) service of a device.
**System API**: This is a system API.
**Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | ------- |
| device | string | Yes | Address of the target device.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900003 | Bluetooth switch is off. |
|2900004 | Profile is not supported. |
|2900099 | Operation failed. |
**Example**
```js
try {
let panProfile = bluetoothManager.getProfileInst(bluetoothManager.ProfileId.PROFILE_PAN_NETWORK) as bluetoothManager.PanProfile;
panProfile.disconnect('XX:XX:XX:XX:XX:XX');
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
```
### on('connectionStateChange')
on(type: "connectionStateChange", callback: Callback&lt;[StateChangeParam](#StateChangeParam)&gt;): void
Subscribes to the PAN connection state change events.
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type | string | Yes | Event type. The value **connectionStateChange** indicates a PAN connection state change event. |
| callback | Callback&lt;[StateChangeParam](#StateChangeParam)&gt; | Yes | Callback invoked to return the PAN connection state change event. |
**Example**
```js
function onReceiveEvent(data) {
console.info('pan state = '+ JSON.stringify(data));
}
let panProfile = bluetoothManager.getProfileInst(bluetoothManager.ProfileId.PROFILE_PAN_NETWORK) as bluetoothManager.PanProfile;
panProfile.on('connectionStateChange', onReceiveEvent);
```
### off('connectionStateChange')
off(type: "connectionStateChange", callback?: Callback&lt;[StateChangeParam](#StateChangeParam)&gt;): void
Unsubscribes from the PAN connection state change events.
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------------------------------------- | ---- | --------------------------------------------------------- |
| type | string | Yes | Event type. The value **connectionStateChange** indicates a PAN connection state change event. |
| callback | Callback&lt;[StateChangeParam](#StateChangeParam)&gt; | No | Callback for the PAN connection state change event. |
**Example**
```js
function onReceiveEvent(data) {
console.info('pan state = '+ JSON.stringify(data));
}
let panProfile = bluetoothManager.getProfileInst(bluetoothManager.ProfileId.PROFILE_PAN_NETWORK) as bluetoothManager.PanProfile;
panProfile.on('connectionStateChange', onReceiveEvent);
panProfile.off('connectionStateChange', onReceiveEvent);
```
### setTethering<a name="setTethering"></a>
setTethering(enable: boolean): void
Sets tethering.
**System API**: This is a system API.
**Required permissions**: ohos.permission.DISCOVER_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | ------- |
| value | boolean | Yes | Whether to set tethering over a Bluetooth PAN.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900003 | Bluetooth switch is off. |
|2900004 | Profile is not supported. |
|2900099 | Operation failed. |
**Example**
```js
try {
let panProfile = bluetoothManager.getProfileInst(bluetoothManager.ProfileId.PROFILE_PAN_NETWORK) as bluetoothManager.PanProfile;
panProfile.setTethering(true);
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
```
### isTetheringOn<a name="isTetheringOn"></a>
isTetheringOn(): boolean
Obtains the network sharing status.
**System API**: This is a system API.
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Return value**
| Type | Description |
| --------------------- | --------------------------------- |
| boolean | Returns **true** if tethering is available over a Bluetooth PAN; return **false** otherwise.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900003 | Bluetooth switch is off. |
|2900004 | Profile is not supported. |
|2900099 | Operation failed. |
**Example**
```js
try {
let panProfile = bluetoothManager.getProfileInst(bluetoothManager.ProfileId.PROFILE_PAN_NETWORK) as bluetoothManager.PanProfile;
let ret = panProfile.isTetheringOn();
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
```
## GattServer
Implements the Generic Attribute Profile (GATT) server. Before using an API of this class, you need to create a **GattServer** instance using **createGattServer()**.
### startAdvertising
startAdvertising(setting: AdvertiseSetting, advData: AdvertiseData, advResponse?: AdvertiseData): void
Starts BLE advertising.
**Required permissions**: ohos.permission.DISCOVER_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ----------- | ------------------------------------- | ---- | -------------- |
| setting | [AdvertiseSetting](#advertisesetting) | Yes | Settings related to BLE advertising. |
| advData | [AdvertiseData](#advertisedata) | Yes | Content of the BLE advertisement packet. |
| advResponse | [AdvertiseData](#advertisedata) | No | Response to the BLE scan request.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900003 | Bluetooth switch is off. |
|2900099 | Operation failed. |
**Example**
```js
let manufactureValueBuffer = new Uint8Array(4);
manufactureValueBuffer[0] = 1;
manufactureValueBuffer[1] = 2;
manufactureValueBuffer[2] = 3;
manufactureValueBuffer[3] = 4;
let serviceValueBuffer = new Uint8Array(4);
serviceValueBuffer[0] = 4;
serviceValueBuffer[1] = 6;
serviceValueBuffer[2] = 7;
serviceValueBuffer[3] = 8;
console.info('manufactureValueBuffer = '+ JSON.stringify(manufactureValueBuffer));
console.info('serviceValueBuffer = '+ JSON.stringify(serviceValueBuffer));
let gattServer = bluetoothManager.BLE.createGattServer();
try {
gattServer.startAdvertising({
interval:150,
txPower:60,
connectable:true,
},{
serviceUuids:["00001888-0000-1000-8000-00805f9b34fb"],
manufactureData:[{
manufactureId:4567,
manufactureValue:manufactureValueBuffer.buffer
}],
serviceData:[{
serviceUuid:"00001888-0000-1000-8000-00805f9b34fb",
serviceValue:serviceValueBuffer.buffer
}],
},{
serviceUuids:["00001889-0000-1000-8000-00805f9b34fb"],
manufactureData:[{
manufactureId:1789,
manufactureValue:manufactureValueBuffer.buffer
}],
serviceData:[{
serviceUuid:"00001889-0000-1000-8000-00805f9b34fb",
serviceValue:serviceValueBuffer.buffer
}],
});
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
```
### stopAdvertising
stopAdvertising(): void
Stops BLE advertising.
**Required permissions**: ohos.permission.DISCOVER_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900003 | Bluetooth switch is off. |
|2900099 | Operation failed. |
**Example**
```js
let server = bluetoothManager.BLE.createGattServer();
try {
server.stopAdvertising();
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
```
### addService
addService(service: GattService): void
Adds a service to this GATT server.
**Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ------- | --------------------------- | ---- | ------------------------ |
| service | [GattService](#gattservice) | Yes | Service to add. Settings related to BLE advertising.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900003 | Bluetooth switch is off. |
|2900099 | Operation failed. |
**Example**
```js
// Create descriptors.
let descriptors = [];
let arrayBuffer = new ArrayBuffer(8);
let descV = new Uint8Array(arrayBuffer);
descV[0] = 11;
let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
descriptorUuid: '00002902-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer};
descriptors[0] = descriptor;
// Create characteristics.
let characteristics = [];
let arrayBufferC = new ArrayBuffer(8);
let cccV = new Uint8Array(arrayBufferC);
cccV[0] = 1;
let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', characteristicValue: arrayBufferC, descriptors:descriptors};
let characteristicN = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
characteristicUuid: '00001821-0000-1000-8000-00805F9B34FB', characteristicValue: arrayBufferC, descriptors:descriptors};
characteristics[0] = characteristic;
// Create a gattService instance.
let gattService = {serviceUuid:'00001810-0000-1000-8000-00805F9B34FB', isPrimary: true, characteristics:characteristics, includeServices:[]};
let gattServer = bluetoothManager.BLE.createGattServer();
try {
gattServer.addService(gattService);
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
```
### removeService
removeService(serviceUuid: string): void
Removes a service from this GATT server.
**Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ----------- | ------ | ---- | ---------------------------------------- |
| serviceUuid | string | Yes | Universally unique identifier (UUID) of the service to remove, for example, **00001810-0000-1000-8000-00805F9B34FB**.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900003 | Bluetooth switch is off. |
|2900004 | Profile is not supported. |
|2900099 | Operation failed. |
**Example**
```js
let server = bluetoothManager.BLE.createGattServer();
try {
server.removeService('00001810-0000-1000-8000-00805F9B34FB');
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
```
### close
close(): void
Closes this GATT server to unregister it from the protocol stack. After this method is called, this [GattServer](#gattserver) cannot be used.
**Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900003 | Bluetooth switch is off. |
|2900099 | Operation failed. |
**Example**
```js
let server = bluetoothManager.BLE.createGattServer();
try {
server.close();
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
```
### notifyCharacteristicChanged
notifyCharacteristicChanged(deviceId: string, notifyCharacteristic: NotifyCharacteristic): void
Notifies the connected client device when a characteristic value changes.
**Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------------------- | ---------------------------------------- | ---- | --------------------------------------- |
| deviceId | string | Yes | Address of the client that receives notifications, for example, XX:XX:XX:XX:XX:XX.|
| notifyCharacteristic | [NotifyCharacteristic](#notifycharacteristic) | Yes | New characteristic value. |
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900003 | Bluetooth switch is off. |
|2900099 | Operation failed. |
**Example**
```js
// Create descriptors.
let descriptors = [];
let arrayBuffer = new ArrayBuffer(8);
let descV = new Uint8Array(arrayBuffer);
descV[0] = 11;
let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
descriptorUuid: '00002902-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer};
descriptors[0] = descriptor;
let arrayBufferC = new ArrayBuffer(8);
let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', characteristicValue: arrayBufferC, descriptors:descriptors};
let notifyCharacteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
characteristicUuid: '00001821-0000-1000-8000-00805F9B34FB', characteristicValue: characteristic.characteristicValue, confirm: false};
let server = bluetoothManager.BLE.createGattServer();
try {
server.notifyCharacteristicChanged('XX:XX:XX:XX:XX:XX', notifyCharacteristic);
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
```
### sendResponse
sendResponse(serverResponse: ServerResponse): void
Sends a response to a read or write request from the GATT client.
**Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------------- | --------------------------------- | ---- | --------------- |
| serverResponse | [ServerResponse](#serverresponse) | Yes | Response returned by the GATT server.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900003 | Bluetooth switch is off. |
|2900099 | Operation failed. |
**Example**
```js
/* send response */
let arrayBufferCCC = new ArrayBuffer(8);
let cccValue = new Uint8Array(arrayBufferCCC);
cccValue[0] = 1123;
let serverResponse = {
"deviceId": "XX:XX:XX:XX:XX:XX",
"transId": 0,
"status": 0,
"offset": 0,
"value": arrayBufferCCC,
};
let gattServer = bluetoothManager.BLE.createGattServer();
try {
gattServer.sendResponse(serverResponse);
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
```
### on('characteristicRead')
on(type: "characteristicRead", callback: Callback&lt;CharacteristicReadRequest&gt;): void
Subscribes to the characteristic read request events.
**Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ------------------------------------- |
| type | string | Yes | Event type. The value **characteristicRead** indicates a characteristic read request event.|
| callback | Callback&lt;[CharacteristicReadRequest](#characteristicreadrequest)&gt; | Yes | Callback invoked to return a characteristic read request event from the GATT client. |
**Example**
```js
let arrayBufferCCC = new ArrayBuffer(8);
let cccValue = new Uint8Array(arrayBufferCCC);
cccValue[0] = 1123;
function ReadCharacteristicReq(CharacteristicReadRequest) {
let deviceId = CharacteristicReadRequest.deviceId;
let transId = CharacteristicReadRequest.transId;
let offset = CharacteristicReadRequest.offset;
let characteristicUuid = CharacteristicReadRequest.characteristicUuid;
let serverResponse = {deviceId: deviceId, transId: transId, status: 0, offset: offset, value:arrayBufferCCC};
try {
gattServer.sendResponse(serverResponse);
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
}
let gattServer = bluetoothManager.BLE.createGattServer();
gattServer.on("characteristicRead", ReadCharacteristicReq);
```
### off('characteristicRead')
off(type: "characteristicRead", callback?: Callback&lt;CharacteristicReadRequest&gt;): void
Unsubscribes from the characteristic read request events.
**Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type | string | Yes | Event type. The value **characteristicRead** indicates a characteristic read request event. |
| callback | Callback&lt;[CharacteristicReadRequest](#characteristicreadrequest)&gt; | No | Callback for the characteristic read request event. If this parameter is not set, this method unsubscribes from all callbacks corresponding to **type**.|
**Example**
```js
let gattServer = bluetoothManager.BLE.createGattServer();
gattServer.off("characteristicRead");
```
### on('characteristicWrite')
on(type: "characteristicWrite", callback: Callback&lt;CharacteristicWriteRequest&gt;): void
Subscribes to the characteristic write request events.
**Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | -------------------------------------- |
| type | string | Yes | Event type. The value **characteristicWrite** indicates a characteristic write request event.|
| callback | Callback&lt;[CharacteristicWriteRequest](#characteristicwriterequest)&gt; | Yes | Callback invoked to return a characteristic write request from the GATT client. |
**Example**
```js
let arrayBufferCCC = new ArrayBuffer(8);
let cccValue = new Uint8Array(arrayBufferCCC);
function WriteCharacteristicReq(CharacteristicWriteRequest) {
let deviceId = CharacteristicWriteRequest.deviceId;
let transId = CharacteristicWriteRequest.transId;
let offset = CharacteristicWriteRequest.offset;
let isPrep = CharacteristicWriteRequest.isPrep;
let needRsp = CharacteristicWriteRequest.needRsp;
let value = new Uint8Array(CharacteristicWriteRequest.value);
let characteristicUuid = CharacteristicWriteRequest.characteristicUuid;
cccValue[0] = value[0];
let serverResponse = {deviceId: deviceId, transId: transId, status: 0, offset: offset, value:arrayBufferCCC};
try {
gattServer.sendResponse(serverResponse);
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
}
let gattServer = bluetoothManager.BLE.createGattServer();
gattServer.on("characteristicWrite", WriteCharacteristicReq);
```
### off('characteristicWrite')
off(type: "characteristicWrite", callback?: Callback&lt;CharacteristicWriteRequest&gt;): void
Unsubscribes from the characteristic write request events.
**Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type | string | Yes | Event type. The value **characteristicWrite** indicates a characteristic write request event. |
| callback | Callback&lt;[CharacteristicWriteRequest](#characteristicwriterequest)&gt; | No | Callback for the characteristic write request event. If this parameter is not set, this method unsubscribes from all callbacks corresponding to **type**.|
**Example**
```js
let gattServer = bluetoothManager.BLE.createGattServer();
gattServer.off("characteristicWrite");
```
### on('descriptorRead')
on(type: "descriptorRead", callback: Callback&lt;DescriptorReadRequest&gt;): void
Subscribes to the descriptor read request events.
**Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | --------------------------------- |
| type | string | Yes | Event type. The value **descriptorRead** indicates a descriptor read request event.|
| callback | Callback&lt;[DescriptorReadRequest](#descriptorreadrequest)&gt; | Yes | Callback invoked to return a descriptor read request event from the GATT client. |
**Example**
```js
let arrayBufferDesc = new ArrayBuffer(8);
let descValue = new Uint8Array(arrayBufferDesc);
descValue[0] = 1101;
function ReadDescriptorReq(DescriptorReadRequest) {
let deviceId = DescriptorReadRequest.deviceId;
let transId = DescriptorReadRequest.transId;
let offset = DescriptorReadRequest.offset;
let descriptorUuid = DescriptorReadRequest.descriptorUuid;
let serverResponse = {deviceId: deviceId, transId: transId, status: 0, offset: offset, value:arrayBufferDesc};
try {
gattServer.sendResponse(serverResponse);
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
}
let gattServer = bluetoothManager.BLE.createGattServer();
gattServer.on("descriptorRead", ReadDescriptorReq);
```
### off('descriptorRead')
off(type: "descriptorRead", callback?: Callback&lt;DescriptorReadRequest&gt;): void
Unsubscribes from the descriptor read request events.
**Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type | string | Yes | Event type. The value **descriptorRead** indicates a descriptor read request event. |
| callback | Callback&lt;[DescriptorReadRequest](#descriptorreadrequest)&gt; | No | Callback for the descriptor read request event. If this parameter is not set, this method unsubscribes from all callbacks corresponding to **type**.|
**Example**
```js
let gattServer = bluetoothManager.BLE.createGattServer();
gattServer.off("descriptorRead");
```
### on('descriptorWrite')
on(type: "descriptorWrite", callback: Callback&lt;DescriptorWriteRequest&gt;): void
Subscribes to the descriptor write request events.
**Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ---------------------------------- |
| type | string | Yes | Event type. The value **descriptorWrite** indicates a descriptor write request event.|
| callback | Callback&lt;[DescriptorWriteRequest](#descriptorwriterequest)&gt; | Yes | Callback invoked to return a descriptor write request from the GATT client. |
**Example**
```js
let arrayBufferDesc = new ArrayBuffer(8);
let descValue = new Uint8Array(arrayBufferDesc);
function WriteDescriptorReq(DescriptorWriteRequest) {
let deviceId = DescriptorWriteRequest.deviceId;
let transId = DescriptorWriteRequest.transId;
let offset = DescriptorWriteRequest.offset;
let isPrep = DescriptorWriteRequest.isPrep;
let needRsp = DescriptorWriteRequest.needRsp;
let value = new Uint8Array(DescriptorWriteRequest.value);
let descriptorUuid = DescriptorWriteRequest.descriptorUuid;
descValue[0] = value[0];
let serverResponse = {deviceId: deviceId, transId: transId, status: 0, offset: offset, value:arrayBufferDesc};
try {
gattServer.sendResponse(serverResponse);
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
}
let gattServer = bluetoothManager.BLE.createGattServer();
gattServer.on("descriptorRead", WriteDescriptorReq);
```
### off('descriptorWrite')
off(type: "descriptorWrite", callback?: Callback&lt;DescriptorWriteRequest&gt;): void
Unsubscribes from the descriptor write request events.
**Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type | string | Yes | Event type. The value **descriptorWrite** indicates a descriptor write request event. |
| callback | Callback&lt;[DescriptorWriteRequest](#descriptorwriterequest)&gt; | No | Callback for the descriptor write request event. If this parameter is not set, this method unsubscribes from all callbacks corresponding to **type**.|
**Example**
```js
let gattServer = bluetoothManager.BLE.createGattServer();
gattServer.off("descriptorWrite");
```
### on('connectStateChange')
on(type: "connectStateChange", callback: Callback&lt;BLEConnectChangedState&gt;): void
Subscribes to the BLE connection state change events.
**Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type | string | Yes | Event type. The value **connectStateChange** indicates a BLE connection state change event.|
| callback | Callback&lt;[BLEConnectChangedState](#bleconnectchangedstate)&gt; | Yes | Callback invoked to return the BLE connection state. |
**Example**
```js
function Connected(BLEConnectChangedState) {
let deviceId = BLEConnectChangedState.deviceId;
let status = BLEConnectChangedState.state;
}
let gattServer = bluetoothManager.BLE.createGattServer();
gattServer.on("connectStateChange", Connected);
```
### off('connectStateChange')
off(type: "connectStateChange", callback?: Callback&lt;BLEConnectChangedState&gt;): void
Unsubscribes from the BLE connection state change events.
**Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type | string | Yes | Event type. The value **connectStateChange** indicates a BLE connection state change event.|
| callback | Callback&lt;[BLEConnectChangedState](#bleconnectchangedstate)&gt; | No | Callback for the BLE connection state change event. If this parameter is not set, this method unsubscribes from all callbacks corresponding to **type**.|
**Example**
```js
let gattServer = bluetoothManager.BLE.createGattServer();
gattServer.off("connectStateChange");
```
## GattClientDevice
Implements the GATT client. Before using an API of this class, you must create a **GattClientDevice** instance using **createGattClientDevice(deviceId: string)**.
### connect
connect(): void
Initiates a connection to the remote BLE device.
**Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900003 | Bluetooth switch is off. |
|2900099 | Operation failed. |
**Example**
```js
try {
let device = bluetoothManager.BLE.createGattClientDevice('XX:XX:XX:XX:XX:XX');
device.connect();
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
```
### disconnect
disconnect(): void
Disconnects from the remote BLE device.
**Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900003 | Bluetooth switch is off. |
|2900099 | Operation failed. |
**Example**
```js
try {
let device = bluetoothManager.BLE.createGattClientDevice('XX:XX:XX:XX:XX:XX');
device.disconnect();
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
```
### close
close(): void
Closes this GATT client to unregister it from the protocol stack. After this method is called, this [GattClientDevice](#gattclientdevice) instance cannot be used.
**Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900003 | Bluetooth switch is off. |
|2900099 | Operation failed. |
**Example**
```js
try {
let device = bluetoothManager.BLE.createGattClientDevice('XX:XX:XX:XX:XX:XX');
device.close();
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
```
### getServices
getServices(callback: AsyncCallback&lt;Array&lt;GattService&gt;&gt;): void
Obtains all services of the remote BLE device. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ------------------------ |
| callback | AsyncCallback&lt;Array&lt;[GattService](#gattservice)&gt;&gt; | Yes | Callback invoked to return the services obtained.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900099 | Operation failed. |
**Example**
```js
// Callback
function getServices(code, gattServices) {
if (code.code == 0) {
let services = gattServices;
console.log('bluetooth code is ' + code.code);
console.log("bluetooth services size is ", services.length);
for (let i = 0; i < services.length; i++) {
console.log('bluetooth serviceUuid is ' + services[i].serviceUuid);
}
}
}
try {
let device = bluetoothManager.BLE.createGattClientDevice('XX:XX:XX:XX:XX:XX');
device.connect();
device.getServices(getServices);
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
```
### getServices
getServices(): Promise&lt;Array&lt;GattService&gt;&gt;
Obtains all services of the remote BLE device. This API uses a promise to return the result.
**Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Return value**
| Type | Description |
| ---------------------------------------- | --------------------------- |
| Promise&lt;Array&lt;[GattService](#gattservice)&gt;&gt; | Promise used to return the services obtained.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900099 | Operation failed. |
**Example**
```js
// Promise
try {
let device = bluetoothManager.BLE.createGattClientDevice('XX:XX:XX:XX:XX:XX');
device.connect();
device.getServices().then(result => {
console.info("getServices successfully:" + JSON.stringify(result));
});
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
```
### readCharacteristicValue
readCharacteristicValue(characteristic: BLECharacteristic, callback: AsyncCallback&lt;BLECharacteristic&gt;): void
Reads the characteristic value of the specific service of the remote BLE device. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------------- | ---------------------------------------- | ---- | ----------------------- |
| characteristic | [BLECharacteristic](#blecharacteristic) | Yes | Characteristic value to read. |
| callback | AsyncCallback&lt;[BLECharacteristic](#blecharacteristic)&gt; | Yes | Callback invoked to return the characteristic value read.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2901000 | Read forbidden. |
|2900099 | Operation failed. |
**Example**
```js
function readCcc(code, BLECharacteristic) {
if (code.code != 0) {
return;
}
console.log('bluetooth characteristic uuid: ' + BLECharacteristic.characteristicUuid);
let value = new Uint8Array(BLECharacteristic.characteristicValue);
console.log('bluetooth characteristic value: ' + value[0] +','+ value[1]+','+ value[2]+','+ value[3]);
}
let descriptors = [];
let bufferDesc = new ArrayBuffer(8);
let descV = new Uint8Array(bufferDesc);
descV[0] = 11;
let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
descriptorUuid: '00002903-0000-1000-8000-00805F9B34FB', descriptorValue: bufferDesc};
descriptors[0] = descriptor;
let bufferCCC = new ArrayBuffer(8);
let cccV = new Uint8Array(bufferCCC);
cccV[0] = 1;
let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
characteristicValue: bufferCCC, descriptors:descriptors};
try {
let device = bluetoothManager.BLE.createGattClientDevice('XX:XX:XX:XX:XX:XX');
device.readCharacteristicValue(characteristic, readCcc);
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
```
### readCharacteristicValue
readCharacteristicValue(characteristic: BLECharacteristic): Promise&lt;BLECharacteristic&gt;
Reads the characteristic value of the specific service of the remote BLE device. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------------- | --------------------------------------- | ---- | -------- |
| characteristic | [BLECharacteristic](#blecharacteristic) | Yes | Characteristic value to read.|
**Return value**
| Type | Description |
| ---------------------------------------- | -------------------------- |
| Promise&lt;[BLECharacteristic](#blecharacteristic)&gt; | Promise used to return the characteristic value read.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2901000 | Read forbidden. |
|2900099 | Operation failed. |
**Example**
```js
let descriptors = [];
let bufferDesc = new ArrayBuffer(8);
let descV = new Uint8Array(bufferDesc);
descV[0] = 11;
let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
descriptorUuid: '00002903-0000-1000-8000-00805F9B34FB', descriptorValue: bufferDesc};
descriptors[0] = descriptor;
let bufferCCC = new ArrayBuffer(8);
let cccV = new Uint8Array(bufferCCC);
cccV[0] = 1;
let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
characteristicValue: bufferCCC, descriptors:descriptors};
try {
let device = bluetoothManager.BLE.createGattClientDevice('XX:XX:XX:XX:XX:XX');
device.readCharacteristicValue(characteristic);
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
```
### readDescriptorValue
readDescriptorValue(descriptor: BLEDescriptor, callback: AsyncCallback&lt;BLEDescriptor&gt;): void
Reads the descriptor contained in the specific characteristic of the remote BLE device. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ---------- | ---------------------------------------- | ---- | ----------------------- |
| descriptor | [BLEDescriptor](#bledescriptor) | Yes | Descriptor to read. |
| callback | AsyncCallback&lt;[BLEDescriptor](#bledescriptor)&gt; | Yes | Callback invoked to return the descriptor read.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2901000 | Read forbidden. |
|2900099 | Operation failed. |
**Example**
```js
function readDesc(code, BLEDescriptor) {
if (code.code != 0) {
return;
}
console.log('bluetooth descriptor uuid: ' + BLEDescriptor.descriptorUuid);
let value = new Uint8Array(BLEDescriptor.descriptorValue);
console.log('bluetooth descriptor value: ' + value[0] +','+ value[1]+','+ value[2]+','+ value[3]);
}
let bufferDesc = new ArrayBuffer(8);
let descV = new Uint8Array(bufferDesc);
descV[0] = 11;
let descriptor = {
serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
descriptorUuid: '00002903-0000-1000-8000-00805F9B34FB',
descriptorValue: bufferDesc
};
try {
let device = bluetoothManager.BLE.createGattClientDevice('XX:XX:XX:XX:XX:XX');
device.readDescriptorValue(descriptor, readDesc);
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
```
### readDescriptorValue
readDescriptorValue(descriptor: BLEDescriptor): Promise&lt;BLEDescriptor&gt;
Reads the descriptor contained in the specific characteristic of the remote BLE device. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ---------- | ------------------------------- | ---- | -------- |
| descriptor | [BLEDescriptor](#bledescriptor) | Yes | Descriptor to read.|
**Return value**
| Type | Description |
| ---------------------------------------- | -------------------------- |
| Promise&lt;[BLEDescriptor](#bledescriptor)&gt; | Promise used to return the descriptor read.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2901000 | Read forbidden. |
|2900099 | Operation failed. |
**Example**
```js
let bufferDesc = new ArrayBuffer(8);
let descV = new Uint8Array(bufferDesc);
descV[0] = 11;
let descriptor = {
serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
descriptorUuid: '00002903-0000-1000-8000-00805F9B34FB',
descriptorValue: bufferDesc
};
try {
let device = bluetoothManager.BLE.createGattClientDevice('XX:XX:XX:XX:XX:XX');
device.readDescriptorValue(descriptor);
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
```
### writeCharacteristicValue
writeCharacteristicValue(characteristic: BLECharacteristic): void
Writes a characteristic value to the remote BLE device.
**Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------------- | --------------------------------------- | ---- | ------------------- |
| characteristic | [BLECharacteristic](#blecharacteristic) | Yes | Binary value and other parameters of the BLE device characteristic.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2901001 | Write forbidden. |
|2900099 | Operation failed. |
**Example**
```js
let descriptors = [];
let bufferDesc = new ArrayBuffer(8);
let descV = new Uint8Array(bufferDesc);
descV[0] = 11;
let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
descriptorUuid: '00002903-0000-1000-8000-00805F9B34FB', descriptorValue: bufferDesc};
descriptors[0] = descriptor;
let bufferCCC = new ArrayBuffer(8);
let cccV = new Uint8Array(bufferCCC);
cccV[0] = 1;
let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
characteristicValue: bufferCCC, descriptors:descriptors};
try {
let device = bluetoothManager.BLE.createGattClientDevice('XX:XX:XX:XX:XX:XX');
device.writeCharacteristicValue(characteristic);
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
```
### writeDescriptorValue
writeDescriptorValue(descriptor: BLEDescriptor): void
Writes binary data to the specific descriptor of the remote BLE device.
**Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ---------- | ------------------------------- | ---- | ------------------ |
| descriptor | [BLEDescriptor](#bledescriptor) | Yes | Binary value and other parameters of the BLE device descriptor.|
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2901001 | Write forbidden. |
|2900099 | Operation failed. |
**Example**
```js
let bufferDesc = new ArrayBuffer(8);
let descV = new Uint8Array(bufferDesc);
descV[0] = 22;
let descriptor = {
serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
descriptorUuid: '00002903-0000-1000-8000-00805F9B34FB',
descriptorValue: bufferDesc
};
try {
let device = bluetoothManager.BLE.createGattClientDevice('XX:XX:XX:XX:XX:XX');
device.writeDescriptorValue(descriptor);
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
```
### setBLEMtuSize
setBLEMtuSize(mtu: number): void
Sets the maximum transmission unit (MTU) that can be transmitted between the GATT client and its remote BLE device. This API can be used only after a connection is set up by calling [connect](#connect).
**Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | -------------- |
| mtu | number | Yes | MTU to set, which ranges from 22 to 512 bytes.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900099 | Operation failed. |
**Example**
```js
try {
let device = bluetoothManager.BLE.createGattClientDevice('XX:XX:XX:XX:XX:XX');
device.setBLEMtuSize(128);
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
```
### setNotifyCharacteristicChanged
setNotifyCharacteristicChanged(characteristic: BLECharacteristic, enable: boolean): void
Sets the function of notifying the GATT client when the characteristic value of the remote BLE device changes.
**Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------------- | --------------------------------------- | ---- | ----------------------------- |
| characteristic | [BLECharacteristic](#blecharacteristic) | Yes | BLE characteristic to listen for. |
| enable | boolean | Yes | Whether to enable the notify function. The value **true** means to enable the notify function, and the value **false** means the opposite.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900099 | Operation failed. |
**Example**
```js
// Create descriptors.
let descriptors = [];
let arrayBuffer = new ArrayBuffer(8);
let descV = new Uint8Array(arrayBuffer);
descV[0] = 11;
let descriptor = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB',
descriptorUuid: '00002902-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer};
descriptors[0] = descriptor;
let arrayBufferC = new ArrayBuffer(8);
let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', characteristicValue: arrayBufferC, descriptors:descriptors};
try {
let device = bluetoothManager.BLE.createGattClientDevice('XX:XX:XX:XX:XX:XX');
device.setNotifyCharacteristicChanged(characteristic, false);
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
```
### on('BLECharacteristicChange')
on(type: "BLECharacteristicChange", callback: Callback&lt;BLECharacteristic&gt;): void
Subscribes to the BLE characteristic change events. The client can receive a notification from the server only after the **setNotifyCharacteristicChanged** method is called.
**Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type | string | Yes | Event type. The value **BLECharacteristicChange** indicates a characteristic value change event.|
| callback | Callback&lt;[BLECharacteristic](#blecharacteristic)&gt; | Yes | Callback invoked to return the characteristic value changes. |
**Example**
```js
function CharacteristicChange(CharacteristicChangeReq) {
let serviceUuid = CharacteristicChangeReq.serviceUuid;
let characteristicUuid = CharacteristicChangeReq.characteristicUuid;
let value = new Uint8Array(CharacteristicChangeReq.characteristicValue);
}
try {
let device = bluetoothManager.BLE.createGattClientDevice('XX:XX:XX:XX:XX:XX');
device.on('BLECharacteristicChange', CharacteristicChange);
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
```
### off('BLECharacteristicChange')
off(type: "BLECharacteristicChange", callback?: Callback&lt;BLECharacteristic&gt;): void
Unsubscribes from the BLE characteristic change events.
**Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type | string | Yes | Event type. The value **BLECharacteristicChange** indicates a characteristic value change event.|
| callback | Callback&lt;[BLECharacteristic](#blecharacteristic)&gt; | No | Callback for the characteristic value change event. If this parameter is not set, this method unsubscribes from all callbacks corresponding to **type**.|
**Example**
```js
try {
let device = bluetoothManager.BLE.createGattClientDevice('XX:XX:XX:XX:XX:XX');
device.off('BLECharacteristicChange');
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
```
### on('BLEConnectionStateChange')
on(type: "BLEConnectionStateChange", callback: Callback&lt;BLEConnectChangedState&gt;): void
Subscribes to the BLE connection state change events.
**Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type | string | Yes | Event type. The value **BLEConnectionStateChange** indicates a BLE connection state change event.|
| callback | Callback&lt;[BLEConnectChangedState](#bleconnectchangedstate)&gt; | Yes | Callback invoked to return the BLE connection state. |
**Example**
```js
function ConnectStateChanged(state) {
console.log('bluetooth connect state changed');
let connectState = state.state;
}
try {
let device = bluetoothManager.BLE.createGattClientDevice('XX:XX:XX:XX:XX:XX');
device.on('BLEConnectionStateChange', ConnectStateChanged);
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
```
### off('BLEConnectionStateChange')
off(type: "BLEConnectionStateChange", callback?: Callback&lt;BLEConnectChangedState&gt;): void
Unsubscribes from the BLE connection state change events.
**Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type | string | Yes | Event type. The value **BLEConnectionStateChange** indicates a BLE connection state change event.|
| callback | Callback&lt;[BLEConnectChangedState](#bleconnectchangedstate)&gt; | No | Callback for the BLE connection state change event. If this parameter is not set, this method unsubscribes from all callbacks corresponding to **type**.|
**Example**
```js
try {
let device = bluetoothManager.BLE.createGattClientDevice('XX:XX:XX:XX:XX:XX');
device.off('BLEConnectionStateChange');
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
```
### getDeviceName
getDeviceName(callback: AsyncCallback&lt;string&gt;): void
Obtains the name of the remote BLE device. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | --------------------------- | ---- | ------------------------------- |
| callback | AsyncCallback&lt;string&gt; | Yes | Callback invoked to return the remote BLE device name obtained.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900099 | Operation failed. |
**Example**
```js
// callback
try {
let gattClient = bluetoothManager.BLE.createGattClientDevice("XX:XX:XX:XX:XX:XX");
gattClient.connect();
let deviceName = gattClient.getDeviceName((err, data)=> {
console.info('device name err ' + JSON.stringify(err));
console.info('device name' + JSON.stringify(data));
})
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
```
### getDeviceName
getDeviceName(): Promise&lt;string&gt;
Obtains the name of the remote BLE device. This API uses a promise to return the result.
**Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Return value**
| Type | Description |
| --------------------- | ---------------------------------- |
| Promise&lt;string&gt; | Promise used to return the remote BLE device name.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900099 | Operation failed. |
**Example**
```js
// promise
try {
let gattClient = bluetoothManager.BLE.createGattClientDevice("XX:XX:XX:XX:XX:XX");
gattClient.connect();
let deviceName = gattClient.getDeviceName().then((data) => {
console.info('device name' + JSON.stringify(data));
})
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
```
### getRssiValue
getRssiValue(callback: AsyncCallback&lt;number&gt;): void
Obtains the received signal strength indication (RSSI) of the remote BLE device. This API uses an asynchronous callback to return the result. It can be used only after a connection is set up by calling [connect](#connect).
**Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | --------------------------- | ---- | ------------------------------ |
| callback | AsyncCallback&lt;number&gt; | Yes | Callback invoked to return the RSSI, in dBm.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900099 | Operation failed. |
**Example**
```js
// callback
try {
let gattClient = bluetoothManager.BLE.createGattClientDevice("XX:XX:XX:XX:XX:XX");
gattClient.connect();
let rssi = gattClient.getRssiValue((err, data)=> {
console.info('rssi err ' + JSON.stringify(err));
console.info('rssi value' + JSON.stringify(data));
})
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
```
### getRssiValue
getRssiValue(): Promise&lt;number&gt;
Obtains the RSSI of the remote BLE device. This API uses a promise to return the result. It can be used only after a connection is set up by calling [connect](#connect).
**Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Return value**
| Type | Description |
| --------------------- | --------------------------------- |
| Promise&lt;number&gt; | Promise used to return the RSSI, in dBm.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900099 | Operation failed. |
**Example**
```js
// promise
try {
let gattClient = bluetoothManager.BLE.createGattClientDevice("XX:XX:XX:XX:XX:XX");
let rssi = gattClient.getRssiValue().then((data) => {
console.info('rssi' + JSON.stringify(data));
})
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
```
## ScanMode<a name="ScanMode"></a>
Enumerates the scan modes.
**System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Value | Description |
| ---------------------------------------- | ---- | --------------- |
| SCAN_MODE_NONE | 0 | No scan mode. |
| SCAN_MODE_CONNECTABLE | 1 | Connectable mode. |
| SCAN_MODE_GENERAL_DISCOVERABLE | 2 | General discoverable mode. |
| SCAN_MODE_LIMITED_DISCOVERABLE | 3 | Limited discoverable mode. |
| SCAN_MODE_CONNECTABLE_GENERAL_DISCOVERABLE | 4 | General connectable and discoverable mode.|
| SCAN_MODE_CONNECTABLE_LIMITED_DISCOVERABLE | 5 | Limited connectable and discoverable mode.|
## BondState<a name="BondState"></a>
Enumerates the pairing states.
**System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Value | Description |
| ------------------ | ---- | ------ |
| BOND_STATE_INVALID | 0 | Invalid pairing.|
| BOND_STATE_BONDING | 1 | Pairing. |
| BOND_STATE_BONDED | 2 | Paired. |
## SppOption<a name="SppOption"></a>
Defines the SPP configuration parameters.
**System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Type | Readable | Writable | Description |
| ------ | ------------------- | ---- | ---- | ----------- |
| uuid | string | Yes | Yes | UUID of the SPP.|
| secure | boolean | Yes | Yes | Whether it is a secure channel. |
| type | [SppType](#spptype) | Yes | Yes | Type of the SPP link. |
## SppType<a name="SppType"></a>
Enumerates the SPP link types.
**System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Value | Description |
| ---------- | ---- | ------------- |
| SPP_RFCOMM | 0 | Radio frequency communication (RFCOMM) link type.|
## GattService
Defines the GATT service API parameters.
**System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Type | Readable | Writable | Description |
| --------------- | ---------------------------------------- | ---- | ---- | ---------------------------------------- |
| serviceUuid | string | Yes | Yes | UUID of the service, for example, **00001888-0000-1000-8000-00805f9b34fb**.|
| isPrimary | boolean | Yes | Yes | Whether the service is a primary service. The value **true** means a primary service. |
| characteristics | Array&lt;[BLECharacteristic](#blecharacteristic)&gt; | Yes | Yes | List of characteristics of the service. |
| includeServices | Array&lt;[GattService](#gattservice)&gt; | Yes | Yes | Services on which the service depends. |
## BLECharacteristic
Defines the characteristic API parameters.
**System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Type | Readable | Writable | Description |
| ------------------- | ---------------------------------------- | ---- | ---- | ---------------------------------------- |
| serviceUuid | string | Yes | Yes | UUID of the service, for example, **00001888-0000-1000-8000-00805f9b34fb**.|
| characteristicUuid | string | Yes | Yes | UUID of the characteristic, for example, **00002a11-0000-1000-8000-00805f9b34fb**.|
| characteristicValue | ArrayBuffer | Yes | Yes | Binary value of the characteristic. |
| descriptors | Array&lt;[BLEDescriptor](#bledescriptor)&gt; | Yes | Yes | List of descriptors of the characteristic. |
## BLEDescriptor
Defines the descriptor API parameters.
**System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Type | Readable | Writable | Description |
| ------------------ | ----------- | ---- | ---- | ---------------------------------------- |
| serviceUuid | string | Yes | Yes | UUID of the service, for example, **00001888-0000-1000-8000-00805f9b34fb**.|
| characteristicUuid | string | Yes | Yes | UUID of the characteristic, for example, **00002a11-0000-1000-8000-00805f9b34fb**.|
| descriptorUuid | string | Yes | Yes | UUID of the descriptor, for example, **00002902-0000-1000-8000-00805f9b34fb**.|
| descriptorValue | ArrayBuffer | Yes | Yes | Binary value of the descriptor. |
## NotifyCharacteristic
Defines the parameters in the notifications sent when the server characteristic value changes.
**System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Type | Readable | Writable | Description |
| ------------------- | ----------- | ---- | ---- | ---------------------------------------- |
| serviceUuid | string | Yes | Yes | UUID of the service, for example, **00001888-0000-1000-8000-00805f9b34fb**.|
| characteristicUuid | string | Yes | Yes | UUID of the characteristic, for example, **00002a11-0000-1000-8000-00805f9b34fb**.|
| characteristicValue | ArrayBuffer | Yes | Yes | Binary value of the characteristic. |
| confirm | boolean | Yes | Yes | Whether the notification needs to be confirmed by the remote end. For a notification, set it to **true**. In this case, the remote end must confirm the receipt of the notification. For an indication, set it to **false**. In this case, the remote end does not need to confirm the receipt of the notification.|
## CharacteristicReadRequest
Defines the parameters of the **CharacteristicReadReq** event received by the server.
**System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Type | Readable | Writable | Description |
| ------------------ | ------ | ---- | ---- | ---------------------------------------- |
| deviceId | string | Yes | No | Address of the remote device that sends the **CharacteristicReadReq** event, for example, XX:XX:XX:XX:XX:XX.|
| transId | number | Yes | No | Transmission ID of the read request. The response returned by the server must use the same transmission ID. |
| offset | number | Yes | No | Position from which the characteristic value is read. For example, **k** means to read from the kth byte. The response returned by the server must use the same offset.|
| characteristicUuid | string | Yes | No | UUID of the characteristic, for example, **00002a11-0000-1000-8000-00805f9b34fb**.|
| serviceUuid | string | Yes | No | UUID of the service, for example, **00001888-0000-1000-8000-00805f9b34fb**.|
## CharacteristicWriteRequest
Defines the parameters of the **CharacteristicWriteReq** event received by the server.
**System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Type | Readable | Writable | Description |
| ------------------ | ------ | ---- | ---- | ---------------------------------------- |
| deviceId | string | Yes | No | Address of the remote device that sends the **CharacteristicWriteReq** event, for example, XX:XX:XX:XX:XX:XX.|
| transId | number | Yes | No | Transmission ID of the write request. The response returned by the server must use the same transmission ID. |
| offset | number | Yes | No | Start position for writing the characteristic value. For example, **k** means to write from the kth byte. The response returned by the server must use the same offset.|
| descriptorUuid | string | Yes | No | UUID of the descriptor, for example, **00002902-0000-1000-8000-00805f9b34fb**.|
| characteristicUuid | string | Yes | No | UUID of the characteristic, for example, **00002a11-0000-1000-8000-00805f9b34fb**.|
| serviceUuid | string | Yes | No | UUID of the service, for example, **00001888-0000-1000-8000-00805f9b34fb**.|
## DescriptorReadRequest
Defines the parameters of the **DescriptorReadReq** event received by the server.
**System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Type | Readable | Writable | Description |
| ------------------ | ------ | ---- | ---- | ---------------------------------------- |
| deviceId | string | Yes | No | Address of the remote device that sends a **DescriptorReadReq** event, for example, XX:XX:XX:XX:XX:XX.|
| transId | number | Yes | No | Transmission ID of the read request. The response returned by the server must use the same transmission ID. |
| offset | number | Yes | No | Position from which the descriptor is read. For example, **k** means to read from the kth byte. The response returned by the server must use the same offset.|
| descriptorUuid | string | Yes | No | UUID of the descriptor, for example, **00002902-0000-1000-8000-00805f9b34fb**.|
| characteristicUuid | string | Yes | No | UUID of the characteristic, for example, **00002a11-0000-1000-8000-00805f9b34fb**.|
| serviceUuid | string | Yes | No | UUID of the service, for example, **00001888-0000-1000-8000-00805f9b34fb**.|
## DescriptorWriteRequest
Defines the parameters of the **DescriptorWriteReq** event received by the server.
**System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Type | Readable | Writable | Description |
| ------------------ | ----------- | ---- | ---- | ---------------------------------------- |
| deviceId | string | Yes | No | Address of the remote device that sends a **DescriptorWriteReq** event, for example, XX:XX:XX:XX:XX:XX.|
| transId | number | Yes | No | Transmission ID of the write request. The response returned by the server must use the same transmission ID. |
| offset | number | Yes | No | Start position for writing the descriptor. For example, **k** means to write from the kth byte. The response returned by the server must use the same offset.|
| isPrep | boolean | Yes | No | Whether the write request is executed immediately. |
| needRsp | boolean | Yes | No | Whether to send a response to the GATT client. |
| value | ArrayBuffer | Yes | No | Binary value of the descriptor to write. |
| descriptorUuid | string | Yes | No | UUID of the descriptor, for example, **00002902-0000-1000-8000-00805f9b34fb**.|
| characteristicUuid | string | Yes | No | UUID of the characteristic, for example, **00002a11-0000-1000-8000-00805f9b34fb**.|
| serviceUuid | string | Yes | No | UUID of the service, for example, **00001888-0000-1000-8000-00805f9b34fb**.|
## ServerResponse
Defines the parameters of the server's response to the GATT client's read/write request.
**System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Type | Readable | Writable | Description |
| -------- | ----------- | ---- | ---- | -------------------------------------- |
| deviceId | string | Yes | No | Address of the remote device, for example, XX:XX:XX:XX:XX:XX. |
| transId | number | Yes | No | Transmission ID of the request. The value must be the same as the ID carried in the read/write request received. |
| status | number | Yes | No | Response state. Set this parameter to **0**, which indicates a normal response. |
| offset | number | Yes | No | Start read/write position. The value must be the same as the offset carried in the read/write request.|
| value | ArrayBuffer | Yes | No | Binary data in the response. |
## BLEConnectChangedState
Defines the parameters of **BLEConnectChangedState**.
**System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Type | Readable| Writable| Description |
| -------- | ------------------------------------------------- | ---- | ---- | --------------------------------------------- |
| deviceId | string | Yes | No | Address of the remote device, for example, XX:XX:XX:XX:XX:XX.|
| state | [ProfileConnectionState](#profileconnectionstate) | Yes | Yes | BLE connection state. |
## ProfileConnectionState
Enumerates the profile connection states.
**System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Value | Description |
| ------------------- | ---- | -------------- |
| STATE_DISCONNECTED | 0 | Disconnected. |
| STATE_CONNECTING | 1 | Connecting.|
| STATE_CONNECTED | 2 | Connected. |
| STATE_DISCONNECTING | 3 | Disconnecting.|
## ScanFilter
Defines the scan filter parameters.
**System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Type | Readable| Writable| Description |
| ---------------------------------------- | ----------- | ---- | ---- | ------------------------------------------------------------ |
| deviceId | string | Yes | Yes | Address of the BLE device to filter, for example, XX:XX:XX:XX:XX:XX. |
| name | string | Yes | Yes | Name of the BLE device to filter. |
| serviceUuid | string | Yes | Yes | Service UUID of the device to filter, for example, **00001888-0000-1000-8000-00805f9b34fb**.|
| serviceUuidMask | string | Yes | Yes | Service UUID mask of the device to filter, for example, **FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF**.|
| serviceSolicitationUuid | string | Yes | Yes | Service solicitation UUID of the device to filter, for example, **00001888-0000-1000-8000-00805F9B34FB**.|
| serviceSolicitationUuidMask | string | Yes | Yes | Service solicitation UUID mask of the device to filter, for example, **FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF**.|
| serviceData | ArrayBuffer | Yes | Yes | Service data of the device to filter, for example, **[0x90, 0x00, 0xF1, 0xF2]**.|
| serviceDataMask | ArrayBuffer | Yes | Yes | Service data mask of the device to filter, for example, **[0xFF,0xFF,0xFF,0xFF]**.|
| manufactureId | number | Yes | Yes | Manufacturer ID of the device to filter, for example, **0x0006**. |
| manufactureData | ArrayBuffer | Yes | Yes | Manufacturer data of the device to filter, for example, **[0x1F,0x2F,0x3F]**.|
| manufactureDataMask | ArrayBuffer | Yes | Yes | Manufacturer data mask of the device to filter, for example, **[0xFF, 0xFF, 0xFF]**.|
## ScanOptions
Defines the scan configuration parameters.
**System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Type | Readable | Writable | Description |
| --------- | ----------------------- | ---- | ---- | -------------------------------------- |
| interval | number | Yes | Yes | Delay in reporting the scan result. The default value is **0**. |
| dutyMode | [ScanDuty](#scanduty) | Yes | Yes | Scan duty. The default value is SCAN_MODE_LOW_POWER. |
| matchMode | [MatchMode](#matchmode) | Yes | Yes | Hardware filtering match mode. The default value is **MATCH_MODE_AGGRESSIVE**.|
## ScanDuty
Enumerates the scan duty options.
**System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Value | Description |
| --------------------- | ---- | ------------ |
| SCAN_MODE_LOW_POWER | 0 | Low-power mode, which is the default value.|
| SCAN_MODE_BALANCED | 1 | Balanced mode. |
| SCAN_MODE_LOW_LATENCY | 2 | Low-latency mode. |
## MatchMode
Enumerates the hardware match modes of BLE scan filters.
**System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Value | Description |
| --------------------- | ---- | ---------------------------------------- |
| MATCH_MODE_AGGRESSIVE | 1 | Hardware reports the scan result with a lower threshold of signal strength and few number of matches in a duration. This is the default value.|
| MATCH_MODE_STICKY | 2 | Hardware reports the scan result with a higher threshold of signal strength and sightings. |
## ScanResult
Defines the scan result.
**System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Type | Readable | Writable | Description |
| -------- | ----------- | ---- | ---- | ---------------------------------- |
| deviceId | string | Yes | No | Address of the scanned device, for example, XX:XX:XX:XX:XX:XX.|
| rssi | number | Yes | No | RSSI of the device. |
| data | ArrayBuffer | Yes | No | Advertisement packets sent by the device. |
## BluetoothState
Enumerates the Bluetooth states.
**System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Value | Description |
| --------------------- | ---- | ------------------ |
| STATE_OFF | 0 | Bluetooth is turned off. |
| STATE_TURNING_ON | 1 | Bluetooth is being turned on. |
| STATE_ON | 2 | Bluetooth is turned on. |
| STATE_TURNING_OFF | 3 | Bluetooth is being turned off. |
| STATE_BLE_TURNING_ON | 4 | The LE-only mode is being turned on for Bluetooth.|
| STATE_BLE_ON | 5 | Bluetooth is in LE-only mode. |
| STATE_BLE_TURNING_OFF | 6 | The LE-only mode is being turned off for Bluetooth.|
## AdvertiseSetting
Defines the BLE advertising parameters.
**System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Type | Readable | Writable | Description |
| ----------- | ------- | ---- | ---- | ---------------------------------------- |
| interval | number | Yes | Yes | Interval for BLE advertising. The minimum value is **32** slots (20 ms). The maximum value is **16384** slots. The default value is **1600** slots (1s).|
| txPower | number | Yes | Yes | Transmit power, in dBm. The value range is -127 to 1. The default value is **-7**. |
| connectable | boolean | Yes | Yes | Whether the advertisement is connectable. The default value is **true**. |
## AdvertiseData
Defines the content of a BLE advertisement packet.
**System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Type | Readable | Writable | Description |
| --------------- | ---------------------------------------- | ---- | ---- | --------------------------- |
| serviceUuids | Array&lt;string&gt; | Yes | Yes | List of service UUIDs to broadcast.|
| manufactureData | Array&lt;[ManufactureData](#manufacturedata)&gt; | Yes | Yes | List of manufacturers to broadcast. |
| serviceData | Array&lt;[ServiceData](#servicedata)&gt; | Yes | Yes | List of service data to broadcast. |
## ManufactureData
Defines the content of a BLE advertisement packet.
**System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Type | Readable | Writable | Description |
| ---------------- | ------------------- | ---- | ---- | ------------------ |
| manufactureId | number | Yes | Yes | Manufacturer ID allocated by the Bluetooth SIG.|
| manufactureValue | ArrayBuffer | Yes | Yes | Manufacturer data. |
## ServiceData
Defines the service data contained in an advertisement packet.
**System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Type | Readable | Writable | Description |
| ------------ | ----------- | ---- | ---- | ---------- |
| serviceUuid | string | Yes | Yes | Service UUID.|
| serviceValue | ArrayBuffer | Yes | Yes | Service data. |
## PinRequiredParam<a name="PinRequiredParam"></a>
Defines the pairing request parameters.
**System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Type | Readable | Writable | Description |
| -------- | ------ | ---- | ---- | ----------- |
| deviceId | string | Yes | No | ID of the device to pair.|
| pinCode | string | Yes | No | Key for the device pairing. |
## BondStateParam<a name="BondStateParam"></a>
Defines the pairing state parameters.
**System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Type | Readable | Writable | Description |
| -------- | ------ | ---- | ---- | ----------- |
| deviceId | string | Yes | No | ID of the device to pair.|
| state | BondState | Yes | No | State of the device.|
## StateChangeParam<a name="StateChangeParam"></a>
Defines the profile state change parameters.
**System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Type | Readable| Writable| Description |
| -------- | ------------------------------------------------- | ---- | ---- | ------------------------------- |
| deviceId | string | Yes | No | Address of a Bluetooth device. |
| state | [ProfileConnectionState](#profileconnectionstate) | Yes | No | Profile connection state of the device.|
## DeviceClass<a name="DeviceClass"></a>
Defines the class of a Bluetooth device.
**System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Type | Readable | Writable | Description |
| --------------- | ----------------------------------- | ---- | ---- | ---------------- |
| majorClass | [MajorClass](#majorclass) | Yes | No | Major classes of Bluetooth devices. |
| majorMinorClass | [MajorMinorClass](#majorminorclass) | Yes | No | Major and minor classes of Bluetooth devices.|
| classOfDevice | number | Yes | No | Class of the device. |
## MajorClass<a name="MajorClass"></a>
Enumerates the major classes of Bluetooth devices.
**System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Value | Description |
| ------------------- | ------ | ---------- |
| MAJOR_MISC | 0x0000 | Miscellaneous device. |
| MAJOR_COMPUTER | 0x0100 | Computer. |
| MAJOR_PHONE | 0x0200 | Mobile phone. |
| MAJOR_NETWORKING | 0x0300 | Network device. |
| MAJOR_AUDIO_VIDEO | 0x0400 | Audio or video device.|
| MAJOR_PERIPHERAL | 0x0500 | Peripheral device. |
| MAJOR_IMAGING | 0x0600 | Imaging device. |
| MAJOR_WEARABLE | 0x0700 | Wearable device. |
| MAJOR_TOY | 0x0800 | Toy. |
| MAJOR_HEALTH | 0x0900 | Health device. |
| MAJOR_UNCATEGORIZED | 0x1F00 | Unclassified device. |
## MajorMinorClass<a name="MajorMinorClass"></a>
Enumerates the major and minor classes of Bluetooth devices.
**System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Value | Description |
| ---------------------------------------- | ------ | --------------- |
| COMPUTER_UNCATEGORIZED | 0x0100 | Unclassified computer. |
| COMPUTER_DESKTOP | 0x0104 | Desktop computer. |
| COMPUTER_SERVER | 0x0108 | Server. |
| COMPUTER_LAPTOP | 0x010C | Laptop. |
| COMPUTER_HANDHELD_PC_PDA | 0x0110 | Hand-held computer. |
| COMPUTER_PALM_SIZE_PC_PDA | 0x0114 | Palmtop computer. |
| COMPUTER_WEARABLE | 0x0118 | Wearable computer. |
| COMPUTER_TABLET | 0x011C | Tablet. |
| PHONE_UNCATEGORIZED | 0x0200 | Unclassified mobile phone. |
| PHONE_CELLULAR | 0x0204 | Portable phone. |
| PHONE_CORDLESS | 0x0208 | Cordless phone. |
| PHONE_SMART | 0x020C | Smartphone. |
| PHONE_MODEM_OR_GATEWAY | 0x0210 | Modem or gateway phone.|
| PHONE_ISDN | 0x0214 | ISDN phone. |
| NETWORK_FULLY_AVAILABLE | 0x0300 | Device with network fully available. |
| NETWORK_1_TO_17_UTILIZED | 0x0320 | Device used on network 1 to 17. |
| NETWORK_17_TO_33_UTILIZED | 0x0340 | Device used on network 17 to 33. |
| NETWORK_33_TO_50_UTILIZED | 0x0360 | Device used on network 33 to 50. |
| NETWORK_60_TO_67_UTILIZED | 0x0380 | Device used on network 60 to 67. |
| NETWORK_67_TO_83_UTILIZED | 0x03A0 | Device used on network 67 to 83. |
| NETWORK_83_TO_99_UTILIZED | 0x03C0 | Device used on network 83 to 99. |
| NETWORK_NO_SERVICE | 0x03E0 | Device without network service |
| AUDIO_VIDEO_UNCATEGORIZED | 0x0400 | Unclassified audio or video device. |
| AUDIO_VIDEO_WEARABLE_HEADSET | 0x0404 | Wearable audio or video headset. |
| AUDIO_VIDEO_HANDSFREE | 0x0408 | Hands-free audio or video device. |
| AUDIO_VIDEO_MICROPHONE | 0x0410 | Audio or video microphone. |
| AUDIO_VIDEO_LOUDSPEAKER | 0x0414 | Audio or video loudspeaker. |
| AUDIO_VIDEO_HEADPHONES | 0x0418 | Audio or video headphones. |
| AUDIO_VIDEO_PORTABLE_AUDIO | 0x041C | Portable audio or video device. |
| AUDIO_VIDEO_CAR_AUDIO | 0x0420 | In-vehicle audio or video device. |
| AUDIO_VIDEO_SET_TOP_BOX | 0x0424 | Audio or video STB device. |
| AUDIO_VIDEO_HIFI_AUDIO | 0x0428 | High-fidelity speaker device. |
| AUDIO_VIDEO_VCR | 0x042C | Video cassette recording (VCR) device. |
| AUDIO_VIDEO_VIDEO_CAMERA | 0x0430 | Camera. |
| AUDIO_VIDEO_CAMCORDER | 0x0434 | Camcorder |
| AUDIO_VIDEO_VIDEO_MONITOR | 0x0438 | Audio or video monitor. |
| AUDIO_VIDEO_VIDEO_DISPLAY_AND_LOUDSPEAKER | 0x043C | Video display or loudspeaker. |
| AUDIO_VIDEO_VIDEO_CONFERENCING | 0x0440 | Video conferencing device. |
| AUDIO_VIDEO_VIDEO_GAMING_TOY | 0x0448 | Audio or video gaming toy. |
| PERIPHERAL_NON_KEYBOARD_NON_POINTING | 0x0500 | Non-keyboard or non-pointing peripheral device. |
| PERIPHERAL_KEYBOARD | 0x0540 | Keyboard device. |
| PERIPHERAL_POINTING_DEVICE | 0x0580 | Pointing peripheral device. |
| PERIPHERAL_KEYBOARD_POINTING | 0x05C0 | Keyboard pointing device. |
| PERIPHERAL_UNCATEGORIZED | 0x0500 | Unclassified peripheral device. |
| PERIPHERAL_JOYSTICK | 0x0504 | Peripheral joystick. |
| PERIPHERAL_GAMEPAD | 0x0508 | Peripheral game pad |
| PERIPHERAL_REMOTE_CONTROL | 0x05C0 | Peripheral remote control device |
| PERIPHERAL_SENSING_DEVICE | 0x0510 | Peripheral sensing device. |
| PERIPHERAL_DIGITIZER_TABLET | 0x0514 | Peripheral digitizer tablet.|
| PERIPHERAL_CARD_READER | 0x0518 | Peripheral card reader. |
| PERIPHERAL_DIGITAL_PEN | 0x051C | Peripheral digital pen. |
| PERIPHERAL_SCANNER_RFID | 0x0520 | Peripheral RFID scanner. |
| PERIPHERAL_GESTURAL_INPUT | 0x0522 | Gesture input device. |
| IMAGING_UNCATEGORIZED | 0x0600 | Unclassified imaging device. |
| IMAGING_DISPLAY | 0x0610 | Imaging display device. |
| IMAGING_CAMERA | 0x0620 | Imaging camera device. |
| IMAGING_SCANNER | 0x0640 | Imaging scanner. |
| IMAGING_PRINTER | 0x0680 | Imaging printer. |
| WEARABLE_UNCATEGORIZED | 0x0700 | Unclassified wearable device. |
| WEARABLE_WRIST_WATCH | 0x0704 | Smart watch. |
| WEARABLE_PAGER | 0x0708 | Wearable pager. |
| WEARABLE_JACKET | 0x070C | Smart jacket. |
| WEARABLE_HELMET | 0x0710 | Wearable helmet. |
| WEARABLE_GLASSES | 0x0714 | Wearable glasses. |
| TOY_UNCATEGORIZED | 0x0800 | Unclassified toy. |
| TOY_ROBOT | 0x0804 | Toy robot. |
| TOY_VEHICLE | 0x0808 | Toy vehicle. |
| TOY_DOLL_ACTION_FIGURE | 0x080C | Humanoid toy doll. |
| TOY_CONTROLLER | 0x0810 | Toy controller. |
| TOY_GAME | 0x0814 | Toy gaming device. |
| HEALTH_UNCATEGORIZED | 0x0900 | Unclassified health devices. |
| HEALTH_BLOOD_PRESSURE | 0x0904 | Blood pressure device. |
| HEALTH_THERMOMETER | 0x0908 | Thermometer |
| HEALTH_WEIGHING | 0x090C | Body scale. |
| HEALTH_GLUCOSE | 0x0910 | Blood glucose monitor. |
| HEALTH_PULSE_OXIMETER | 0x0914 | Pulse oximeter. |
| HEALTH_PULSE_RATE | 0x0918 | Heart rate monitor. |
| HEALTH_DATA_DISPLAY | 0x091C | Health data display. |
| HEALTH_STEP_COUNTER | 0x0920 | Step counter. |
| HEALTH_BODY_COMPOSITION_ANALYZER | 0x0924 | Body composition analyzer. |
| HEALTH_PEAK_FLOW_MONITOR | 0x0928 | Hygrometer. |
| HEALTH_MEDICATION_MONITOR | 0x092C | Medication monitor. |
| HEALTH_KNEE_PROSTHESIS | 0x0930 | Prosthetic knee. |
| HEALTH_ANKLE_PROSTHESIS | 0x0934 | Prosthetic ankle. |
| HEALTH_GENERIC_HEALTH_MANAGER | 0x0938 | Generic health management device. |
| HEALTH_PERSONAL_MOBILITY_DEVICE | 0x093C | Personal mobility device. |
## PlayingState<a name="PlayingState"></a>
Enumerates the A2DP playing states.
**System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Value | Description |
| ----------------- | ------ | ------- |
| STATE_NOT_PLAYING | 0x0000 | Not playing. |
| STATE_PLAYING | 0x0001 | Playing.|
## ProfileId<a name="ProfileId"></a>
Enumerates the Bluetooth profiles. API version 9 is added with **PROFILE_HID_HOST** and **PROFILE_PAN_NETWORK**.
**System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Value | Description |
| -------------------------------- | ------ | --------------- |
| PROFILE_A2DP_SOURCE | 1 | A2DP profile.|
| PROFILE_HANDS_FREE_AUDIO_GATEWAY | 4 | HFP profile. |
| PROFILE_HID_HOST | 6 | Human Interface Device (HID) profile. |
| PROFILE_PAN_NETWORK | 7 | PAN profile. |
...@@ -3,9 +3,9 @@ ...@@ -3,9 +3,9 @@
The **fileio** module provides APIs for file storage and management, including basic file management, directory management, file information statistics, and stream read and write. The **fileio** module provides APIs for file storage and management, including basic file management, directory management, file information statistics, and stream read and write.
> **NOTE** > **NOTE**
> >
> - The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version. > - The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> - The APIs provided by this module are deprecated since API version 9. You are advised to use [@ohos.file.fs](./js-apis-file-fs.md). > - The APIs provided by this module are deprecated since API version 9. You are advised to use [@ohos.file.fs](js-apis-file-fs.md).
## Modules to Import ## Modules to Import
...@@ -18,7 +18,7 @@ import fileio from '@ohos.fileio'; ...@@ -18,7 +18,7 @@ import fileio from '@ohos.fileio';
Before using the APIs provided by this module to perform operations on files or directories, obtain the path of the application sandbox as follows: Before using the APIs provided by this module to perform operations on files or directories, obtain the path of the application sandbox as follows:
Stage Model **Stage Model**
```js ```js
import UIAbility from '@ohos.app.ability.UIAbility'; import UIAbility from '@ohos.app.ability.UIAbility';
...@@ -31,9 +31,9 @@ export default class EntryAbility extends UIAbility { ...@@ -31,9 +31,9 @@ export default class EntryAbility extends UIAbility {
} }
``` ```
For details about how to obtain the stage model context, see [AbilityContext](js-apis-ability-context.md#abilitycontext). For details about how to obtain the stage model context, see [UIAbilityContext](js-apis-inner-application-uiAbilityContext.md).
FA Model **FA Model**
```js ```js
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
...@@ -62,9 +62,9 @@ Obtains file information. This API uses a promise to return the result. ...@@ -62,9 +62,9 @@ Obtains file information. This API uses a promise to return the result.
**Return value** **Return value**
| Type | Description | | Type | Description |
| ---------------------------- | ---------- | | ---------------------------- | ---------- |
| Promise&lt;[Stat](#stat)&gt; | Promise used to return the file information obtained.| | Promise&lt;[Stat](#stat)&gt; | Promise used to return the file information obtained.|
**Example** **Example**
...@@ -119,9 +119,9 @@ Synchronously obtains file information. ...@@ -119,9 +119,9 @@ Synchronously obtains file information.
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------- | ---------- | | ------------- | ---------- |
| [Stat](#stat) | File information obtained.| | [Stat](#stat) | File information obtained.|
**Example** **Example**
...@@ -147,9 +147,9 @@ Opens a file directory. This API uses a promise to return the result. ...@@ -147,9 +147,9 @@ Opens a file directory. This API uses a promise to return the result.
**Return value** **Return value**
| Type | Description | | Type | Description |
| -------------------------- | -------- | | -------------------------- | -------- |
| Promise&lt;[Dir](#dir)&gt; | Promise used to return the **Dir** object.| | Promise&lt;[Dir](#dir)&gt; | Promise used to return the **Dir** object.|
**Example** **Example**
...@@ -205,9 +205,9 @@ Synchronously opens a directory. ...@@ -205,9 +205,9 @@ Synchronously opens a directory.
**Return value** **Return value**
| Type | Description | | Type | Description |
| ----------- | -------- | | ----------- | -------- |
| [Dir](#dir) | A **Dir** instance corresponding to the directory.| | [Dir](#dir) | A **Dir** instance corresponding to the directory.|
**Example** **Example**
...@@ -231,13 +231,13 @@ Checks whether the current process can access a file. This API uses a promise to ...@@ -231,13 +231,13 @@ Checks whether the current process can access a file. This API uses a promise to
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------------------------------------------------ | | ------ | ------ | ---- | ------------------------------------------------------------ |
| path | string | Yes | Application sandbox path of the file. | | path | string | Yes | Application sandbox path of the file. |
| mode | number | No | Options for accessing the file. You can specify multiple options, separated with a bitwise OR operator (&#124;). The default value is **0**.<br>The options are as follows:<br>-&nbsp;**0**: check whether the file exists.<br>-&nbsp;**1**: check whether the current process has the execute permission on the file.<br>-&nbsp;**2**: check whether the current process has the write permission on the file.<br>-&nbsp;**4**: check whether the current process has the read permission on the file.| | mode | number | No | Options for accessing the file. You can specify multiple options, separated with a bitwise OR operator (&#124;). The default value is **0**.<br>The options are as follows:<br>- **0**: Check whether the file exists.<br>- **1**: Check whether the process has the execute permission on the file.<br>- **2**: Check whether the process has the write permission on the file.<br>- **4**: Check whether the process has the read permission on the file. |
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.| | Promise&lt;void&gt; | Promise that returns no value.|
**Example** **Example**
...@@ -264,7 +264,7 @@ Checks whether the current process can access a file. This API uses an asynchron ...@@ -264,7 +264,7 @@ Checks whether the current process can access a file. This API uses an asynchron
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ------------------------------------------------------------ | | -------- | ------------------------- | ---- | ------------------------------------------------------------ |
| path | string | Yes | Application sandbox path of the file. | | path | string | Yes | Application sandbox path of the file. |
| mode | number | No | Options for accessing the file. You can specify multiple options, separated with a bitwise OR operator (&#124;). The default value is **0**.<br>The options are as follows:<br>-&nbsp;**0**: check whether the file exists.<br>-&nbsp;**1**: check whether the current process has the execute permission on the file.<br>-&nbsp;**2**: check whether the current process has the write permission on the file.<br>-&nbsp;**4**: check whether the current process has the read permission on the file.| | mode | number | No | Options for accessing the file. You can specify multiple options, separated with a bitwise OR operator (&#124;). The default value is **0**.<br>The options are as follows:<br>- **0**: Check whether the file exists.<br>- **1**: Check whether the process has the execute permission on the file.<br>- **2**: Check whether the process has the write permission on the file.<br>- **4**: Check whether the process has the read permission on the file. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file is asynchronously checked. | | callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file is asynchronously checked. |
**Example** **Example**
...@@ -290,7 +290,7 @@ Synchronously checks whether the current process can access the specified file. ...@@ -290,7 +290,7 @@ Synchronously checks whether the current process can access the specified file.
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------------------------------------------------ | | ------ | ------ | ---- | ------------------------------------------------------------ |
| path | string | Yes | Application sandbox path of the file. | | path | string | Yes | Application sandbox path of the file. |
| mode | number | No | Options for accessing the file. You can specify multiple options, separated with a bitwise OR operator (&#124;). The default value is **0**.<br>The options are as follows:<br>-&nbsp;**0**: check whether the file exists.<br>-&nbsp;**1**: check whether the current process has the execute permission on the file.<br>-&nbsp;**2**: check whether the current process has the write permission on the file.<br>-&nbsp;**4**: check whether the current process has the read permission on the file.| | mode | number | No | Options for accessing the file. You can specify multiple options, separated with a bitwise OR operator (&#124;). The default value is **0**.<br>The options are as follows:<br>- **0**: Check whether the file exists.<br>- **1**: Check whether the process has the execute permission on the file.<br>- **2**: Check whether the process has the write permission on the file.<br>- **4**: Check whether the process has the read permission on the file. |
**Example** **Example**
...@@ -314,15 +314,15 @@ Closes a file. This API uses a promise to return the result. ...@@ -314,15 +314,15 @@ Closes a file. This API uses a promise to return the result.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ------------ | | ---- | ------ | ---- | ------------ |
| fd | number | Yes | File descriptor of the file to close.| | fd | number | Yes | File descriptor of the file to close.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.| | Promise&lt;void&gt; | Promise that returns no value.|
**Example** **Example**
...@@ -347,10 +347,10 @@ Closes a file. This API uses an asynchronous callback to return the result. ...@@ -347,10 +347,10 @@ Closes a file. This API uses an asynchronous callback to return the result.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ------------------------- | ---- | ------------ | | -------- | ------------------------- | ---- | ------------ |
| fd | number | Yes | File descriptor of the file to close.| | fd | number | Yes | File descriptor of the file to close.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file is closed asynchronously.| | callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file is closed asynchronously.|
**Example** **Example**
...@@ -373,9 +373,9 @@ Synchronously closes a file. ...@@ -373,9 +373,9 @@ Synchronously closes a file.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ------------ | | ---- | ------ | ---- | ------------ |
| fd | number | Yes | File descriptor of the file to close.| | fd | number | Yes | File descriptor of the file to close.|
**Example** **Example**
...@@ -396,17 +396,17 @@ Copies a file. This API uses a promise to return the result. ...@@ -396,17 +396,17 @@ Copies a file. This API uses a promise to return the result.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ---- | -------------------------- | ---- | ---------------------------------------- | | ---- | -------------------------- | ---- | ---------------------------------------- |
| src | string\|number | Yes | Path or file descriptor of the file to copy. | | src | string\|number | Yes | Path or file descriptor of the file to copy. |
| dest | string\|number | Yes | Path or file descriptor of the new file. | | dest | string\|number | Yes | Path or file descriptor of the new file. |
| mode | number | No | Option for overwriting the file of the same name in the destination path. The default value is **0**, which is the only value supported.<br>**0**: Completely overwrite the file with the same name and truncate the part that is not overwritten.| | mode | number | No | Option for overwriting the file of the same name in the destination path. The default value is **0**, which is the only value supported.<br>**0**: Completely overwrite the file with the same name and truncate the part that is not overwritten.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.| | Promise&lt;void&gt; | Promise that returns no value.|
**Example** **Example**
...@@ -431,12 +431,12 @@ Copies a file. This API uses an asynchronous callback to return the result. ...@@ -431,12 +431,12 @@ Copies a file. This API uses an asynchronous callback to return the result.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | -------------------------- | ---- | ---------------------------------------- | | -------- | -------------------------- | ---- | ---------------------------------------- |
| src | string\|number | Yes | Path or file descriptor of the file to copy. | | src | string\|number | Yes | Path or file descriptor of the file to copy. |
| dest | string\|number | Yes | Path or file descriptor of the new file. | | dest | string\|number | Yes | Path or file descriptor of the new file. |
| mode | number | No | Option for overwriting the file of the same name in the destination path. The default value is **0**, which is the only value supported.<br>**0**: Completely overwrite the file with the same name and truncate the part that is not overwritten.| | mode | number | No | Option for overwriting the file of the same name in the destination path. The default value is **0**, which is the only value supported.<br>**0**: Completely overwrite the file with the same name and truncate the part that is not overwritten.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file is copied asynchronously. | | callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file is copied asynchronously. |
**Example** **Example**
...@@ -459,11 +459,11 @@ Synchronously copies a file. ...@@ -459,11 +459,11 @@ Synchronously copies a file.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ---- | -------------------------- | ---- | ---------------------------------------- | | ---- | -------------------------- | ---- | ---------------------------------------- |
| src | string\|number | Yes | Path or file descriptor of the file to copy. | | src | string\|number | Yes | Path or file descriptor of the file to copy. |
| dest | string\|number | Yes | Path or file descriptor of the new file. | | dest | string\|number | Yes | Path or file descriptor of the new file. |
| mode | number | No | Option for overwriting the file of the same name in the destination path. The default value is **0**, which is the only value supported.<br>**0**: Completely overwrite the file with the same name and truncate the part that is not overwritten.| | mode | number | No | Option for overwriting the file of the same name in the destination path. The default value is **0**, which is the only value supported.<br>**0**: Completely overwrite the file with the same name and truncate the part that is not overwritten.|
**Example** **Example**
...@@ -487,13 +487,13 @@ Creates a directory. This API uses a promise to return the result. ...@@ -487,13 +487,13 @@ Creates a directory. This API uses a promise to return the result.
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------------------------------------------------ | | ------ | ------ | ---- | ------------------------------------------------------------ |
| path | string | Yes | Application sandbox path of the directory. | | path | string | Yes | Application sandbox path of the directory. |
| mode | number | No | Permission on the directory to create. You can specify multiple permissions, separated using a bitwise OR operator (&#124;). The default value is **0o775**.<br>-&nbsp;**0o775**: The owner has the read, write, and execute permissions, and other users have the read and execute permissions.<br>-&nbsp;**0o700**: The owner has the read, write, and execute permissions.<br>- &nbsp;**0o400**: The owner has the read permission.<br>-&nbsp;**0o200**: The owner has the write permission.<br>-&nbsp;**0o100**: The owner has the execute permission.<br>-&nbsp;**0o070**: The user group has the read, write, and execute permissions.<br>-&nbsp;**0o040**: The user group has the read permission.<br>-&nbsp;**0o020**: The user group has the write permission.<br>-&nbsp;**0o010**: The user group has the execute permission.<br>-&nbsp;**0o007**: Other users have the read, write, and execute permissions.<br>-&nbsp;**0o004**: Other users have the read permission.<br>-&nbsp;**0o002**: Other users have the write permission.<br>-&nbsp;**0o001**: Other users have the execute permission.| | mode | number | No | Permission on the directory to create. You can specify multiple permissions, separated using a bitwise OR operator (&#124;). The default value is **0o775**.<br>- **0o775**: The owner has the read, write, and execute permissions, and other users have the read and execute permissions.<br>- **0o700**: The owner has the read, write, and execute permissions.<br>- **0o400**: The owner has the read permission.<br>- **0o200**: The owner has the write permission.<br>- **0o100**: The owner has the execute permission.<br>- **0o070**: The user group has the read, write, and execute permissions.<br>- **0o040**: The user group has the read permission.<br>- **0o020**: The user group has the write permission.<br>- **0o010**: The user group has the execute permission.<br>- **0o007**: Other users have the read, write, and execute permissions.<br>- **0o004**: Other users have the read permission.<br>- **0o002**: Other users have the write permission.<br>- **0o001**: Other users have the execute permission. |
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.| | Promise&lt;void&gt; | Promise that returns no value.|
**Example** **Example**
...@@ -520,7 +520,7 @@ Creates a directory. This API uses an asynchronous callback to return the result ...@@ -520,7 +520,7 @@ Creates a directory. This API uses an asynchronous callback to return the result
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ------------------------------------------------------------ | | -------- | ------------------------- | ---- | ------------------------------------------------------------ |
| path | string | Yes | Application sandbox path of the directory. | | path | string | Yes | Application sandbox path of the directory. |
| mode | number | No | Permission on the directory to create. You can specify multiple permissions, separated using a bitwise OR operator (&#124;). The default value is **0o775**.<br>-&nbsp;**0o775**: The owner has the read, write, and execute permissions, and other users have the read and execute permissions.<br>-&nbsp;**0o700**: The owner has the read, write, and execute permissions.<br>- &nbsp;**0o400**: The owner has the read permission.<br>-&nbsp;**0o200**: The owner has the write permission.<br>-&nbsp;**0o100**: The owner has the execute permission.<br>-&nbsp;**0o070**: The user group has the read, write, and execute permissions.<br>-&nbsp;**0o040**: The user group has the read permission.<br>-&nbsp;**0o020**: The user group has the write permission.<br>-&nbsp;**0o010**: The user group has the execute permission.<br>-&nbsp;**0o007**: Other users have the read, write, and execute permissions.<br>-&nbsp;**0o004**: Other users have the read permission.<br>-&nbsp;**0o002**: Other users have the write permission.<br>-&nbsp;**0o001**: Other users have the execute permission.| | mode | number | No | Permission on the directory to create. You can specify multiple permissions, separated using a bitwise OR operator (&#124;). The default value is **0o775**.<br>- **0o775**: The owner has the read, write, and execute permissions, and other users have the read and execute permissions.<br>- **0o700**: The owner has the read, write, and execute permissions.<br>- **0o400**: The owner has the read permission.<br>- **0o200**: The owner has the write permission.<br>- **0o100**: The owner has the execute permission.<br>- **0o070**: The user group has the read, write, and execute permissions.<br>- **0o040**: The user group has the read permission.<br>- **0o020**: The user group has the write permission.<br>- **0o010**: The user group has the execute permission.<br>- **0o007**: Other users have the read, write, and execute permissions.<br>- **0o004**: Other users have the read permission.<br>- **0o002**: Other users have the write permission.<br>- **0o001**: Other users have the execute permission. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the directory is created asynchronously. | | callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the directory is created asynchronously. |
**Example** **Example**
...@@ -546,7 +546,7 @@ Synchronously creates a directory. ...@@ -546,7 +546,7 @@ Synchronously creates a directory.
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------------------------------------------------ | | ------ | ------ | ---- | ------------------------------------------------------------ |
| path | string | Yes | Application sandbox path of the directory. | | path | string | Yes | Application sandbox path of the directory. |
| mode | number | No | Permission on the directory to create. You can specify multiple permissions, separated using a bitwise OR operator (&#124;). The default value is **0o775**.<br>-&nbsp;**0o775**: The owner has the read, write, and execute permissions, and other users have the read and execute permissions.<br>-&nbsp;**0o700**: The owner has the read, write, and execute permissions.<br>- &nbsp;**0o400**: The owner has the read permission.<br>-&nbsp;**0o200**: The owner has the write permission.<br>-&nbsp;**0o100**: The owner has the execute permission.<br>-&nbsp;**0o070**: The user group has the read, write, and execute permissions.<br>-&nbsp;**0o040**: The user group has the read permission.<br>-&nbsp;**0o020**: The user group has the write permission.<br>-&nbsp;**0o010**: The user group has the execute permission.<br>-&nbsp;**0o007**: Other users have the read, write, and execute permissions.<br>-&nbsp;**0o004**: Other users have the read permission.<br>-&nbsp;**0o002**: Other users have the write permission.<br>-&nbsp;**0o001**: Other users have the execute permission.| | mode | number | No | Permission on the directory to create. You can specify multiple permissions, separated using a bitwise OR operator (&#124;). The default value is **0o775**.<br>- **0o775**: The owner has the read, write, and execute permissions, and other users have the read and execute permissions.<br>- **0o700**: The owner has the read, write, and execute permissions.<br>- **0o400**: The owner has the read permission.<br>- **0o200**: The owner has the write permission.<br>- **0o100**: The owner has the execute permission.<br>- **0o070**: The user group has the read, write, and execute permissions.<br>- **0o040**: The user group has the read permission.<br>- **0o020**: The user group has the write permission.<br>- **0o010**: The user group has the execute permission.<br>- **0o007**: Other users have the read, write, and execute permissions.<br>- **0o004**: Other users have the read permission.<br>- **0o002**: Other users have the write permission.<br>- **0o001**: Other users have the execute permission. |
**Example** **Example**
...@@ -569,14 +569,14 @@ Opens a file. This API uses a promise to return the result. ...@@ -569,14 +569,14 @@ Opens a file. This API uses a promise to return the result.
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------------------------------------------------ | | ------ | ------ | ---- | ------------------------------------------------------------ |
| path | string | Yes | Application sandbox path of the file. | | path | string | Yes | Application sandbox path of the file. |
| flags | number | No | Option for opening the file. You must specify one of the following options. By default, the file is open in read-only mode.<br>-&nbsp;**0o0**: Open the file in read-only mode.<br>-&nbsp;**0o1**: Open the file in write-only mode.<br>-&nbsp;**0o2**: Open the file in read/write mode.<br>In addition, you can specify the following options, separated using a bitwise OR operator (&#124;). By default, no additional option is specified.<br>-&nbsp;**0o100**: If the file does not exist, create it. If you use this option, you must also specify **mode**.<br>-&nbsp;**0o200**: If **0o100** is added and the file already exists, throw an exception.<br>-&nbsp;**0o1000**: If the file exists and is open in write-only or read/write mode, truncate the file length to 0.<br>-&nbsp;**0o2000**: Open the file in append mode. New data will be appended to the file (added to the end of the file).<br>-&nbsp;**0o4000**: If **path** points to a named pipe (also known as a FIFO), block special file, or character special file, perform non-blocking operations on the open file and in subsequent I/Os.<br>-&nbsp;**0o200000**: If **path** does not point to a directory, throw an exception.<br><br>-&nbsp;**0o400000**: If **path** points to a symbolic link, throw an exception.<br>-&nbsp;**0o4010000**: Open the file in synchronous I/O mode.| | flags | number | No | Option for opening the file. You must specify one of the following options. By default, the file is open in read-only mode.<br>- **0o0**: Open the file in read-only mode.<br>- **0o1**: Open the file in write-only mode.<br>- **0o2**: Open the file in read/write mode.<br>In addition, you can specify the following options, separated using a bitwise OR operator (&#124;). By default, no additional option is specified.<br>- **0o100**: If the file does not exist, create a file. The third parameter **mode** must also be specified.<br>- **0o200**: If **0o100** is added and the file already exists, throw an exception.<br>- **0o1000**: If the file exists and is open in write-only or read/write mode, truncate the file length to 0.<br>- **0o2000**: Open the file in append mode. New data will be appended to the file (written to the end of the file).<br>- **0o4000**: If **path** points to a named pipe (also known as a FIFO), block special file, or character special file, perform non-blocking operations on the open file and in subsequent I/Os.<br>- **0o200000**: If **path** does not point to a directory, throw an exception.<br>- **0o400000**: If **path** points to a symbolic link, throw an exception.<br>- **0o4010000**: Open the file in synchronous I/O mode.|
| mode | number | No | Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (&#124;). The default value is **0o666**.<br>-&nbsp;**0o666**: The owner, user group, and other users have the read and write permissions on the file.<br>-&nbsp;**0o700**: The owner has the read, write, and execute permissions.<br>- &nbsp;**0o400**: The owner has the read permission.<br>-&nbsp;**0o200**: The owner has the write permission.<br>-&nbsp;**0o100**: The owner has the execute permission.<br>-&nbsp;**0o070**: The user group has the read, write, and execute permissions.<br>-&nbsp;**0o040**: The user group has the read permission.<br>-&nbsp;**0o020**: The user group has the write permission.<br>-&nbsp;**0o010**: The user group has the execute permission.<br>-&nbsp;**0o007**: Other users have the read, write, and execute permissions.<br>-&nbsp;**0o004**: Other users have the read permission.<br>-&nbsp;**0o002**: Other users have the write permission.<br>-&nbsp;**0o001**: Other users have the execute permission.| | mode | number | No | Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (&#124;). The default value is **0o666**.<br>- **0o666**: The owner, user group, and other users have the read and write permissions.<br>- **0o700**: The owner has the read, write, and execute permissions.<br>- **0o400**: The owner has the read permission.<br>- **0o200**: The owner has the write permission.<br>- **0o100**: The owner has the execute permission.<br>- **0o070**: The user group has the read, write, and execute permissions.<br>- **0o040**: The user group has the read permission.<br>- **0o020**: The user group has the write permission.<br>- **0o010**: The user group has the execute permission.<br>- **0o007**: Other users have the read, write, and execute permissions.<br>- **0o004**: Other users have the read permission.<br>- **0o002**: Other users have the write permission.<br>- **0o001**: Other users have the execute permission. |
**Return value** **Return value**
| Type | Description | | Type | Description |
| --------------------- | ----------- | | --------------------- | ----------- |
| Promise&lt;number&gt; | Promise used to return the file descriptor of the file opened.| | Promise&lt;number&gt; | Promise used to return the file descriptor of the file opened.|
**Example** **Example**
...@@ -603,8 +603,8 @@ Opens a file. This API uses an asynchronous callback to return the result. ...@@ -603,8 +603,8 @@ Opens a file. This API uses an asynchronous callback to return the result.
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------------- | ---- | ------------------------------------------------------------ | | -------- | ------------------------------- | ---- | ------------------------------------------------------------ |
| path | string | Yes | Application sandbox path of the file. | | path | string | Yes | Application sandbox path of the file. |
| flags | number | No | Option for opening the file. You must specify one of the following options. By default, the file is open in read-only mode.<br>-&nbsp;**0o0**: Open the file in read-only mode.<br>-&nbsp;**0o1**: Open the file in write-only mode.<br>-&nbsp;**0o2**: Open the file in read/write mode.<br>In addition, you can specify the following options, separated using a bitwise OR operator (&#124;). By default, no additional option is specified.<br>-&nbsp;**0o100**: If the file does not exist, create it. If you use this option, you must also specify **mode**.<br>-&nbsp;**0o200**: If **0o100** is added and the file already exists, throw an exception.<br>-&nbsp;**0o1000**: If the file exists and is open in write-only or read/write mode, truncate the file length to 0.<br>-&nbsp;**0o2000**: Open the file in append mode. New data will be appended to the file (added to the end of the file).<br>-&nbsp;**0o4000**: If **path** points to a named pipe (also known as a FIFO), block special file, or character special file, perform non-blocking operations on the open file and in subsequent I/Os.<br>-&nbsp;**0o200000**: If **path** does not point to a directory, throw an exception.<br><br>-&nbsp;**0o400000**: If **path** points to a symbolic link, throw an exception.<br>-&nbsp;**0o4010000**: Open the file in synchronous I/O mode.| | flags | number | No | Option for opening the file. You must specify one of the following options. By default, the file is open in read-only mode.<br>- **0o0**: Open the file in read-only mode.<br>- **0o1**: Open the file in write-only mode.<br>- **0o2**: Open the file in read/write mode.<br>In addition, you can specify the following options, separated using a bitwise OR operator (&#124;). By default, no additional option is specified.<br>- **0o100**: If the file does not exist, create a file. The third parameter **mode** must also be specified.<br>- **0o200**: If **0o100** is added and the file already exists, throw an exception.<br>- **0o1000**: If the file exists and is open in write-only or read/write mode, truncate the file length to 0.<br>- **0o2000**: Open the file in append mode. New data will be appended to the file (written to the end of the file).<br>- **0o4000**: If **path** points to a named pipe (also known as a FIFO), block special file, or character special file, perform non-blocking operations on the open file and in subsequent I/Os.<br>- **0o200000**: If **path** does not point to a directory, throw an exception.<br>- **0o400000**: If **path** points to a symbolic link, throw an exception.<br>- **0o4010000**: Open the file in synchronous I/O mode.|
| mode | number | No | Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (&#124;). The default value is **0o666**.<br>-&nbsp;**0o666**: The owner, user group, and other users have the read and write permissions on the file.<br>-&nbsp;**0o700**: The owner has the read, write, and execute permissions.<br>- &nbsp;**0o400**: The owner has the read permission.<br>-&nbsp;**0o200**: The owner has the write permission.<br>-&nbsp;**0o100**: The owner has the execute permission.<br>-&nbsp;**0o070**: The user group has the read, write, and execute permissions.<br>-&nbsp;**0o040**: The user group has the read permission.<br>-&nbsp;**0o020**: The user group has the write permission.<br>-&nbsp;**0o010**: The user group has the execute permission.<br>-&nbsp;**0o007**: Other users have the read, write, and execute permissions.<br>-&nbsp;**0o004**: Other users have the read permission.<br>-&nbsp;**0o002**: Other users have the write permission.<br>-&nbsp;**0o001**: Other users have the execute permission.| | mode | number | No | Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (&#124;). The default value is **0o666**.<br>- **0o666**: The owner, user group, and other users have the read and write permissions.<br>- **0o700**: The owner has the read, write, and execute permissions.<br>- **0o400**: The owner has the read permission.<br>- **0o200**: The owner has the write permission.<br>- **0o100**: The owner has the execute permission.<br>- **0o070**: The user group has the read, write, and execute permissions.<br>- **0o040**: The user group has the read permission.<br>- **0o020**: The user group has the write permission.<br>- **0o010**: The user group has the execute permission.<br>- **0o007**: Other users have the read, write, and execute permissions.<br>- **0o004**: Other users have the read permission.<br>- **0o002**: Other users have the write permission.<br>- **0o001**: Other users have the execute permission. |
| callback | AsyncCallback&lt;number&gt; | Yes | Callback invoked when the file is open asynchronously. | | callback | AsyncCallback&lt;number&gt; | Yes | Callback invoked when the file is open asynchronously. |
**Example** **Example**
...@@ -630,14 +630,14 @@ Synchronously opens a file. ...@@ -630,14 +630,14 @@ Synchronously opens a file.
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------------------------------------------------ | | ------ | ------ | ---- | ------------------------------------------------------------ |
| path | string | Yes | Application sandbox path of the file. | | path | string | Yes | Application sandbox path of the file. |
| flags | number | No | Option for opening the file. You must specify one of the following options. By default, the file is open in read-only mode.<br>-&nbsp;**0o0**: Open the file in read-only mode.<br>-&nbsp;**0o1**: Open the file in write-only mode.<br>-&nbsp;**0o2**: Open the file in read/write mode.<br>In addition, you can specify the following options, separated using a bitwise OR operator (&#124;). By default, no additional option is specified.<br>-&nbsp;**0o100**: If the file does not exist, create it. If you use this option, you must also specify **mode**.<br>-&nbsp;**0o200**: If **0o100** is added and the file already exists, throw an exception.<br>-&nbsp;**0o1000**: If the file exists and is open in write-only or read/write mode, truncate the file length to 0.<br>-&nbsp;**0o2000**: Open the file in append mode. New data will be appended to the file (added to the end of the file).<br>-&nbsp;**0o4000**: If **path** points to a named pipe (also known as a FIFO), block special file, or character special file, perform non-blocking operations on the open file and in subsequent I/Os.<br>-&nbsp;**0o200000**: If **path** does not point to a directory, throw an exception.<br><br>-&nbsp;**0o400000**: If **path** points to a symbolic link, throw an exception.<br>-&nbsp;**0o4010000**: Open the file in synchronous I/O mode.| | flags | number | No | Option for opening the file. You must specify one of the following options. By default, the file is open in read-only mode.<br>- **0o0**: Open the file in read-only mode.<br>- **0o1**: Open the file in write-only mode.<br>- **0o2**: Open the file in read/write mode.<br>In addition, you can specify the following options, separated using a bitwise OR operator (&#124;). By default, no additional option is specified.<br>- **0o100**: If the file does not exist, create a file. The third parameter **mode** must also be specified.<br>- **0o200**: If **0o100** is added and the file already exists, throw an exception.<br>- **0o1000**: If the file exists and is open in write-only or read/write mode, truncate the file length to 0.<br>- **0o2000**: Open the file in append mode. New data will be appended to the file (written to the end of the file).<br>- **0o4000**: If **path** points to a named pipe (also known as a FIFO), block special file, or character special file, perform non-blocking operations on the open file and in subsequent I/Os.<br>- **0o200000**: If **path** does not point to a directory, throw an exception.<br>- **0o400000**: If **path** points to a symbolic link, throw an exception.<br>- **0o4010000**: Open the file in synchronous I/O mode.|
| mode | number | No | Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (&#124;). The default value is **0o666**.<br>-&nbsp;**0o666**: The owner, user group, and other users have the read and write permissions on the file.<br>-&nbsp;**0o640**: The owner has the read and write permissions, and the user group has the read permission.<br>-&nbsp;**0o700**: The owner has the read, write, and execute permissions.<br>- &nbsp;**0o400**: The owner has the read permission.<br>-&nbsp;**0o200**: The owner has the write permission.<br>-&nbsp;**0o100**: The owner has the execute permission.<br>-&nbsp;**0o070**: The user group has the read, write, and execute permissions.<br>-&nbsp;**0o040**: The user group has the read permission.<br>-&nbsp;**0o020**: The user group has the write permission.<br>-&nbsp;**0o010**: The user group has the execute permission.<br>-&nbsp;**0o007**: Other users have the read, write, and execute permissions.<br>-&nbsp;**0o004**: Other users have the read permission.<br>-&nbsp;**0o002**: Other users have the write permission.<br>-&nbsp;**0o001**: Other users have the execute permission.<br>The file permissions on newly created files are affected by umask, which is set as the process starts. Currently, the modification of umask is not open.| | mode | number | No | Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (&#124;). The default value is **0o666**.<br>- **0o666**: The owner, user group, and other users have the read and write permissions.<br>- **0o640**: The owner has the read and write permissions, and the user group has the read permission.<br>- **0o700**: The owner has the read, write, and execute permissions.<br>- **0o400**: The owner has the read permission.<br>- **0o200**: The owner has the write permission.<br>- **0o100**: The owner has the execute permission.<br>- **0o070**: The user group has the read, write, and execute permissions.<br>- **0o040**: The user group has the read permission.<br>- **0o020**: The user group has the write permission.<br>- **0o010**: The user group has the execute permission.<br>- **0o007**: Other users have the read, write, and execute permissions.<br>- **0o004**: Other users have the read permission.<br>- **0o002**: Other users have the write permission.<br>- **0o001**: Other users have the execute permission.<br>The file permissions on newly created files are affected by umask, which is set as the process starts. Currently, the modification of umask is not open. |
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------ | ----------- | | ------ | ----------- |
| number | File descriptor of the file opened.| | number | File descriptor of the file opened.|
**Example** **Example**
...@@ -670,13 +670,13 @@ Reads data from a file. This API uses a promise to return the result. ...@@ -670,13 +670,13 @@ Reads data from a file. This API uses a promise to return the result.
| ------- | ----------- | ---- | ------------------------------------------------------------ | | ------- | ----------- | ---- | ------------------------------------------------------------ |
| fd | number | Yes | File descriptor of the file to read. | | fd | number | Yes | File descriptor of the file to read. |
| buffer | ArrayBuffer | Yes | Buffer used to store the file data read. | | buffer | ArrayBuffer | Yes | Buffer used to store the file data read. |
| options | Object | No | The options are as follows:<br>-&nbsp;**offset** (number): position to store the data read in the buffer in reference to the start address of the buffer. The default value is **0**.<br>-&nbsp;**length** (number): length of the data to read. The default value is the buffer length minus the offset.<br>-&nbsp;**position** (number): position of the data to read in the file. By default, data is read from the current position.<br>Constraints: offset + length <= Buffer size| | options | Object | No | The options are as follows:<br>- **offset** (number): position to store the data read in the buffer in reference to the start address of the buffer. The default value is **0**.<br>- **length** (number): length of the data to read. The default value is the buffer length minus the offset.<br>- **position** (number): position of the data to read in the file. By default, data is read from the current position.<br>Constraints: offset + length <= Buffer size|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ---------------------------------- | ------ | | ---------------------------------- | ------ |
| Promise&lt;[ReadOut](#readout)&gt; | Promise used to return the data read.| | Promise&lt;[ReadOut](#readout)&gt; | Promise used to return the data read.|
**Example** **Example**
...@@ -703,12 +703,12 @@ Reads data from a file. This API uses an asynchronous callback to return the res ...@@ -703,12 +703,12 @@ Reads data from a file. This API uses an asynchronous callback to return the res
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- | | -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| fd | number | Yes | File descriptor of the file to read. | | fd | number | Yes | File descriptor of the file to read. |
| buffer | ArrayBuffer | Yes | Buffer used to store the file data read. | | buffer | ArrayBuffer | Yes | Buffer used to store the file data read. |
| options | Object | No | The options are as follows:<br>-&nbsp;**offset** (number): position to store the data read in the buffer in reference to the start address of the buffer. The default value is **0**.<br>-&nbsp;**length** (number): length of the data to read. The default value is the buffer length minus the offset.<br>-&nbsp;**position** (number): position of the data to read in the file. By default, data is read from the current position.<br>Constraints: offset + length <= Buffer size | | options | Object | No | The options are as follows:<br>- **offset** (number): position to store the data read in the buffer in reference to the start address of the buffer. The default value is **0**.<br>- **length** (number): length of the data to read. The default value is the buffer length minus the offset.<br>- **position** (number): position of the data to read in the file. By default, data is read from the current position.<br>Constraints: offset + length <= Buffer size |
| callback | AsyncCallback&lt;[ReadOut](#readout)&gt; | Yes | Callback invoked when the data is read asynchronously. | | callback | AsyncCallback&lt;[ReadOut](#readout)&gt; | Yes | Callback invoked when the data is read asynchronously. |
**Example** **Example**
...@@ -735,17 +735,17 @@ Synchronously reads data from a file. ...@@ -735,17 +735,17 @@ Synchronously reads data from a file.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------- | ----------- | ---- | ---------------------------------------- | | ------- | ----------- | ---- | ---------------------------------------- |
| fd | number | Yes | File descriptor of the file to read. | | fd | number | Yes | File descriptor of the file to read. |
| buffer | ArrayBuffer | Yes | Buffer used to store the file data read. | | buffer | ArrayBuffer | Yes | Buffer used to store the file data read. |
| options | Object | No | The options are as follows:<br>-&nbsp;**offset** (number): position to store the data read in the buffer in reference to the start address of the buffer. The default value is **0**.<br>-&nbsp;**length** (number): length of the data to read. The default value is the buffer length minus the offset.<br>-&nbsp;**position** (number): position of the data to read in the file. By default, data is read from the current position.<br>Constraints: offset + length <= Buffer size | | options | Object | No | The options are as follows:<br>- **offset** (number): position to store the data read in the buffer in reference to the start address of the buffer. The default value is **0**.<br>- **length** (number): length of the data to read. The default value is the buffer length minus the offset.<br>- **position** (number): position of the data to read in the file. By default, data is read from the current position.<br>Constraints: offset + length <= Buffer size |
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------ | -------- | | ------ | -------- |
| number | Length of the data read.| | number | Length of the data read.|
**Example** **Example**
...@@ -773,9 +773,9 @@ Deletes a directory. This API uses a promise to return the result. ...@@ -773,9 +773,9 @@ Deletes a directory. This API uses a promise to return the result.
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.| | Promise&lt;void&gt; | Promise that returns no value.|
**Example** **Example**
...@@ -853,9 +853,9 @@ Deletes a file. This API uses a promise to return the result. ...@@ -853,9 +853,9 @@ Deletes a file. This API uses a promise to return the result.
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.| | Promise&lt;void&gt; | Promise that returns no value.|
**Example** **Example**
...@@ -926,17 +926,17 @@ Writes data into a file. This API uses a promise to return the result. ...@@ -926,17 +926,17 @@ Writes data into a file. This API uses a promise to return the result.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------- | ------------------------------- | ---- | ---------------------------------------- | | ------- | ------------------------------- | ---- | ---------------------------------------- |
| fd | number | Yes | File descriptor of the file to write. | | fd | number | Yes | File descriptor of the file to write. |
| buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. | | buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. |
| options | Object | No | The options are as follows:<br>-&nbsp;**offset** (number): position of the data to write in reference to the start address of the data. The default value is **0**.<br>-&nbsp;**length** (number): length of the data to write. The default value is the buffer length minus the offset.<br>-&nbsp;**position** (number): start position to write the data in the file. By default, data is written from the current position.<br>-&nbsp;**encoding** (string): format of the string to be encoded. The default value is **utf-8**, which is the only value supported.<br>Constraints: offset + length <= Buffer size| | options | Object | No | The options are as follows:<br>- **offset** (number): position of the data to write in reference to the start address of the data. The default value is **0**.<br>- **length** (number): length of the data to write. The default value is the buffer length minus the offset.<br>- **position** (number): start position to write the data in the file. By default, data is written from the current position.<br>- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **'utf-8'**, which is the only value supported.<br>Constraints: offset + length <= Buffer size|
**Return value** **Return value**
| Type | Description | | Type | Description |
| --------------------- | -------- | | --------------------- | -------- |
| Promise&lt;number&gt; | Promise used to return the length of the data written.| | Promise&lt;number&gt; | Promise used to return the length of the data written.|
**Example** **Example**
...@@ -961,12 +961,12 @@ Writes data into a file. This API uses an asynchronous callback to return the re ...@@ -961,12 +961,12 @@ Writes data into a file. This API uses an asynchronous callback to return the re
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ------------------------------- | ---- | ---------------------------------------- | | -------- | ------------------------------- | ---- | ---------------------------------------- |
| fd | number | Yes | File descriptor of the file to write. | | fd | number | Yes | File descriptor of the file to write. |
| buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. | | buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. |
| options | Object | No | The options are as follows:<br>-&nbsp;**offset** (number): position of the data to write in reference to the start address of the data. The default value is **0**.<br>-&nbsp;**length** (number): length of the data to write. The default value is the buffer length minus the offset.<br>-&nbsp;**position** (number): start position to write the data in the file. By default, data is written from the current position.<br>-&nbsp;**encoding** (string): format of the string to be encoded. The default value is **utf-8**, which is the only value supported.<br>Constraints: offset + length <= Buffer size| | options | Object | No | The options are as follows:<br>- **offset** (number): position of the data to write in reference to the start address of the data. The default value is **0**.<br>- **length** (number): length of the data to write. The default value is the buffer length minus the offset.<br>- **position** (number): start position to write the data in the file. By default, data is written from the current position.<br>- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **'utf-8'**, which is the only value supported.<br>Constraints: offset + length <= Buffer size|
| callback | AsyncCallback&lt;number&gt; | Yes | Callback invoked when the data is written asynchronously. | | callback | AsyncCallback&lt;number&gt; | Yes | Callback invoked when the data is written asynchronously. |
**Example** **Example**
...@@ -991,17 +991,17 @@ Synchronously writes data into a file. ...@@ -991,17 +991,17 @@ Synchronously writes data into a file.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------- | ------------------------------- | ---- | ---------------------------------------- | | ------- | ------------------------------- | ---- | ---------------------------------------- |
| fd | number | Yes | File descriptor of the file to write. | | fd | number | Yes | File descriptor of the file to write. |
| buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. | | buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. |
| options | Object | No | The options are as follows:<br>-&nbsp;**offset** (number): position of the data to write in reference to the start address of the data. The default value is **0**.<br>-&nbsp;**length** (number): length of the data to write. The default value is the buffer length minus the offset.<br>-&nbsp;**position** (number): start position to write the data in the file. By default, data is written from the current position.<br>-&nbsp;**encoding** (string): format of the string to be encoded. The default value is **utf-8**, which is the only value supported.<br>Constraints: offset + length <= Buffer size| | options | Object | No | The options are as follows:<br>- **offset** (number): position of the data to write in reference to the start address of the data. The default value is **0**.<br>- **length** (number): length of the data to write. The default value is the buffer length minus the offset.<br>- **position** (number): start position to write the data in the file. By default, data is written from the current position.<br>- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **'utf-8'**, which is the only value supported.<br>Constraints: offset + length <= Buffer size|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------ | -------- | | ------ | -------- |
| number | Length of the data written in the file.| | number | Length of the data written in the file.|
**Example** **Example**
...@@ -1029,9 +1029,9 @@ Calculates the hash value of a file. This API uses a promise to return the resul ...@@ -1029,9 +1029,9 @@ Calculates the hash value of a file. This API uses a promise to return the resul
**Return value** **Return value**
| Type | Description | | Type | Description |
| --------------------- | -------------------------- | | --------------------- | -------------------------- |
| Promise&lt;string&gt; | Promise used to return the hash value obtained. The hash value is a hexadecimal string consisting of digits and uppercase letters.| | Promise&lt;string&gt; | Promise used to return the hash value obtained. The hash value is a hexadecimal string consisting of digits and uppercase letters.|
**Example** **Example**
...@@ -1086,13 +1086,13 @@ Changes file permissions. This API uses a promise to return the result. ...@@ -1086,13 +1086,13 @@ Changes file permissions. This API uses a promise to return the result.
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------------------------------------------------ | | ------ | ------ | ---- | ------------------------------------------------------------ |
| path | string | Yes | Application sandbox path of the file. | | path | string | Yes | Application sandbox path of the file. |
| mode | number | Yes | Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (&#124;).<br>-&nbsp;**0o700**: The owner has the read, write, and execute permissions.<br>- &nbsp;**0o400**: The owner has the read permission.<br>-&nbsp;**0o200**: The owner has the write permission.<br>-&nbsp;**0o100**: The owner has the execute permission.<br>-&nbsp;**0o070**: The user group has the read, write, and execute permissions.<br>-&nbsp;**0o040**: The user group has the read permission.<br>-&nbsp;**0o020**: The user group has the write permission.<br>-&nbsp;**0o010**: The user group has the execute permission.<br>-&nbsp;**0o007**: Other users have the read, write, and execute permissions.<br>-&nbsp;**0o004**: Other users have the read permission.<br>-&nbsp;**0o002**: Other users have the write permission.<br>-&nbsp;**0o001**: Other users have the execute permission.| | mode | number | Yes | Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (&#124;).<br>- **0o700**: The owner has the read, write, and execute permissions.<br>- **0o400**: The owner has the read permission.<br>- **0o200**: The owner has the write permission.<br>- **0o100**: The owner has the execute permission.<br>- **0o070**: The user group has the read, write, and execute permissions.<br>- **0o040**: The user group has the read permission.<br>- **0o020**: The user group has the write permission.<br>- **0o010**: The user group has the execute permission.<br>- **0o007**: Other users have the read, write, and execute permissions.<br>- **0o004**: Other users have the read permission.<br>- **0o002**: Other users have the write permission.<br>- **0o001**: Other users have the execute permission. |
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.| | Promise&lt;void&gt; | Promise that returns no value.|
**Example** **Example**
...@@ -1119,7 +1119,7 @@ Changes file permissions. This API uses an asynchronous callback to return the r ...@@ -1119,7 +1119,7 @@ Changes file permissions. This API uses an asynchronous callback to return the r
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ------------------------------------------------------------ | | -------- | ------------------------- | ---- | ------------------------------------------------------------ |
| path | string | Yes | Application sandbox path of the file. | | path | string | Yes | Application sandbox path of the file. |
| mode | number | Yes | Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (&#124;).<br>-&nbsp;**0o700**: The owner has the read, write, and execute permissions.<br>- &nbsp;**0o400**: The owner has the read permission.<br>-&nbsp;**0o200**: The owner has the write permission.<br>-&nbsp;**0o100**: The owner has the execute permission.<br>-&nbsp;**0o070**: The user group has the read, write, and execute permissions.<br>-&nbsp;**0o040**: The user group has the read permission.<br>-&nbsp;**0o020**: The user group has the write permission.<br>-&nbsp;**0o010**: The user group has the execute permission.<br>-&nbsp;**0o007**: Other users have the read, write, and execute permissions.<br>-&nbsp;**0o004**: Other users have the read permission.<br>-&nbsp;**0o002**: Other users have the write permission.<br>-&nbsp;**0o001**: Other users have the execute permission.| | mode | number | Yes | Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (&#124;).<br>- **0o700**: The owner has the read, write, and execute permissions.<br>- **0o400**: The owner has the read permission.<br>- **0o200**: The owner has the write permission.<br>- **0o100**: The owner has the execute permission.<br>- **0o070**: The user group has the read, write, and execute permissions.<br>- **0o040**: The user group has the read permission.<br>- **0o020**: The user group has the write permission.<br>- **0o010**: The user group has the execute permission.<br>- **0o007**: Other users have the read, write, and execute permissions.<br>- **0o004**: Other users have the read permission.<br>- **0o002**: Other users have the write permission.<br>- **0o001**: Other users have the execute permission. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file permissions are changed asynchronously. | | callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file permissions are changed asynchronously. |
**Example** **Example**
...@@ -1145,7 +1145,7 @@ Synchronously changes file permissions. ...@@ -1145,7 +1145,7 @@ Synchronously changes file permissions.
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------------------------------------------------ | | ------ | ------ | ---- | ------------------------------------------------------------ |
| path | string | Yes | Application sandbox path of the file. | | path | string | Yes | Application sandbox path of the file. |
| mode | number | Yes | Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (&#124;).<br>-&nbsp;**0o700**: The owner has the read, write, and execute permissions.<br>- &nbsp;**0o400**: The owner has the read permission.<br>-&nbsp;**0o200**: The owner has the write permission.<br>-&nbsp;**0o100**: The owner has the execute permission.<br>-&nbsp;**0o070**: The user group has the read, write, and execute permissions.<br>-&nbsp;**0o040**: The user group has the read permission.<br>-&nbsp;**0o020**: The user group has the write permission.<br>-&nbsp;**0o010**: The user group has the execute permission.<br>-&nbsp;**0o007**: Other users have the read, write, and execute permissions.<br>-&nbsp;**0o004**: Other users have the read permission.<br>-&nbsp;**0o002**: Other users have the write permission.<br>-&nbsp;**0o001**: Other users have the execute permission.| | mode | number | Yes | Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (&#124;).<br>- **0o700**: The owner has the read, write, and execute permissions.<br>- **0o400**: The owner has the read permission.<br>- **0o200**: The owner has the write permission.<br>- **0o100**: The owner has the execute permission.<br>- **0o070**: The user group has the read, write, and execute permissions.<br>- **0o040**: The user group has the read permission.<br>- **0o020**: The user group has the write permission.<br>- **0o010**: The user group has the execute permission.<br>- **0o007**: Other users have the read, write, and execute permissions.<br>- **0o004**: Other users have the read permission.<br>- **0o002**: Other users have the write permission.<br>- **0o001**: Other users have the execute permission. |
**Example** **Example**
...@@ -1165,15 +1165,15 @@ Obtains file information based on the file descriptor. This API uses a promise t ...@@ -1165,15 +1165,15 @@ Obtains file information based on the file descriptor. This API uses a promise t
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ------------ | | ---- | ------ | ---- | ------------ |
| fd | number | Yes | Descriptor of the target file.| | fd | number | Yes | Descriptor of the target file.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ---------------------------- | ---------- | | ---------------------------- | ---------- |
| Promise&lt;[Stat](#stat)&gt; | Promise used to return the file information.| | Promise&lt;[Stat](#stat)&gt; | Promise used to return the file information obtained.|
**Example** **Example**
...@@ -1198,10 +1198,10 @@ Obtains file information based on the file descriptor. This API uses an asynchro ...@@ -1198,10 +1198,10 @@ Obtains file information based on the file descriptor. This API uses an asynchro
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ---------------------------------- | ---- | ---------------- | | -------- | ---------------------------------- | ---- | ---------------- |
| fd | number | Yes | File descriptor of the target file. | | fd | number | Yes | File descriptor of the target file. |
| callback | AsyncCallback&lt;[Stat](#stat)&gt; | Yes | Callback invoked to return the file information obtained.| | callback | AsyncCallback&lt;[Stat](#stat)&gt; | Yes | Callback invoked to return the file information obtained.|
**Example** **Example**
...@@ -1224,15 +1224,15 @@ Synchronously obtains file information based on the file descriptor. ...@@ -1224,15 +1224,15 @@ Synchronously obtains file information based on the file descriptor.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ------------ | | ---- | ------ | ---- | ------------ |
| fd | number | Yes | File descriptor of the target file.| | fd | number | Yes | File descriptor of the target file.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------- | ---------- | | ------------- | ---------- |
| [Stat](#stat) | File information obtained.| | [Stat](#stat) | File information obtained.|
**Example** **Example**
...@@ -1253,16 +1253,16 @@ Truncates a file based on the file descriptor. This API uses a promise to return ...@@ -1253,16 +1253,16 @@ Truncates a file based on the file descriptor. This API uses a promise to return
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ---------------- | | ---- | ------ | ---- | ---------------- |
| fd | number | Yes | File descriptor of the file to truncate. | | fd | number | Yes | File descriptor of the file to truncate. |
| len | number | No | File length, in bytes, after truncation.| | len | number | No | File length, in bytes, after truncation.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.| | Promise&lt;void&gt; | Promise that returns no value.|
**Example** **Example**
...@@ -1287,11 +1287,11 @@ Truncates a file based on the file descriptor. This API uses an asynchronous cal ...@@ -1287,11 +1287,11 @@ Truncates a file based on the file descriptor. This API uses an asynchronous cal
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ------------------------- | ---- | ---------------- | | -------- | ------------------------- | ---- | ---------------- |
| fd | number | Yes | File descriptor of the file to truncate. | | fd | number | Yes | File descriptor of the file to truncate. |
| len | number | No | File length, in bytes, after truncation.| | len | number | No | File length, in bytes, after truncation.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback that returns no value. | | callback | AsyncCallback&lt;void&gt; | Yes | Callback that returns no value. |
**Example** **Example**
...@@ -1315,10 +1315,10 @@ Synchronously truncates a file based on the file descriptor. ...@@ -1315,10 +1315,10 @@ Synchronously truncates a file based on the file descriptor.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ---------------- | | ---- | ------ | ---- | ---------------- |
| fd | number | Yes | File descriptor of the file to truncate. | | fd | number | Yes | File descriptor of the file to truncate. |
| len | number | No | File length, in bytes, after truncation.| | len | number | No | File length, in bytes, after truncation.|
**Example** **Example**
...@@ -1347,9 +1347,9 @@ Truncates a file based on the file path. This API uses a promise to return the r ...@@ -1347,9 +1347,9 @@ Truncates a file based on the file path. This API uses a promise to return the r
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.| | Promise&lt;void&gt; | Promise that returns no value.|
**Example** **Example**
...@@ -1376,7 +1376,7 @@ Truncates a file based on the file path. This API uses an asynchronous callback ...@@ -1376,7 +1376,7 @@ Truncates a file based on the file path. This API uses an asynchronous callback
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | -------------------------------- | | -------- | ------------------------- | ---- | -------------------------------- |
| path | string | Yes | Application sandbox path of the file to truncate.| | path | string | Yes | Application sandbox path of the file to truncate. |
| len | number | No | File length, in bytes, after truncation.| | len | number | No | File length, in bytes, after truncation.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback that returns no value. | | callback | AsyncCallback&lt;void&gt; | Yes | Callback that returns no value. |
...@@ -1403,7 +1403,7 @@ Synchronously truncates a file based on the file path. ...@@ -1403,7 +1403,7 @@ Synchronously truncates a file based on the file path.
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | ------ | ---- | -------------------------------- | | ------ | ------ | ---- | -------------------------------- |
| path | string | Yes | Application sandbox path of the file to truncate.| | path | string | Yes | Application sandbox path of the file to truncate. |
| len | number | No | File length, in bytes, after truncation.| | len | number | No | File length, in bytes, after truncation.|
**Example** **Example**
...@@ -1428,13 +1428,13 @@ Reads the text content of a file. This API uses a promise to return the result. ...@@ -1428,13 +1428,13 @@ Reads the text content of a file. This API uses a promise to return the result.
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------ | ---- | ------------------------------------------------------------ | | -------- | ------ | ---- | ------------------------------------------------------------ |
| filePath | string | Yes | Application sandbox path of the file to read. | | filePath | string | Yes | Application sandbox path of the file to read. |
| options | Object | No | The options are as follows:<br>-&nbsp;**position** (number): position of the data to read in the file. By default, data is read from the current position.<br>-&nbsp;**length** (number): length of the data to read. The default value is the buffer length minus the offset.<br>-&nbsp;**encoding** (string): format of the data (string) to be encoded. The default value is **utf-8**, which is the only value supported.| | options | Object | No | The options are as follows:<br>- **position** (number): position of the data to read in the file. By default, data is read from the current position.<br>- **length** (number): length of the data to read. The default value is the buffer length minus the offset.<br>- **encoding** (string): format of the string to be encoded. The default value is **'utf-8'**, which is the only value supported.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| --------------------- | ---------- | | --------------------- | ---------- |
| Promise&lt;string&gt; | Promise used to return the content read.| | Promise&lt;string&gt; | Promise used to return the content read.|
**Example** **Example**
...@@ -1461,7 +1461,7 @@ Reads the text content of a file. This API uses an asynchronous callback to retu ...@@ -1461,7 +1461,7 @@ Reads the text content of a file. This API uses an asynchronous callback to retu
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | --------------------------- | ---- | ------------------------------------------------------------ | | -------- | --------------------------- | ---- | ------------------------------------------------------------ |
| filePath | string | Yes | Application sandbox path of the file to read. | | filePath | string | Yes | Application sandbox path of the file to read. |
| options | Object | No | The options are as follows:<br>-&nbsp;**position** (number): position of the data to read in the file. By default, data is read from the current position.<br>-&nbsp;**length** (number): length of the data to read. The default value is the buffer length minus the offset.<br>- &nbsp;**encoding**: format of the string to be encoded. The default value is &nbsp;**utf-8**, which is the only value supported.| | options | Object | No | The options are as follows:<br>- **position** (number): position of the data to read in the file. By default, data is read from the current position.<br>- **length** (number): length of the data to read. The default value is the buffer length minus the offset.<br>- **encoding** (string): format of the string to be encoded. The default value is **'utf-8'**, which is the only value supported.|
| callback | AsyncCallback&lt;string&gt; | Yes | Callback used to return the content read. | | callback | AsyncCallback&lt;string&gt; | Yes | Callback used to return the content read. |
**Example** **Example**
...@@ -1487,13 +1487,13 @@ Synchronously reads the text of a file. ...@@ -1487,13 +1487,13 @@ Synchronously reads the text of a file.
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------ | ---- | ------------------------------------------------------------ | | -------- | ------ | ---- | ------------------------------------------------------------ |
| filePath | string | Yes | Application sandbox path of the file to read. | | filePath | string | Yes | Application sandbox path of the file to read. |
| options | Object | No | The options are as follows:<br>-&nbsp;**position** (number): position of the data to read in the file. By default, data is read from the current position.<br>-&nbsp;**length** (number): length of the data to read. The default value is the buffer length minus the offset.<br>-&nbsp;**encoding** (string): format of the data (string) to be encoded. The default value is **utf-8**, which is the only value supported.| | options | Object | No | The options are as follows:<br>- **position** (number): position of the data to read in the file. By default, data is read from the current position.<br>- **length** (number): length of the data to read. The default value is the buffer length minus the offset.<br>- **encoding** (string): format of the string to be encoded. The default value is **'utf-8'**, which is the only value supported.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------ | -------------------- | | ------ | -------------------- |
| string | Promise used to return the content of the file read.| | string | Promise used to return the content of the file read.|
**Example** **Example**
...@@ -1519,9 +1519,9 @@ Obtains link information. This API uses a promise to return the result. ...@@ -1519,9 +1519,9 @@ Obtains link information. This API uses a promise to return the result.
**Return value** **Return value**
| Type | Description | | Type | Description |
| ---------------------------- | ---------- | | ---------------------------- | ---------- |
| Promise&lt;[Stat](#stat)&gt; | Promise used to return the link information obtained. For details, see [Stat](#stat).| | Promise&lt;[Stat](#stat)&gt; | Promise used to return the link information obtained. For details, see [Stat](#stat).|
**Example** **Example**
...@@ -1576,9 +1576,9 @@ Synchronously obtains the link information. ...@@ -1576,9 +1576,9 @@ Synchronously obtains the link information.
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------- | ---------- | | ------------- | ---------- |
| [Stat](#stat) | Link information obtained.| | [Stat](#stat) | Link information obtained.|
**Example** **Example**
...@@ -1605,9 +1605,9 @@ Renames a file. This API uses a promise to return the result. ...@@ -1605,9 +1605,9 @@ Renames a file. This API uses a promise to return the result.
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.| | Promise&lt;void&gt; | Promise that returns no value.|
**Example** **Example**
...@@ -1682,15 +1682,15 @@ Flushes data of a file to disk. This API uses a promise to return the result. ...@@ -1682,15 +1682,15 @@ Flushes data of a file to disk. This API uses a promise to return the result.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ------------ | | ---- | ------ | ---- | ------------ |
| fd | number | Yes | File descriptor of the file to flush.| | fd | number | Yes | File descriptor of the file to flush.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.| | Promise&lt;void&gt; | Promise that returns no value.|
**Example** **Example**
...@@ -1715,10 +1715,10 @@ Flushes data of a file to disk. This API uses an asynchronous callback to return ...@@ -1715,10 +1715,10 @@ Flushes data of a file to disk. This API uses an asynchronous callback to return
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ------------------------- | ---- | --------------- | | -------- | ------------------------- | ---- | --------------- |
| fd | number | Yes | File descriptor of the file to flush. | | fd | number | Yes | File descriptor of the file to flush. |
| Callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file is synchronized in asynchronous mode.| | Callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file is synchronized in asynchronous mode.|
**Example** **Example**
...@@ -1741,9 +1741,9 @@ Flushes data of a file to disk in synchronous mode. ...@@ -1741,9 +1741,9 @@ Flushes data of a file to disk in synchronous mode.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ------------ | | ---- | ------ | ---- | ------------ |
| fd | number | Yes | File descriptor of the file to flush.| | fd | number | Yes | File descriptor of the file to flush.|
**Example** **Example**
...@@ -1764,15 +1764,15 @@ Flushes data of a file to disk. This API uses a promise to return the result. ** ...@@ -1764,15 +1764,15 @@ Flushes data of a file to disk. This API uses a promise to return the result. **
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ------------ | | ---- | ------ | ---- | ------------ |
| fd | number | Yes | File descriptor of the file to flush.| | fd | number | Yes | File descriptor of the file to flush.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.| | Promise&lt;void&gt; | Promise that returns no value.|
**Example** **Example**
...@@ -1797,10 +1797,10 @@ Flushes data of a file to disk. This API uses an asynchronous callback to return ...@@ -1797,10 +1797,10 @@ Flushes data of a file to disk. This API uses an asynchronous callback to return
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ------------------------------- | ---- | ----------------- | | -------- | ------------------------------- | ---- | ----------------- |
| fd | number | Yes | File descriptor of the file to synchronize. | | fd | number | Yes | File descriptor of the file to synchronize. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file data is synchronized in asynchronous mode.| | callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file data is synchronized in asynchronous mode.|
**Example** **Example**
...@@ -1823,9 +1823,9 @@ Synchronizes data in a file in synchronous mode. ...@@ -1823,9 +1823,9 @@ Synchronizes data in a file in synchronous mode.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ------------ | | ---- | ------ | ---- | ------------ |
| fd | number | Yes | File descriptor of the file to flush.| | fd | number | Yes | File descriptor of the file to flush.|
**Example** **Example**
...@@ -1853,9 +1853,9 @@ Creates a symbolic link based on the file path. This API uses a promise to retur ...@@ -1853,9 +1853,9 @@ Creates a symbolic link based on the file path. This API uses a promise to retur
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.| | Promise&lt;void&gt; | Promise that returns no value.|
**Example** **Example**
...@@ -1939,9 +1939,9 @@ Changes the file owner based on the file path. This API uses a promise to return ...@@ -1939,9 +1939,9 @@ Changes the file owner based on the file path. This API uses a promise to return
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.| | Promise&lt;void&gt; | Promise that returns no value.|
**Example** **Example**
...@@ -2019,15 +2019,15 @@ Creates a temporary directory. This API uses a promise to return the result. ...@@ -2019,15 +2019,15 @@ Creates a temporary directory. This API uses a promise to return the result.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------ | ------ | ---- | --------------------------- | | ------ | ------ | ---- | --------------------------- |
| prefix | string | Yes | A randomly generated string used to replace "XXXXXX" in a directory.| | prefix | string | Yes | A randomly generated string used to replace "XXXXXX" in a directory.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| --------------------- | ---------- | | --------------------- | ---------- |
| Promise&lt;string&gt; | Promise used to return the unique directory generated.| | Promise&lt;string&gt; | Promise used to return the unique directory generated.|
**Example** **Example**
...@@ -2050,10 +2050,10 @@ Creates a temporary directory. This API uses an asynchronous callback to return ...@@ -2050,10 +2050,10 @@ Creates a temporary directory. This API uses an asynchronous callback to return
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | --------------------------- | ---- | --------------------------- | | -------- | --------------------------- | ---- | --------------------------- |
| prefix | string | Yes | A randomly generated string used to replace "XXXXXX" in a directory.| | prefix | string | Yes | A randomly generated string used to replace "XXXXXX" in a directory.|
| callback | AsyncCallback&lt;string&gt; | Yes | Callback invoked when a temporary directory is created asynchronously. | | callback | AsyncCallback&lt;string&gt; | Yes | Callback invoked when a temporary directory is created asynchronously. |
**Example** **Example**
...@@ -2074,15 +2074,15 @@ Synchronously creates a temporary directory. ...@@ -2074,15 +2074,15 @@ Synchronously creates a temporary directory.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------ | ------ | ---- | --------------------------- | | ------ | ------ | ---- | --------------------------- |
| prefix | string | Yes | A randomly generated string used to replace "XXXXXX" in a directory.| | prefix | string | Yes | A randomly generated string used to replace "XXXXXX" in a directory.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------ | ---------- | | ------ | ---------- |
| string | Unique path generated.| | string | Unique path generated.|
**Example** **Example**
...@@ -2101,16 +2101,16 @@ Changes file permissions based on the file descriptor. This API uses a promise t ...@@ -2101,16 +2101,16 @@ Changes file permissions based on the file descriptor. This API uses a promise t
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ---------------------------------------- | | ---- | ------ | ---- | ---------------------------------------- |
| fd | number | Yes | File descriptor of the target file. | | fd | number | Yes | File descriptor of the target file. |
| mode | number | Yes | Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (&#124;).<br>-&nbsp;**0o700**: The owner has the read, write, and execute permissions.<br>- &nbsp;**0o400**: The owner has the read permission.<br>-&nbsp;**0o200**: The owner has the write permission.<br>-&nbsp;**0o100**: The owner has the execute permission.<br>-&nbsp;**0o070**: The user group has the read, write, and execute permissions.<br>-&nbsp;**0o040**: The user group has the read permission.<br>-&nbsp;**0o020**: The user group has the write permission.<br>-&nbsp;**0o010**: The user group has the execute permission.<br>-&nbsp;**0o007**: Other users have the read, write, and execute permissions.<br>-&nbsp;**0o004**: Other users have the read permission.<br>-&nbsp;**0o002**: Other users have the write permission.<br>-&nbsp;**0o001**: Other users have the execute permission.| | mode | number | Yes | Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (&#124;).<br>- **0o700**: The owner has the read, write, and execute permissions.<br>- **0o400**: The owner has the read permission.<br>- **0o200**: The owner has the write permission.<br>- **0o100**: The owner has the execute permission.<br>- **0o070**: The user group has the read, write, and execute permissions.<br>- **0o040**: The user group has the read permission.<br>- **0o020**: The user group has the write permission.<br>- **0o010**: The user group has the execute permission.<br>- **0o007**: Other users have the read, write, and execute permissions.<br>- **0o004**: Other users have the read permission.<br>- **0o002**: Other users have the write permission.<br>- **0o001**: Other users have the execute permission. |
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.| | Promise&lt;void&gt; | Promise that returns no value.|
**Example** **Example**
...@@ -2136,11 +2136,11 @@ Changes file permissions based on the file descriptor. This API uses an asynchro ...@@ -2136,11 +2136,11 @@ Changes file permissions based on the file descriptor. This API uses an asynchro
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ------------------------------- | ---- | ---------------------------------------- | | -------- | ------------------------------- | ---- | ---------------------------------------- |
| fd | number | Yes | File descriptor of the target file. | | fd | number | Yes | File descriptor of the target file. |
| mode | number | Yes | Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (&#124;).<br>-&nbsp;**0o700**: The owner has the read, write, and execute permissions.<br>- &nbsp;**0o400**: The owner has the read permission.<br>-&nbsp;**0o200**: The owner has the write permission.<br>-&nbsp;**0o100**: The owner has the execute permission.<br>-&nbsp;**0o070**: The user group has the read, write, and execute permissions.<br>-&nbsp;**0o040**: The user group has the read permission.<br>-&nbsp;**0o020**: The user group has the write permission.<br>-&nbsp;**0o010**: The user group has the execute permission.<br>-&nbsp;**0o007**: Other users have the read, write, and execute permissions.<br>-&nbsp;**0o004**: Other users have the read permission.<br>-&nbsp;**0o002**: Other users have the write permission.<br>-&nbsp;**0o001**: Other users have the execute permission.| | mode | number | Yes | Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (&#124;).<br>- **0o700**: The owner has the read, write, and execute permissions.<br>- **0o400**: The owner has the read permission.<br>- **0o200**: The owner has the write permission.<br>- **0o100**: The owner has the execute permission.<br>- **0o070**: The user group has the read, write, and execute permissions.<br>- **0o040**: The user group has the read permission.<br>- **0o020**: The user group has the write permission.<br>- **0o010**: The user group has the execute permission.<br>- **0o007**: Other users have the read, write, and execute permissions.<br>- **0o004**: Other users have the read permission.<br>- **0o002**: Other users have the write permission.<br>- **0o001**: Other users have the execute permission. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file permissions are changed asynchronously. | | callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file permissions are changed asynchronously. |
**Example** **Example**
...@@ -2164,10 +2164,10 @@ Synchronously changes the file permissions based on the file descriptor. ...@@ -2164,10 +2164,10 @@ Synchronously changes the file permissions based on the file descriptor.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ---------------------------------------- | | ---- | ------ | ---- | ---------------------------------------- |
| fd | number | Yes | File descriptor of the target file. | | fd | number | Yes | File descriptor of the target file. |
| mode | number | Yes | Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (&#124;).<br>-&nbsp;**0o700**: The owner has the read, write, and execute permissions.<br>- &nbsp;**0o400**: The owner has the read permission.<br>-&nbsp;**0o200**: The owner has the write permission.<br>-&nbsp;**0o100**: The owner has the execute permission.<br>-&nbsp;**0o070**: The user group has the read, write, and execute permissions.<br>-&nbsp;**0o040**: The user group has the read permission.<br>-&nbsp;**0o020**: The user group has the write permission.<br>-&nbsp;**0o010**: The user group has the execute permission.<br>-&nbsp;**0o007**: Other users have the read, write, and execute permissions.<br>-&nbsp;**0o004**: Other users have the read permission.<br>-&nbsp;**0o002**: Other users have the write permission.<br>-&nbsp;**0o001**: Other users have the execute permission.| | mode | number | Yes | Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (&#124;).<br>- **0o700**: The owner has the read, write, and execute permissions.<br>- **0o400**: The owner has the read permission.<br>- **0o200**: The owner has the write permission.<br>- **0o100**: The owner has the execute permission.<br>- **0o070**: The user group has the read, write, and execute permissions.<br>- **0o040**: The user group has the read permission.<br>- **0o020**: The user group has the write permission.<br>- **0o010**: The user group has the execute permission.<br>- **0o007**: Other users have the read, write, and execute permissions.<br>- **0o004**: Other users have the read permission.<br>- **0o002**: Other users have the write permission.<br>- **0o001**: Other users have the execute permission. |
**Example** **Example**
...@@ -2192,13 +2192,13 @@ Opens a file stream based on the file path. This API uses a promise to return th ...@@ -2192,13 +2192,13 @@ Opens a file stream based on the file path. This API uses a promise to return th
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------------------------------------------------ | | ------ | ------ | ---- | ------------------------------------------------------------ |
| path | string | Yes | Application sandbox path of the file. | | path | string | Yes | Application sandbox path of the file. |
| mode | string | Yes | -&nbsp;**r**: Open a file for reading. The file must exist.<br>-&nbsp;**r+**: Open a file for both reading and writing. The file must exist.<br>-&nbsp;**w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.<br>-&nbsp;**w+**: Open a file for both reading and writing. If the file exists, clear its content. If the file does not exist, create a file.<br>-&nbsp;**a**: Open a file in append mode for writing at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).<br>-&nbsp;**a+**: Open a file in append mode for reading or updating at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).| | mode | string | Yes | - **r**: Open a file for reading. The file must exist.<br>- **r+**: Open a file for both reading and writing. The file must exist.<br>- **w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.<br>- **w+**: Open a file for both reading and writing. If the file exists, clear its content. If the file does not exist, create a file.<br>- **a**: Open a file in append mode for writing at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).<br>- **a+**: Open a file in append mode for reading or updating at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).|
**Return value** **Return value**
| Type | Description | | Type | Description |
| --------------------------------- | --------- | | --------------------------------- | --------- |
| Promise&lt;[Stream](#stream)&gt; | Promise used to return the result.| | Promise&lt;[Stream](#stream)&gt; | Promise used to return the result.|
**Example** **Example**
...@@ -2225,7 +2225,7 @@ Opens a file stream based on the file path. This API uses an asynchronous callba ...@@ -2225,7 +2225,7 @@ Opens a file stream based on the file path. This API uses an asynchronous callba
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | --------------------------------------- | ---- | ------------------------------------------------------------ | | -------- | --------------------------------------- | ---- | ------------------------------------------------------------ |
| path | string | Yes | Application sandbox path of the file. | | path | string | Yes | Application sandbox path of the file. |
| mode | string | Yes | -&nbsp;**r**: Open a file for reading. The file must exist.<br>-&nbsp;**r+**: Open a file for both reading and writing. The file must exist.<br>-&nbsp;**w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.<br>-&nbsp;**w+**: Open a file for both reading and writing. If the file exists, clear its content. If the file does not exist, create a file.<br>-&nbsp;**a**: Open a file in append mode for writing at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).<br>-&nbsp;**a+**: Open a file in append mode for reading or updating at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).| | mode | string | Yes | - **r**: Open a file for reading. The file must exist.<br>- **r+**: Open a file for both reading and writing. The file must exist.<br>- **w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.<br>- **w+**: Open a file for both reading and writing. If the file exists, clear its content. If the file does not exist, create a file.<br>- **a**: Open a file in append mode for writing at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).<br>- **a+**: Open a file in append mode for reading or updating at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).|
| callback | AsyncCallback&lt;[Stream](#stream)&gt; | Yes | Callback invoked when the stream is open asynchronously. | | callback | AsyncCallback&lt;[Stream](#stream)&gt; | Yes | Callback invoked when the stream is open asynchronously. |
**Example** **Example**
...@@ -2251,13 +2251,13 @@ Synchronously opens a stream based on the file path. ...@@ -2251,13 +2251,13 @@ Synchronously opens a stream based on the file path.
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------------------------------------------------ | | ------ | ------ | ---- | ------------------------------------------------------------ |
| path | string | Yes | Application sandbox path of the file. | | path | string | Yes | Application sandbox path of the file. |
| mode | string | Yes | -&nbsp;**r**: Open a file for reading. The file must exist.<br>-&nbsp;**r+**: Open a file for both reading and writing. The file must exist.<br>-&nbsp;**w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.<br>-&nbsp;**w+**: Open a file for both reading and writing. If the file exists, clear its content. If the file does not exist, create a file.<br>-&nbsp;**a**: Open a file in append mode for writing at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).<br>-&nbsp;**a+**: Open a file in append mode for reading or updating at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).| | mode | string | Yes | - **r**: Open a file for reading. The file must exist.<br>- **r+**: Open a file for both reading and writing. The file must exist.<br>- **w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.<br>- **w+**: Open a file for both reading and writing. If the file exists, clear its content. If the file does not exist, create a file.<br>- **a**: Open a file in append mode for writing at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).<br>- **a+**: Open a file in append mode for reading or updating at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------ | --------- | | ------------------ | --------- |
| [Stream](#stream) | Stream opened.| | [Stream](#stream) | Stream opened.|
**Example** **Example**
...@@ -2277,16 +2277,16 @@ Opens a file stream based on the file descriptor. This API uses a promise to ret ...@@ -2277,16 +2277,16 @@ Opens a file stream based on the file descriptor. This API uses a promise to ret
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ---------------------------------------- | | ---- | ------ | ---- | ---------------------------------------- |
| fd | number | Yes | File descriptor of the target file. | | fd | number | Yes | File descriptor of the target file. |
| mode | string | Yes | -&nbsp;**r**: Open a file for reading. The file must exist.<br>-&nbsp;**r+**: Open a file for both reading and writing. The file must exist.<br>-&nbsp;**w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.<br>-&nbsp;**w+**: Open a file for both reading and writing. If the file exists, clear its content. If the file does not exist, create a file.<br>-&nbsp;**a**: Open a file in append mode for writing at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).<br>-&nbsp;**a+**: Open a file in append mode for reading or updating at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).| | mode | string | Yes | - **r**: Open a file for reading. The file must exist.<br>- **r+**: Open a file for both reading and writing. The file must exist.<br>- **w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.<br>- **w+**: Open a file for both reading and writing. If the file exists, clear its content. If the file does not exist, create a file.<br>- **a**: Open a file in append mode for writing at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).<br>- **a+**: Open a file in append mode for reading or updating at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).|
**Return value** **Return value**
| Type | Description | | Type | Description |
| --------------------------------- | --------- | | --------------------------------- | --------- |
| Promise&lt;[Stream](#stream)&gt; | Promise used to return the result.| | Promise&lt;[Stream](#stream)&gt; | Promise used to return the result.|
**Example** **Example**
...@@ -2311,11 +2311,11 @@ Opens a file stream based on the file descriptor. This API uses an asynchronous ...@@ -2311,11 +2311,11 @@ Opens a file stream based on the file descriptor. This API uses an asynchronous
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- | | -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| fd | number | Yes | File descriptor of the target file. | | fd | number | Yes | File descriptor of the target file. |
| mode | string | Yes | -&nbsp;**r**: Open a file for reading. The file must exist.<br>-&nbsp;**r+**: Open a file for both reading and writing. The file must exist.<br>-&nbsp;**w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.<br>-&nbsp;**w+**: Open a file for both reading and writing. If the file exists, clear its content. If the file does not exist, create a file.<br>-&nbsp;**a**: Open a file in append mode for writing at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).<br>-&nbsp;**a+**: Open a file in append mode for reading or updating at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).| | mode | string | Yes | - **r**: Open a file for reading. The file must exist.<br>- **r+**: Open a file for both reading and writing. The file must exist.<br>- **w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.<br>- **w+**: Open a file for both reading and writing. If the file exists, clear its content. If the file does not exist, create a file.<br>- **a**: Open a file in append mode for writing at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).<br>- **a+**: Open a file in append mode for reading or updating at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).|
| callback | AsyncCallback&lt;[Stream](#stream)&gt; | Yes | Callback invoked when the stream is open asynchronously. | | callback | AsyncCallback&lt;[Stream](#stream)&gt; | Yes | Callback invoked when the stream is open asynchronously. |
**Example** **Example**
...@@ -2338,16 +2338,16 @@ Synchronously opens a stream based on the file descriptor. ...@@ -2338,16 +2338,16 @@ Synchronously opens a stream based on the file descriptor.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ---------------------------------------- | | ---- | ------ | ---- | ---------------------------------------- |
| fd | number | Yes | File descriptor of the target file. | | fd | number | Yes | File descriptor of the target file. |
| mode | string | Yes | -&nbsp;**r**: Open a file for reading. The file must exist.<br>-&nbsp;**r+**: Open a file for both reading and writing. The file must exist.<br>-&nbsp;**w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.<br>-&nbsp;**w+**: Open a file for both reading and writing. If the file exists, clear its content. If the file does not exist, create a file.<br>-&nbsp;**a**: Open a file in append mode for writing at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).<br>-&nbsp;**a+**: Open a file in append mode for reading or updating at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).| | mode | string | Yes | - **r**: Open a file for reading. The file must exist.<br>- **r+**: Open a file for both reading and writing. The file must exist.<br>- **w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.<br>- **w+**: Open a file for both reading and writing. If the file exists, clear its content. If the file does not exist, create a file.<br>- **a**: Open a file in append mode for writing at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).<br>- **a+**: Open a file in append mode for reading or updating at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------ | --------- | | ------------------ | --------- |
| [Stream](#stream) | Stream opened.| | [Stream](#stream) | Stream opened.|
**Example** **Example**
...@@ -2368,17 +2368,17 @@ Changes the file owner based on the file descriptor. This API uses a promise to ...@@ -2368,17 +2368,17 @@ Changes the file owner based on the file descriptor. This API uses a promise to
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ------------ | | ---- | ------ | ---- | ------------ |
| fd | number | Yes | File descriptor of the target file.| | fd | number | Yes | File descriptor of the target file.|
| uid | number | Yes | New UID. | | uid | number | Yes | New UID. |
| gid | number | Yes | New GID. | | gid | number | Yes | New GID. |
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.| | Promise&lt;void&gt; | Promise that returns no value.|
**Example** **Example**
...@@ -2404,12 +2404,12 @@ Changes the file owner based on the file descriptor. This API uses an asynchrono ...@@ -2404,12 +2404,12 @@ Changes the file owner based on the file descriptor. This API uses an asynchrono
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ------------------------- | ---- | --------------- | | -------- | ------------------------- | ---- | --------------- |
| fd | number | Yes | File descriptor of the target file. | | fd | number | Yes | File descriptor of the target file. |
| uid | number | Yes | New UID. | | uid | number | Yes | New UID. |
| gid | number | Yes | New GID. | | gid | number | Yes | New GID. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file owner is changed asynchronously.| | callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file owner is changed asynchronously.|
**Example** **Example**
...@@ -2433,11 +2433,11 @@ Synchronously changes the file owner based on the file descriptor. ...@@ -2433,11 +2433,11 @@ Synchronously changes the file owner based on the file descriptor.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ------------ | | ---- | ------ | ---- | ------------ |
| fd | number | Yes | File descriptor of the target file.| | fd | number | Yes | File descriptor of the target file.|
| uid | number | Yes | New UID. | | uid | number | Yes | New UID. |
| gid | number | Yes | New GID. | | gid | number | Yes | New GID. |
**Example** **Example**
...@@ -2467,9 +2467,9 @@ Changes the file owner (owner of the symbolic link, not the file referred to by ...@@ -2467,9 +2467,9 @@ Changes the file owner (owner of the symbolic link, not the file referred to by
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.| | Promise&lt;void&gt; | Promise that returns no value.|
**Example** **Example**
...@@ -2550,14 +2550,14 @@ Listens for file or directory changes. This API uses an asynchronous callback to ...@@ -2550,14 +2550,14 @@ Listens for file or directory changes. This API uses an asynchronous callback to
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | --------------------------------- | ---- | ------------------------------------------------------------ | | -------- | --------------------------------- | ---- | ------------------------------------------------------------ |
| filePath | string | Yes | Application sandbox path of the file. | | filePath | string | Yes | Application sandbox path of the file. |
| events | number | Yes | -&nbsp;**1**: The file or directory is renamed.<br>-&nbsp;**2**: The file or directory is modified.<br>-&nbsp;**3**: The file or directory is modified and renamed.| | events | number | Yes | -**1**: The file or directory is renamed.<br>- **2**: The file or directory is modified.<br>- **3**: The file or directory is modified and renamed.|
| callback | AsyncCallback&lt;number&gt; | Yes | Called each time a change is detected. | | callback | AsyncCallback&lt;number&gt; | Yes | Called each time a change is detected. |
**Return value** **Return value**
| Type | Description | | Type | Description |
| -------------------- | ---------- | | -------------------- | ---------- |
| [Watcher](#watcher7) | Promise used to return the **Watcher** instance.| | [Watcher](#watcher7) | Promise used to return the **Watcher** instance.|
**Example** **Example**
...@@ -2595,7 +2595,7 @@ Provides detailed file information. Before calling a method of the **Stat** clas ...@@ -2595,7 +2595,7 @@ Provides detailed file information. Before calling a method of the **Stat** clas
| ------ | ------ | ---- | ---- | ---------------------------------------- | | ------ | ------ | ---- | ---- | ---------------------------------------- |
| dev | number | Yes | No | Major device number. | | dev | number | Yes | No | Major device number. |
| ino | number | Yes | No | File ID. Different files on the same device have different **ino**s. | | ino | number | Yes | No | File ID. Different files on the same device have different **ino**s. |
| mode | number | Yes | No | File type and permissions. The first four bits indicate the file type, and the last 12 bits indicate the permissions. The bit fields are described as follows:<br>-&nbsp;**0o170000**: mask used to obtain the file type.<br>-&nbsp;**0o140000**: The file is a socket.<br>-&nbsp;**0o120000**: The file is a symbolic link.<br>-&nbsp;**0o100000**: The file is a regular file.<br>-&nbsp;**0o060000**: The file is a block device.<br>-&nbsp;**0o040000**: The file is a directory.<br>-&nbsp;**0o020000**: The file is a character device.<br>- **0o010000**: The file is a named pipe (FIFO).<br>-&nbsp;**0o0700**: mask used to obtain the owner permissions.<br>-&nbsp;**0o0400**: The owner has the permission to read a regular file or a directory entry.<br>-&nbsp;**0o0200**: The owner has the permission to write a regular file or create and delete a directory entry.<br>-&nbsp;**0o0100**: The owner has the permission to execute a regular file or search for the specified path in a directory.<br>-&nbsp;**0o0070**: mask used to obtain the user group permissions.<br>-&nbsp;**0o0040**: The user group has the permission to read a regular file or a directory entry.<br>-&nbsp;**0o0020**: The user group has the permission to write a regular file or create and delete a directory entry.<br>-&nbsp;**0o0010**: The user group has the permission to execute a regular file or search for the specified path in a directory.<br>-&nbsp;**0o0007**: mask used to obtain the permissions of other users.<br>-&nbsp;**0o0004**: Other users have the permission to read a regular file or a directory entry.<br>-&nbsp;**0o0002**: Other users have the permission to write a regular file or create and delete a directory entry.<br>-&nbsp;**0o0001**: Other users have the permission to execute a regular file or search for the specified path in a directory.| | mode | number | Yes | No | File type and permissions. The first four bits indicate the file type, and the last 12 bits indicate the permissions. The bit fields are described as follows:<br>- **0o170000**: mask used to obtain the file type.<br>- **0o140000**: The file is a socket.<br>- **0o120000**: The file is a symbolic link.<br>- **0o100000**: The file is a regular file.<br>- **0o060000**: The file is a block device.<br>- **0o040000**: The file is a directory.<br>- **0o020000**: The file is a character device.<br>- **0o010000**: The file is a named pipe, that is, FIFO.<br>- **0o0700**: mask used to obtain owner permissions.<br>- **0o0400**: The owner has the read permission on a regular file or a directory entry.<br>- **0o0200**: The owner has the permission to write a regular file or create and delete a directory entry.<br>- **0o0100**: The owner has the permission to execute a regular file or has the permission to search for the specified path in a directory.<br>- **0o0070**: mask used to obtain user group permissions.<br>- **0o0040**: The user group has the read permission on a regular file or a directory entry.<br>- **0o0020**: The user group has the permission to write a regular file or has the permission to create and delete a directory entry.<br>- **0o0010**: The user group has the permission to execute a regular file or has the permission to search for the specified path in a directory.<br>- **0o0007**: mask used to obtain permissions of other users.<br>- **0o0004**: Other user groups have the read permission on a regular file or a directory entry.<br>- **0o0002**: Other user groups have the permission to write a regular file or have the permission to create and delete a directory entry.<br>- **0o0001**: Other users have the permission to execute a regular file or search for the specified path in a directory.|
| nlink | number | Yes | No | Number of hard links in the file. | | nlink | number | Yes | No | Number of hard links in the file. |
| uid | number | Yes | No | User ID, that is ID of the file owner. | | uid | number | Yes | No | User ID, that is ID of the file owner. |
| gid | number | Yes | No | Group ID, that is, ID of the user group of the file. | | gid | number | Yes | No | Group ID, that is, ID of the user group of the file. |
...@@ -2617,9 +2617,9 @@ Checks whether this file is a block special file. A block special file supports ...@@ -2617,9 +2617,9 @@ Checks whether this file is a block special file. A block special file supports
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------- | ---------------- | | ------- | ---------------- |
| boolean | Whether the file is a block special file.| | boolean | Whether the file is a block special file.|
**Example** **Example**
...@@ -2639,9 +2639,9 @@ Checks whether this file is a character special file. A character special file s ...@@ -2639,9 +2639,9 @@ Checks whether this file is a character special file. A character special file s
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------- | ----------------- | | ------- | ----------------- |
| boolean | Whether the file is a character special file.| | boolean | Whether the file is a character special file.|
**Example** **Example**
...@@ -2661,9 +2661,9 @@ Checks whether this file is a directory. ...@@ -2661,9 +2661,9 @@ Checks whether this file is a directory.
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------- | ------------- | | ------- | ------------- |
| boolean | Whether the file is a directory.| | boolean | Whether the file is a directory.|
**Example** **Example**
...@@ -2683,9 +2683,9 @@ Checks whether this file is a named pipe (or FIFO). Named pipes are used for int ...@@ -2683,9 +2683,9 @@ Checks whether this file is a named pipe (or FIFO). Named pipes are used for int
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------- | --------------------- | | ------- | --------------------- |
| boolean | Whether the file is an FIFO.| | boolean | Whether the file is an FIFO.|
**Example** **Example**
...@@ -2705,9 +2705,9 @@ Checks whether this file is a regular file. ...@@ -2705,9 +2705,9 @@ Checks whether this file is a regular file.
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------- | --------------- | | ------- | --------------- |
| boolean | Whether the file is a regular file.| | boolean | Whether the file is a regular file.|
**Example** **Example**
...@@ -2727,9 +2727,9 @@ Checks whether this file is a socket. ...@@ -2727,9 +2727,9 @@ Checks whether this file is a socket.
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------- | -------------- | | ------- | -------------- |
| boolean | Whether the file is a socket.| | boolean | Whether the file is a socket.|
**Example** **Example**
...@@ -2749,9 +2749,9 @@ Checks whether this file is a symbolic link. ...@@ -2749,9 +2749,9 @@ Checks whether this file is a symbolic link.
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------- | --------------- | | ------- | --------------- |
| boolean | Whether the file is a symbolic link.| | boolean | Whether the file is a symbolic link.|
**Example** **Example**
...@@ -2797,9 +2797,9 @@ Stops the **watcher** instance. This API uses an asynchronous callback to return ...@@ -2797,9 +2797,9 @@ Stops the **watcher** instance. This API uses an asynchronous callback to return
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ------------------------- | ---- | ---------------------- | | -------- | ------------------------- | ---- | ---------------------- |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when **watcher** is stopped asynchronously.| | callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when **watcher** is stopped asynchronously.|
**Example** **Example**
...@@ -2829,9 +2829,9 @@ Closes the stream. This API uses a promise to return the result. ...@@ -2829,9 +2829,9 @@ Closes the stream. This API uses a promise to return the result.
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ------------- | | ------------------- | ------------- |
| Promise&lt;void&gt; | Promise used to return the stream close result.| | Promise&lt;void&gt; | Promise used to return the stream close result.|
**Example** **Example**
...@@ -2856,9 +2856,9 @@ Closes the stream. This API uses an asynchronous callback to return the result. ...@@ -2856,9 +2856,9 @@ Closes the stream. This API uses an asynchronous callback to return the result.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ------------------------- | ---- | ------------- | | -------- | ------------------------- | ---- | ------------- |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the stream is closed asynchronously.| | callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the stream is closed asynchronously.|
**Example** **Example**
...@@ -2898,9 +2898,9 @@ Flushes the stream. This API uses a promise to return the result. ...@@ -2898,9 +2898,9 @@ Flushes the stream. This API uses a promise to return the result.
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ------------- | | ------------------- | ------------- |
| Promise&lt;void&gt; | Promise used to return the stream flushing result.| | Promise&lt;void&gt; | Promise used to return the stream flushing result.|
**Example** **Example**
...@@ -2925,9 +2925,9 @@ Flushes the stream. This API uses an asynchronous callback to return the result. ...@@ -2925,9 +2925,9 @@ Flushes the stream. This API uses an asynchronous callback to return the result.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ------------------------- | ---- | -------------- | | -------- | ------------------------- | ---- | -------------- |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the stream is asynchronously flushed.| | callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the stream is asynchronously flushed.|
**Example** **Example**
...@@ -2967,16 +2967,16 @@ Writes data into the stream. This API uses a promise to return the result. ...@@ -2967,16 +2967,16 @@ Writes data into the stream. This API uses a promise to return the result.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------- | ------------------------------- | ---- | ---------------------------------------- | | ------- | ------------------------------- | ---- | ---------------------------------------- |
| buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. | | buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. |
| options | Object | No | The options are as follows:<br>-&nbsp;**offset** (number): position of the data to write in reference to the start address of the data. The default value is **0**.<br>-&nbsp;**length** (number): length of the data to write. The default value is the buffer length minus the offset.<br>-&nbsp;**position** (number): start position to write the data in the file. By default, data is written from the current position.<br>-&nbsp;**encoding** (string): format of the string to be encoded. The default value is **utf-8**, which is the only value supported.<br>Constraints: offset + length <= Buffer size | | options | Object | No | The options are as follows:<br>- **offset** (number): position of the data to write in reference to the start address of the data. The default value is **0**.<br>- **length** (number): length of the data to write. The default value is the buffer length minus the offset.<br>- **position** (number): start position to write the data in the file. By default, data is written from the current position.<br>- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **'utf-8'**, which is the only value supported.<br>Constraints: offset + length <= Buffer size |
**Return value** **Return value**
| Type | Description | | Type | Description |
| --------------------- | -------- | | --------------------- | -------- |
| Promise&lt;number&gt; | Promise used to return the length of the data written.| | Promise&lt;number&gt; | Promise used to return the length of the data written.|
**Example** **Example**
...@@ -3001,11 +3001,11 @@ Writes data into the stream. This API uses an asynchronous callback to return th ...@@ -3001,11 +3001,11 @@ Writes data into the stream. This API uses an asynchronous callback to return th
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------------- | ---- | ------------------------------------------------------------ | | -------- | ------------------------------- | ---- | ------------------------------------------------------------ |
| buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. | | buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. |
| options | Object | No | The options are as follows:<br>-&nbsp;**offset** (number): position of the data to write in reference to the start address of the data. The default value is **0**.<br>-&nbsp;**length** (number): length of the data to write. The default value is the buffer length minus the offset.<br>-&nbsp;**position** (number): start position to write the data in the file. By default, data is written from the current position.<br>-&nbsp;**encoding** (string): format of the string to be encoded. The default value is **utf-8**, which is the only value supported.<br>Constraints: offset + length <= Buffer size| | options | Object | No | The options are as follows:<br>- **offset** (number): position of the data to write in reference to the start address of the data. The default value is **0**.<br>- **length** (number): length of the data to write. The default value is the buffer length minus the offset.<br>- **position** (number): start position to write the data in the file. By default, data is written from the current position.<br>- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **'utf-8'**, which is the only value supported.<br>Constraints: offset + length <= Buffer size|
| callback | AsyncCallback&lt;number&gt; | Yes | Callback invoked when the data is written asynchronously. | | callback | AsyncCallback&lt;number&gt; | Yes | Callback invoked when the data is written asynchronously. |
**Example** **Example**
...@@ -3031,16 +3031,16 @@ Synchronously writes data into the stream. ...@@ -3031,16 +3031,16 @@ Synchronously writes data into the stream.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------- | ------------------------------- | ---- | ---------------------------------------- | | ------- | ------------------------------- | ---- | ---------------------------------------- |
| buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. | | buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. |
| options | Object | No | The options are as follows:<br>-&nbsp;**offset** (number): position of the data to write in reference to the start address of the data. The default value is **0**.<br>-&nbsp;**length** (number): length of the data to write. The default value is the buffer length minus the offset.<br>-&nbsp;**position** (number): start position to write the data in the file. By default, data is written from the current position.<br>-&nbsp;**encoding** (string): format of the string to be encoded. The default value is **utf-8**, which is the only value supported.<br>Constraints: offset + length <= Buffer size | | options | Object | No | The options are as follows:<br>- **offset** (number): position of the data to write in reference to the start address of the data. The default value is **0**.<br>- **length** (number): length of the data to write. The default value is the buffer length minus the offset.<br>- **position** (number): start position to write the data in the file. By default, data is written from the current position.<br>- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **'utf-8'**, which is the only value supported.<br>Constraints: offset + length <= Buffer size |
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------ | -------- | | ------ | -------- |
| number | Length of the data written in the file.| | number | Length of the data written in the file.|
**Example** **Example**
...@@ -3061,16 +3061,16 @@ Reads data from the stream. This API uses a promise to return the result. ...@@ -3061,16 +3061,16 @@ Reads data from the stream. This API uses a promise to return the result.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------- | ----------- | ---- | ---------------------------------------- | | ------- | ----------- | ---- | ---------------------------------------- |
| buffer | ArrayBuffer | Yes | Buffer used to store the file read. | | buffer | ArrayBuffer | Yes | Buffer used to store the file read. |
| options | Object | No | The options are as follows:<br>-&nbsp;**offset** (number): position to store the data read in the buffer in reference to the start address of the buffer. The default value is **0**.<br>-&nbsp;**length** (number): length of the data to read. The default value is the buffer length minus the offset.<br>-&nbsp;**position** (number): position of the data to read in the file. By default, data is read from the current position.<br>Constraints: offset + length <= Buffer size | | options | Object | No | The options are as follows:<br>- **offset** (number): position to store the data read in the buffer in reference to the start address of the buffer. The default value is **0**.<br>- **length** (number): length of the data to read. The default value is the buffer length minus the offset.<br>- **position** (number): position of the data to read in the file. By default, data is read from the current position.<br>Constraints: offset + length <= Buffer size |
**Return value** **Return value**
| Type | Description | | Type | Description |
| ---------------------------------- | ------ | | ---------------------------------- | ------ |
| Promise&lt;[ReadOut](#readout)&gt; | Promise used to return the data read.| | Promise&lt;[ReadOut](#readout)&gt; | Promise used to return the data read.|
**Example** **Example**
...@@ -3096,11 +3096,11 @@ Reads data from the stream. This API uses an asynchronous callback to return the ...@@ -3096,11 +3096,11 @@ Reads data from the stream. This API uses an asynchronous callback to return the
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- | | -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| buffer | ArrayBuffer | Yes | Buffer used to store the file read. | | buffer | ArrayBuffer | Yes | Buffer used to store the file read. |
| options | Object | No | The options are as follows:<br>-&nbsp;**offset** (number): position to store the data read in the buffer in reference to the start address of the buffer. The default value is **0**.<br>-&nbsp;**length** (number): length of the data to read. The default value is the buffer length minus the offset.<br>-&nbsp;**position** (number): position of the data to read in the file. By default, data is read from the current position.<br>Constraints: offset + length <= Buffer size | | options | Object | No | The options are as follows:<br>- **offset** (number): position to store the data read in the buffer in reference to the start address of the buffer. The default value is **0**.<br>- **length** (number): length of the data to read. The default value is the buffer length minus the offset.<br>- **position** (number): position of the data to read in the file. By default, data is read from the current position.<br>Constraints: offset + length <= Buffer size |
| callback | AsyncCallback&lt;[ReadOut](#readout)&gt; | Yes | Callback invoked when data is read asynchronously from the stream. | | callback | AsyncCallback&lt;[ReadOut](#readout)&gt; | Yes | Callback invoked when data is read asynchronously from the stream. |
**Example** **Example**
...@@ -3126,16 +3126,16 @@ Synchronously reads data from the stream. ...@@ -3126,16 +3126,16 @@ Synchronously reads data from the stream.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------- | ----------- | ---- | ---------------------------------------- | | ------- | ----------- | ---- | ---------------------------------------- |
| buffer | ArrayBuffer | Yes | Buffer used to store the file read. | | buffer | ArrayBuffer | Yes | Buffer used to store the file read. |
| options | Object | No | The options are as follows:<br>-&nbsp;**offset** (number): position to store the data read in the buffer in reference to the start address of the buffer. The default value is **0**.<br>-&nbsp;**length** (number): length of the data to read. The default value is the buffer length minus the offset.<br>-&nbsp;**position** (number): position of the data to read in the file. By default, data is read from the current position.<br>Constraints: offset + length <= Buffer size | | options | Object | No | The options are as follows:<br>- **offset** (number): position to store the data read in the buffer in reference to the start address of the buffer. The default value is **0**.<br>- **length** (number): length of the data to read. The default value is the buffer length minus the offset.<br>- **position** (number): position of the data to read in the file. By default, data is read from the current position.<br>Constraints: offset + length <= Buffer size |
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------ | -------- | | ------ | -------- |
| number | Length of the data read.| | number | Length of the data read.|
**Example** **Example**
...@@ -3161,9 +3161,9 @@ Reads the next directory entry. This API uses a promise to return the result. ...@@ -3161,9 +3161,9 @@ Reads the next directory entry. This API uses a promise to return the result.
**Return value** **Return value**
| Type | Description | | Type | Description |
| -------------------------------- | ------------- | | -------------------------------- | ------------- |
| Promise&lt;[Dirent](#dirent)&gt; | Promise used to return the directory entry read.| | Promise&lt;[Dirent](#dirent)&gt; | Promise used to return the directory entry read.|
**Example** **Example**
...@@ -3186,9 +3186,9 @@ Reads the next directory entry. This API uses an asynchronous callback to return ...@@ -3186,9 +3186,9 @@ Reads the next directory entry. This API uses an asynchronous callback to return
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | -------------------------------------- | ---- | ---------------- | | -------- | -------------------------------------- | ---- | ---------------- |
| callback | AsyncCallback&lt;[Dirent](#dirent)&gt; | Yes | Callback invoked when the next directory entry is asynchronously read.| | callback | AsyncCallback&lt;[Dirent](#dirent)&gt; | Yes | Callback invoked when the next directory entry is asynchronously read.|
**Example** **Example**
...@@ -3212,9 +3212,9 @@ Synchronously reads the next directory entry. ...@@ -3212,9 +3212,9 @@ Synchronously reads the next directory entry.
**Return value** **Return value**
| Type | Description | | Type | Description |
| ----------------- | -------- | | ----------------- | -------- |
| [Dirent](#dirent) | Directory entry read.| | [Dirent](#dirent) | Directory entry read.|
**Example** **Example**
...@@ -3295,9 +3295,9 @@ Checks whether this directory entry is a block special file. A block special fil ...@@ -3295,9 +3295,9 @@ Checks whether this directory entry is a block special file. A block special fil
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------- | ---------------- | | ------- | ---------------- |
| boolean | Whether the directory entry is a block special file.| | boolean | Whether the directory entry is a block special file.|
**Example** **Example**
...@@ -3317,9 +3317,9 @@ Checks whether a directory entry is a character special file. A character specia ...@@ -3317,9 +3317,9 @@ Checks whether a directory entry is a character special file. A character specia
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------- | ----------------- | | ------- | ----------------- |
| boolean | Whether the directory entry is a character special file.| | boolean | Whether the directory entry is a character special file.|
**Example** **Example**
...@@ -3339,9 +3339,9 @@ Checks whether a directory entry is a directory. ...@@ -3339,9 +3339,9 @@ Checks whether a directory entry is a directory.
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------- | ------------- | | ------- | ------------- |
| boolean | Whether the directory entry is a directory.| | boolean | Whether the directory entry is a directory.|
**Example** **Example**
...@@ -3361,9 +3361,9 @@ Checks whether this directory entry is a named pipe (or FIFO). Named pipes are u ...@@ -3361,9 +3361,9 @@ Checks whether this directory entry is a named pipe (or FIFO). Named pipes are u
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------- | --------------- | | ------- | --------------- |
| boolean | Whether the directory entry is a FIFO.| | boolean | Whether the directory entry is a FIFO.|
**Example** **Example**
...@@ -3383,9 +3383,9 @@ Checks whether a directory entry is a regular file. ...@@ -3383,9 +3383,9 @@ Checks whether a directory entry is a regular file.
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------- | --------------- | | ------- | --------------- |
| boolean | Whether the directory entry is a regular file.| | boolean | Whether the directory entry is a regular file.|
**Example** **Example**
...@@ -3405,9 +3405,9 @@ Checks whether a directory entry is a socket. ...@@ -3405,9 +3405,9 @@ Checks whether a directory entry is a socket.
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------- | -------------- | | ------- | -------------- |
| boolean | Whether the directory entry is a socket.| | boolean | Whether the directory entry is a socket.|
**Example** **Example**
...@@ -3427,9 +3427,9 @@ Checks whether a directory entry is a symbolic link. ...@@ -3427,9 +3427,9 @@ Checks whether a directory entry is a symbolic link.
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------- | --------------- | | ------- | --------------- |
| boolean | Whether the directory entry is a symbolic link.| | boolean | Whether the directory entry is a symbolic link.|
**Example** **Example**
......
...@@ -22,7 +22,6 @@ Scans for Bluetooth Low Energy (BLE) devices nearby. This operation consumes sys ...@@ -22,7 +22,6 @@ Scans for Bluetooth Low Energy (BLE) devices nearby. This operation consumes sys
**System capability**: SystemCapability.Communication.Bluetooth.Lite **System capability**: SystemCapability.Communication.Bluetooth.Lite
**Parameters** **Parameters**
**Table 1** StartBLEScanOptions **Table 1** StartBLEScanOptions
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
...@@ -57,7 +56,6 @@ Stops scanning for BLE devices nearby. This API is used with [bluetooth.startBLE ...@@ -57,7 +56,6 @@ Stops scanning for BLE devices nearby. This API is used with [bluetooth.startBLE
**System capability**: SystemCapability.Communication.Bluetooth.Lite **System capability**: SystemCapability.Communication.Bluetooth.Lite
**Parameters** **Parameters**
**Table 2** StopBLEScanOptions **Table 2** StopBLEScanOptions
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
......
...@@ -57,10 +57,11 @@ ...@@ -57,10 +57,11 @@
- [Network Sharing Error Codes](errorcode-net-sharing.md) - [Network Sharing Error Codes](errorcode-net-sharing.md)
- [Policy Management Error Codes](errorcode-net-policy.md) - [Policy Management Error Codes](errorcode-net-policy.md)
- Connectivity - Connectivity
- [Wi-Fi Error Codes](errorcode-wifi.md) - [Bluetooth Error Codes](errorcode-bluetoothManager.md)
- [Wi-Fi Error Codes](errorcode-wifi.md)
- [NFC Error Codes](errorcode-nfc.md) - [NFC Error Codes](errorcode-nfc.md)
- [RPC Error Codes](errorcode-rpc.md) - [RPC Error Codes](errorcode-rpc.md)
- Basic Features - Basic Features
- [Accessibility Error Codes](errorcode-accessibility.md) - [Accessibility Error Codes](errorcode-accessibility.md)
- [FaultLogger Error Codes](errorcode-faultlogger.md) - [FaultLogger Error Codes](errorcode-faultlogger.md)
- [Application Event Logging Error Codes](errorcode-hiappevent.md) - [Application Event Logging Error Codes](errorcode-hiappevent.md)
......
# Bluetooth Error Codes
> **NOTE**
>
> This topic describes only module-specific error codes. For details about universal error codes, see [Universal Error Codes](errorcode-universal.md).
## 2900001
**Error Message**
Service stopped.
**Description**
The Bluetooth service is stopped, and the APIs related to the Bluetooth service cannot be called.
**Possible Causes**
The Bluetooth service fails to start.
**Solution**
Start the Bluetooth service.
## 2900003
**Error Message**
Bluetooth switch is off.
**Description**
Bluetooth is disabled.
**Possible Causes**
Bluetooth is disabled.
**Solution**
Enable Bluetooth.
## 2900004
**Error Message**
Profile is not supported.
**Description**
The profile is not supported.
**Possible Causes**
The profile is not supported by the device.
**Solution**
Check whether the device supports the profile. Use a profile supported by the device.
## 2900099
**Error Message**
Operation failed.
**Description**
The operation failed.
**Possible Causes**
The profile is not supported by the device.
**Solution**
Perform this operation again.
## 2901000
**Error Message**
Read forbidden.
**Description**
The read operation is not allowed.
**Possible Causes**
The caller does not have the read permission.
**Solution**
Check whether the caller has the read permission.
## 2901001
**Error Message**
Write forbidden.
**Description**
The write operation is not allowed.
**Possible Causes**
The caller does not have the write permission.
**Solution**
Check whether the caller has the write permission.
## 2901054
**Error Message**
IO error.
**Description**
The I/O operation failed.
**Possible Causes**
The I/O transmission is abnormal.
**Solution**
Perform this operation again.
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册