提交 f23fa0a8 编写于 作者: L lverpeng

示例代码,接口完整性测试docs修改

Signed-off-by: Nlverpeng <lverpeng118@163.com>
上级 a4b4c216
......@@ -233,6 +233,8 @@ cancelPairedDevice(deviceId: string): boolean
删除配对的远程设备。
此接口为系统接口。
**需要权限**:ohos.permission.DISCOVER_BLUETOOTH
**系统能力**:SystemCapability.Communication.Bluetooth.Core。
......@@ -397,7 +399,7 @@ startBluetoothDiscovery(): boolean
开启蓝牙扫描,可以发现远端设备。
**需要权限**:ohos.permission.USE_BLUETOOTH;ohos.permission.LOCATION
**需要权限**:ohos.permission.DISCOVER_BLUETOOTH;ohos.permission.LOCATION
**系统能力**:SystemCapability.Communication.Bluetooth.Core。
......@@ -1125,7 +1127,7 @@ startBLEScan(filters: Array&lt;ScanFilter&gt;, options?: ScanOptions): void
发起BLE扫描流程。
**需要权限**:ohos.permission.DISCOVER_BLUETOOTH;ohos.permission.MANAGE_BLUETOOTH; ohos.permission.LOCATION
**需要权限**:ohos.permission.DISCOVER_BLUETOOTH;ohos.permission.MANAGE_BLUETOOTH;ohos.permission.LOCATION
**系统能力**:SystemCapability.Communication.Bluetooth.Core。
......@@ -1396,7 +1398,7 @@ A2dpSourceProfile.on('connectionStateChange', onReceiveEvent);
### A2dpSourceProfile.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
取消订阅a2dp连接状态变化事件。
......@@ -1423,12 +1425,14 @@ A2dpSourceProfile.off('connectionStateChange', onReceiveEvent);
```
### getPlayingState
### getPlayingState<sup>9+</sup>
getPlayingState(device: string): PlayingState
获取设备的播放状态。
**需要权限**:ohos.permission.USE_BLUETOOTH
**系统能力**:SystemCapability.Communication.Bluetooth.Core。
**参数:**
......@@ -1551,7 +1555,7 @@ HandsFreeAudioGatewayProfile.on('connectionStateChange', onReceiveEvent);
### HandsFreeAudioGatewayProfile.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
取消订阅HFP连接状态变化事件。
......@@ -1807,6 +1811,16 @@ server端特征值发生变化时,主动通知已连接的client设备。
**示例:**
```js
// 创建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 characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', characteristicValue: arrayBufferC, descriptors:descriptors};
......@@ -2385,14 +2399,9 @@ client端获取蓝牙低功耗设备的所有服务,即服务发现。
```js
// Promise 模式
let device = bluetooth.BLE.createGattClientDevice('XX:XX:XX:XX:XX:XX');
device.connect();
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);
}
gattClientDevice.getServices().then(result => {
console.info("getServices successfully:" + JSON.stringify(result));
});
```
......@@ -2725,6 +2734,16 @@ setNotifyCharacteristicChanged(characteristic: BLECharacteristic, enable: boolea
**示例:**
```js
// 创建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 characteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB',
characteristicUuid: '00001820-0000-1000-8000-00805F9B34FB', characteristicValue: arrayBufferC, descriptors:descriptors};
......
......@@ -130,19 +130,12 @@ ohos.permission.MANAGE_BLUETOOTH
**示例:**
```
bluetooth.startBLEScan({
success() {
bluetooth.subscribeBLEFound({
success(data) {
const [device] = data.devices;
if (!!device) {
bluetooth.stopBLEScan();
}
}
});
bluetooth.subscribeBLEFound({
success(data) {
console.log('call bluetooth.subscribeBLEFound success, data: ${data}.');
},
fail(code, data) {
console.log('Failed to start BLE device scan, code: ${code}, data: ${data}');
fail(data, code) {
console.log('call bluetooth.startBLEScan failed, data: ${data}, code: ${code}.');
}
});
```
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册