diff --git a/en/application-dev/reference/apis/js-apis-bluetooth.md b/en/application-dev/reference/apis/js-apis-bluetooth.md index 1e280124850de1ccfa9658365d97c3219b1d5b2b..42be84f040bf62367601a1a39c640255b6f16b87 100644 --- a/en/application-dev/reference/apis/js-apis-bluetooth.md +++ b/en/application-dev/reference/apis/js-apis-bluetooth.md @@ -3,7 +3,7 @@ > **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. -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 @@ -222,12 +222,12 @@ cancelPairedDevice(deviceId: string): boolean Cancels a paired remote device. +This is a system API. + **Required permissions**: ohos.permission.DISCOVER_BLUETOOTH **System capability**: SystemCapability.Communication.Bluetooth.Core -**System API**: This is a system API and cannot be called by third-party applications. - **Parameters** | Name | Type | Mandatory | Description | @@ -388,7 +388,7 @@ startBluetoothDiscovery(): boolean 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 @@ -447,7 +447,7 @@ Sets the device pairing confirmation. | 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. | **Return value** @@ -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 Unsubscribes from the A2DP connection state change events. @@ -1451,12 +1451,14 @@ a2dpSrc.off('connectionStateChange', onReceiveEvent); ``` -### getPlayingState +### getPlayingState9+ getPlayingState(device: string): PlayingState Obtains the playing state of a device. +**Required permissions**: ohos.permission.USE_BLUETOOTH + **System capability**: SystemCapability.Communication.Bluetooth.Core **Parameters** @@ -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 Unsubscribes from the HFP connection state change events. @@ -1616,12 +1618,12 @@ connect(device: string): boolean Connects to the HidHost service of a device. +This is a system API. + **Required permissions**: ohos.permission.DISCOVER_BLUETOOTH **System capability**: SystemCapability.Communication.Bluetooth.Core -**System API**: This is a system API and cannot be called by third-party applications. - **Parameters** | Name | Type | Mandatory | Description | @@ -1648,12 +1650,12 @@ disconnect(device: string): boolean Disconnects from the HidHost service of a device. +This is a system API. + **Required permissions**: ohos.permission.DISCOVER_BLUETOOTH **System capability**: SystemCapability.Communication.Bluetooth.Core -**System API**: This is a system API and cannot be called by third-party applications. - **Parameters** | Name | Type | Mandatory | Description | @@ -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 Unsubscribes from the HidHost connection state change events. @@ -1964,6 +1966,15 @@ Notifies the connected client device when a characteristic value changes. **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: '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}; @@ -2541,14 +2552,9 @@ Obtains all services of the remote BLE device. This API uses a promise to return ```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("Got services successfully:" + JSON.stringify(result)); +}); ``` @@ -2881,6 +2887,15 @@ Sets the function of notifying the GATT client when the characteristic value of **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: '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/en/application-dev/reference/apis/js-apis-system-bluetooth.md b/en/application-dev/reference/apis/js-apis-system-bluetooth.md index 9f2ef61d8465f220a97884f3097c43b203e07b80..a8c77cd86a20c0401d01ce1e54a61c58c7aace17 100644 --- a/en/application-dev/reference/apis/js-apis-system-bluetooth.md +++ b/en/application-dev/reference/apis/js-apis-system-bluetooth.md @@ -37,6 +37,7 @@ Scans for Bluetooth Low Energy (BLE) devices nearby. This operation consumes sys ``` bluetooth.startBLEScan({ + interval:0, success() { console.log('call bluetooth.startBLEScan success.'); }, @@ -71,7 +72,6 @@ Stops scanning for BLE devices nearby. This API is used with [bluetooth.startBLE ``` bluetooth.stopBLEScan({ - interval:0, 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 **Example** ``` - bluetooth.startBLEScan({ - success() { - bluetooth.subscribeBLEFound({ - success(data) { - const [device] = data.devices; - if (!!device) { - bluetooth.stopBLEScan(); - } - } - }); + bluetooth.subscribeBLEFound({ + success(data) { + console.log('Called bluetooth.subscribeBLEFound successsully, data: ${data}.'); }, - fail(code, data) { - console.log('Failed to start BLE device scan, code: ${code}, data: ${data}'); + fail(data, code) { + console.log('Failed to call bluetooth.startBLEScan, data: ${data}, code: ${code}.'); } }); ```