提交 b75f3201 编写于 作者: A Annie_wang

update docs

Signed-off-by: NAnnie_wang <annie.wangli@huawei.com>
上级 7d18c4c3
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
> **NOTE**<br> > **NOTE**<br>
> 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.
Provides classic Bluetooth capabilities and Bluetooth Low Energy (BLE) scan and advertising. The Bluetooth module provides classic Bluetooth capabilities and Bluetooth Low Energy (BLE) scan and advertising.
## Modules to Import ## Modules to Import
...@@ -222,12 +222,12 @@ cancelPairedDevice(deviceId: string): boolean ...@@ -222,12 +222,12 @@ cancelPairedDevice(deviceId: string): boolean
Cancels a paired remote device. Cancels a paired remote device.
This is a system API.
**Required permissions**: ohos.permission.DISCOVER_BLUETOOTH **Required permissions**: ohos.permission.DISCOVER_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
...@@ -388,7 +388,7 @@ startBluetoothDiscovery(): boolean ...@@ -388,7 +388,7 @@ startBluetoothDiscovery(): boolean
Starts Bluetooth scan to discover remote devices. Starts Bluetooth scan to discover remote devices.
**Required permissions**: ohos.permission.USE_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
...@@ -447,7 +447,7 @@ Sets the device pairing confirmation. ...@@ -447,7 +447,7 @@ Sets the device pairing confirmation.
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------ | ------- | ---- | -------------------------------- | | ------ | ------- | ---- | -------------------------------- |
| device | string | Yes | Address of the target remote device, for example, XX:XX:XX:XX:XX:XX.| | 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. | | 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. |
**Return value** **Return value**
...@@ -1422,7 +1422,7 @@ a2dpSrc.on('connectionStateChange', onReceiveEvent); ...@@ -1422,7 +1422,7 @@ a2dpSrc.on('connectionStateChange', onReceiveEvent);
### off('connectionStateChange')<sup>8+</sup> ### off('connectionStateChange')<sup>8+</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.
...@@ -1451,12 +1451,14 @@ a2dpSrc.off('connectionStateChange', onReceiveEvent); ...@@ -1451,12 +1451,14 @@ a2dpSrc.off('connectionStateChange', onReceiveEvent);
``` ```
### getPlayingState ### getPlayingState<sup>9+</sup>
getPlayingState(device: string): PlayingState getPlayingState(device: string): PlayingState
Obtains the playing state of a device. Obtains the playing state of a device.
**Required permissions**: ohos.permission.USE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters** **Parameters**
...@@ -1576,7 +1578,7 @@ hfpAg.on('connectionStateChange', onReceiveEvent); ...@@ -1576,7 +1578,7 @@ hfpAg.on('connectionStateChange', onReceiveEvent);
### off('connectionStateChange')<sup>8+</sup> ### off('connectionStateChange')<sup>8+</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.
...@@ -1616,12 +1618,12 @@ connect(device: string): boolean ...@@ -1616,12 +1618,12 @@ connect(device: string): boolean
Connects to the HidHost service of a device. Connects to the HidHost service of a device.
This is a system API.
**Required permissions**: ohos.permission.DISCOVER_BLUETOOTH **Required permissions**: ohos.permission.DISCOVER_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
...@@ -1648,12 +1650,12 @@ disconnect(device: string): boolean ...@@ -1648,12 +1650,12 @@ disconnect(device: string): boolean
Disconnects from the HidHost service of a device. Disconnects from the HidHost service of a device.
This is a system API.
**Required permissions**: ohos.permission.DISCOVER_BLUETOOTH **Required permissions**: ohos.permission.DISCOVER_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
...@@ -1706,7 +1708,7 @@ hidHost.on('connectionStateChange', onReceiveEvent); ...@@ -1706,7 +1708,7 @@ hidHost.on('connectionStateChange', onReceiveEvent);
### off('connectionStateChange')<sup>9+</sup> ### off('connectionStateChange')<sup>9+</sup>
off(type: "connectionStateChange", callback: Callback&lt;[StateChangeParam](#StateChangeParam)&gt;): void off(type: "connectionStateChange", callback?: Callback&lt;[StateChangeParam](#StateChangeParam)&gt;): void
Unsubscribes from the HidHost connection state change events. Unsubscribes from the HidHost connection state change events.
...@@ -1964,6 +1966,15 @@ Notifies the connected client device when a characteristic value changes. ...@@ -1964,6 +1966,15 @@ Notifies the connected client device when a characteristic value changes.
**Example** **Example**
```js ```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: '00001830-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer};
descriptors[0] = descriptor;
let arrayBufferC = new ArrayBuffer(8); let arrayBufferC = new ArrayBuffer(8);
let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', characteristicValue: arrayBufferC, descriptors:descriptors}; characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', characteristicValue: arrayBufferC, descriptors:descriptors};
...@@ -2541,14 +2552,9 @@ Obtains all services of the remote BLE device. This API uses a promise to return ...@@ -2541,14 +2552,9 @@ Obtains all services of the remote BLE device. This API uses a promise to return
```js ```js
// Promise // Promise
let device = bluetooth.BLE.createGattClientDevice('XX:XX:XX:XX:XX:XX'); gattClientDevice.getServices().then(result => {
device.connect(); console.info("Got services successfully:" + JSON.stringify(result));
var services = device.getServices(); });
console.log("bluetooth services size is ", services.length);
for (let i = 0; i < services.length; i++) {
console.log('bluetooth serviceUuid is ' + services[i].serviceUuid);
}
``` ```
...@@ -2881,6 +2887,15 @@ Sets the function of notifying the GATT client when the characteristic value of ...@@ -2881,6 +2887,15 @@ Sets the function of notifying the GATT client when the characteristic value of
**Example** **Example**
```js ```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: '00001830-0000-1000-8000-00805F9B34FB', descriptorValue: arrayBuffer};
descriptors[0] = descriptor;
let arrayBufferC = new ArrayBuffer(8); let arrayBufferC = new ArrayBuffer(8);
let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', let characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', characteristicValue: arrayBufferC, descriptors:descriptors}; characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', characteristicValue: arrayBufferC, descriptors:descriptors};
......
...@@ -37,6 +37,7 @@ Scans for Bluetooth Low Energy (BLE) devices nearby. This operation consumes sys ...@@ -37,6 +37,7 @@ Scans for Bluetooth Low Energy (BLE) devices nearby. This operation consumes sys
``` ```
bluetooth.startBLEScan({ bluetooth.startBLEScan({
interval:0,
success() { success() {
console.log('call bluetooth.startBLEScan success.'); console.log('call bluetooth.startBLEScan success.');
}, },
...@@ -71,7 +72,6 @@ Stops scanning for BLE devices nearby. This API is used with [bluetooth.startBLE ...@@ -71,7 +72,6 @@ Stops scanning for BLE devices nearby. This API is used with [bluetooth.startBLE
``` ```
bluetooth.stopBLEScan({ bluetooth.stopBLEScan({
interval:0,
success() { success() {
console.log('call bluetooth.stopBLEScan success.'); console.log('call bluetooth.stopBLEScan success.');
}, },
...@@ -120,19 +120,12 @@ Subscribes to the newly detected BLE device. If this API is called multiple time ...@@ -120,19 +120,12 @@ Subscribes to the newly detected BLE device. If this API is called multiple time
**Example** **Example**
``` ```
bluetooth.startBLEScan({ bluetooth.subscribeBLEFound({
success() { success(data) {
bluetooth.subscribeBLEFound({ console.log('Called bluetooth.subscribeBLEFound successsully, data: ${data}.');
success(data) {
const [device] = data.devices;
if (!!device) {
bluetooth.stopBLEScan();
}
}
});
}, },
fail(code, data) { fail(data, code) {
console.log('Failed to start BLE device scan, code: ${code}, data: ${data}'); console.log('Failed to call bluetooth.startBLEScan, data: ${data}, code: ${code}.');
} }
}); });
``` ```
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册