From 96d5cf74558fa0847a2cb7e9fa32c831b8fedc09 Mon Sep 17 00:00:00 2001 From: lverpeng Date: Wed, 29 Jun 2022 20:38:28 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A4=BA=E4=BE=8B=E4=BB=A3=E7=A0=81=EF=BC=8C?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E5=AE=8C=E6=95=B4=E6=80=A7=E6=B5=8B=E8=AF=95?= =?UTF-8?q?docs=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: lverpeng --- .../reference/apis/js-apis-bluetooth.md | 55 ++++++++++++------- .../apis/js-apis-system-bluetooth.md | 19 ++----- 2 files changed, 41 insertions(+), 33 deletions(-) diff --git a/zh-cn/application-dev/reference/apis/js-apis-bluetooth.md b/zh-cn/application-dev/reference/apis/js-apis-bluetooth.md index 424a51db8e..c07d60d16a 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-bluetooth.md +++ b/zh-cn/application-dev/reference/apis/js-apis-bluetooth.md @@ -222,12 +222,12 @@ cancelPairedDevice(deviceId: string): boolean 删除配对的远程设备。 +此接口为系统接口。 + **需要权限**:ohos.permission.DISCOVER_BLUETOOTH **系统能力**:SystemCapability.Communication.Bluetooth.Core。 -**系统API**:该接口为系统接口,三方应用不支持调用。 - **参数:** | 参数名 | 类型 | 必填 | 说明 | @@ -388,7 +388,7 @@ startBluetoothDiscovery(): boolean 开启蓝牙扫描,可以发现远端设备。 -**需要权限**:ohos.permission.USE_BLUETOOTH;ohos.permission.LOCATION +**需要权限**:ohos.permission.DISCOVER_BLUETOOTH;ohos.permission.LOCATION **系统能力**:SystemCapability.Communication.Bluetooth.Core。 @@ -1143,7 +1143,7 @@ startBLEScan(filters: Array<ScanFilter>, 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。 @@ -1422,7 +1422,7 @@ a2dpSrc.on('connectionStateChange', onReceiveEvent); ### off('connectionStateChange')8+ -off(type: "connectionStateChange", callback: Callback<[StateChangeParam](#StateChangeParam)>): void +off(type: "connectionStateChange", callback?: Callback<[StateChangeParam](#StateChangeParam)>): void 取消订阅a2dp连接状态变化事件。 @@ -1451,12 +1451,14 @@ a2dpSrc.off('connectionStateChange', onReceiveEvent); ``` -### getPlayingState +### getPlayingState9+ getPlayingState(device: string): PlayingState 获取设备的播放状态。 +**需要权限**:ohos.permission.USE_BLUETOOTH + **系统能力**:SystemCapability.Communication.Bluetooth.Core。 **参数:** @@ -1576,7 +1578,7 @@ hfpAg.on('connectionStateChange', onReceiveEvent); ### off('connectionStateChange')8+ -off(type: "connectionStateChange", callback: Callback<[StateChangeParam](#StateChangeParam)>): void +off(type: "connectionStateChange", callback?: Callback<[StateChangeParam](#StateChangeParam)>): void 取消订阅HFP连接状态变化事件。 @@ -1616,12 +1618,12 @@ connect(device: string): boolean 连接设备的HidHost服务。 +此接口为系统接口。 + **需要权限**:ohos.permission.DISCOVER_BLUETOOTH **系统能力**:SystemCapability.Communication.Bluetooth.Core。 -**系统API**:该接口为系统接口,三方应用不支持调用。 - **参数:** | 参数名 | 类型 | 必填 | 说明 | @@ -1648,12 +1650,12 @@ disconnect(device: string): boolean 断开连接设备的HidHost服务。 +此接口为系统接口。 + **需要权限**:ohos.permission.DISCOVER_BLUETOOTH **系统能力**:SystemCapability.Communication.Bluetooth.Core。 -**系统API**:该接口为系统接口,三方应用不支持调用。 - **参数:** | 参数名 | 类型 | 必填 | 说明 | @@ -1706,7 +1708,7 @@ hidHost.on('connectionStateChange', onReceiveEvent); ### off('connectionStateChange')9+ -off(type: "connectionStateChange", callback: Callback<[StateChangeParam](#StateChangeParam)>): void +off(type: "connectionStateChange", callback?: Callback<[StateChangeParam](#StateChangeParam)>): void 取消订阅HidHost连接状态变化事件。 @@ -1964,6 +1966,15 @@ 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}; @@ -2542,14 +2553,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)); +}); ``` @@ -2882,6 +2888,15 @@ 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}; diff --git a/zh-cn/application-dev/reference/apis/js-apis-system-bluetooth.md b/zh-cn/application-dev/reference/apis/js-apis-system-bluetooth.md index 1ea5c7c26a..0c8c37bc56 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-system-bluetooth.md +++ b/zh-cn/application-dev/reference/apis/js-apis-system-bluetooth.md @@ -37,6 +37,7 @@ import bluetooth from '@system.bluetooth'; ``` bluetooth.startBLEScan({ + interval:0, success() { console.log('call bluetooth.startBLEScan success.'); }, @@ -71,7 +72,6 @@ import bluetooth from '@system.bluetooth'; ``` bluetooth.stopBLEScan({ - interval:0, success() { console.log('call bluetooth.stopBLEScan success.'); }, @@ -120,19 +120,12 @@ import bluetooth from '@system.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}.'); } }); ``` -- GitLab