未验证 提交 eb4748b6 编写于 作者: O openharmony_ci 提交者: Gitee

!11119 [翻译完成】#I5TR61

Merge pull request !11119 from Annie_wang/PR10098
# Bluetooth # Bluetooth
The Bluetooth module 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.
> **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.
...@@ -223,7 +223,7 @@ cancelPairedDevice(deviceId: string): boolean ...@@ -223,7 +223,7 @@ cancelPairedDevice(deviceId: string): boolean
Cancels a paired remote device. Cancels a paired remote device.
This is a system API. **System API**: This is a system API.
**Required permissions**: ohos.permission.DISCOVER_BLUETOOTH **Required permissions**: ohos.permission.DISCOVER_BLUETOOTH
...@@ -281,7 +281,7 @@ let remoteDeviceName = bluetooth.getRemoteDeviceName("XX:XX:XX:XX:XX:XX"); ...@@ -281,7 +281,7 @@ let remoteDeviceName = bluetooth.getRemoteDeviceName("XX:XX:XX:XX:XX:XX");
getRemoteDeviceClass(deviceId: string): DeviceClass getRemoteDeviceClass(deviceId: string): DeviceClass
Obtains the type of the remote Bluetooth device. Obtains the class of the remote Bluetooth device.
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
...@@ -297,7 +297,7 @@ Obtains the type of the remote Bluetooth device. ...@@ -297,7 +297,7 @@ Obtains the type of the remote Bluetooth device.
| Type | Description | | Type | Description |
| --------------------------- | -------- | | --------------------------- | -------- |
| [DeviceClass](#deviceclass) | Type of a remote device obtained.| | [DeviceClass](#deviceclass) | Class of the remote device obtained.|
**Example** **Example**
...@@ -515,7 +515,7 @@ Unsubscribes from the Bluetooth device discovery events. ...@@ -515,7 +515,7 @@ Unsubscribes from the Bluetooth device discovery events.
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ----------------------------------- | ---- | ---------------------------------------- | | -------- | ----------------------------------- | ---- | ---------------------------------------- |
| type | string | Yes | Event type. The value **bluetoothDeviceFind** indicates an event reported when a Bluetooth device is discovered. | | 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 used to report the discovered devices. If this parameter is not set, this method unsubscribes from all callbacks corresponding to **type**.| | 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**.|
**Return value** **Return value**
...@@ -578,7 +578,7 @@ Unsubscribes from the pairing request events of the remote Bluetooth device. ...@@ -578,7 +578,7 @@ Unsubscribes from the pairing request events of the remote Bluetooth device.
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- | | -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type | string | Yes | Event type. The value **pinRequired** indicates a pairing request event. | | type | string | Yes | Event type. The value **pinRequired** indicates a pairing request event. |
| callback | Callback&lt;[PinRequiredParam](#pinrequiredparam)&gt; | No | Callback used to report the Bluetooth pairing request. The input parameter is the pairing request parameter. If this parameter is not set, this method unsubscribes from all callbacks corresponding to **type**.| | 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**.|
**Return value** **Return value**
...@@ -599,7 +599,7 @@ bluetooth.off('pinRequired', onReceiveEvent); ...@@ -599,7 +599,7 @@ bluetooth.off('pinRequired', onReceiveEvent);
on(type: "bondStateChange", callback: Callback&lt;BondStateParam&gt;): void on(type: "bondStateChange", callback: Callback&lt;BondStateParam&gt;): void
Subscribes to the Bluetooth bond state change events. Subscribes to the Bluetooth pairing state change events.
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
...@@ -609,8 +609,8 @@ Subscribes to the Bluetooth bond state change events. ...@@ -609,8 +609,8 @@ Subscribes to the Bluetooth bond state change events.
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ------------------------------------ | | -------- | ---------------------------------------- | ---- | ------------------------------------ |
| type | string | Yes | Event type. The value **bondStateChange** indicates a Bluetooth bond state change event.| | 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 bond state. You need to implement this callback. | | callback | Callback&lt;[BondStateParam](#BondStateParam)&gt; | Yes | Callback invoked to return the pairing state. You need to implement this callback. |
**Return value** **Return value**
...@@ -619,7 +619,7 @@ No value is returned. ...@@ -619,7 +619,7 @@ No value is returned.
**Example** **Example**
```js ```js
function onReceiveEvent(data) { // data, as the input parameter of the callback, indicates the bond state. function onReceiveEvent(data) { // data, as the input parameter of the callback, indicates the pairing state.
console.info('pair state = '+ JSON.stringify(data)); console.info('pair state = '+ JSON.stringify(data));
} }
bluetooth.on('bondStateChange', onReceiveEvent); bluetooth.on('bondStateChange', onReceiveEvent);
...@@ -630,7 +630,7 @@ bluetooth.on('bondStateChange', onReceiveEvent); ...@@ -630,7 +630,7 @@ bluetooth.on('bondStateChange', onReceiveEvent);
off(type: "bondStateChange", callback?: Callback&lt;BondStateParam&gt;): void off(type: "bondStateChange", callback?: Callback&lt;BondStateParam&gt;): void
Unsubscribes from the Bluetooth bond state change events. Unsubscribes from the Bluetooth pairing state change events.
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
...@@ -640,8 +640,8 @@ Unsubscribes from the Bluetooth bond state change events. ...@@ -640,8 +640,8 @@ Unsubscribes from the Bluetooth bond state change events.
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- | | -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type | string | Yes | Event type. The value **bondStateChange** indicates a Bluetooth bond state change event. | | type | string | Yes | Event type. The value **bondStateChange** indicates a Bluetooth pairing state change event. |
| callback | Callback&lt;[BondStateParam](#BondStateParam)&gt; | No | Callback used to report the change of the Bluetooth bond state. If this parameter is not set, this method unsubscribes from all callbacks corresponding to **type**.| | 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**.|
**Return value** **Return value**
...@@ -704,7 +704,7 @@ Unsubscribes from the Bluetooth connection state change events. ...@@ -704,7 +704,7 @@ Unsubscribes from the Bluetooth connection state change events.
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- | | -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type | string | Yes | Event type. The value **stateChange** indicates a Bluetooth connection state change event. | | type | string | Yes | Event type. The value **stateChange** indicates a Bluetooth connection state change event. |
| callback | Callback&lt;[BluetoothState](#bluetoothstate)&gt; | No | Callback used to report the Bluetooth connection state. If this parameter is not set, this method unsubscribes from all callbacks corresponding to **type**.| | 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**.|
**Return value** **Return value**
...@@ -990,7 +990,7 @@ Unsubscribes from the SPP read request events. ...@@ -990,7 +990,7 @@ Unsubscribes from the SPP read request events.
| ------------ | --------------------------- | ---- | ---------------------------------------- | | ------------ | --------------------------- | ---- | ---------------------------------------- |
| type | string | Yes | Event type. The value **sppRead** indicates an SPP read request event. | | 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**. | | clientSocket | number | Yes | Client socket ID, which is obtained by **sppAccept** or **sppConnect**. |
| callback | Callback&lt;ArrayBuffer&gt; | No | Callback used to report an SPP read request event. If this parameter is not set, this method unsubscribes from all callbacks corresponding to **type**.| | 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**.|
**Return value** **Return value**
...@@ -1248,7 +1248,7 @@ Unsubscribes from the BLE device discovery events. ...@@ -1248,7 +1248,7 @@ Unsubscribes from the BLE device discovery events.
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- | | -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type | string | Yes | Event type. The value **BLEDeviceFind** indicates an event reported when a BLE device is discovered. | | 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 used to report the discovered devices. If this parameter is not set, this method unsubscribes from all callbacks corresponding to **type**.| | 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**.|
**Return value** **Return value**
...@@ -1293,7 +1293,7 @@ No value is returned. ...@@ -1293,7 +1293,7 @@ No value is returned.
**Example** **Example**
```js ```js
let a2dpSrc = bluetooth.getProfile(bluetooth.ProfileId.PROFILE_A2DP_SOURCE) let a2dpSrc = bluetooth.getProfile(bluetooth.ProfileId.PROFILE_A2DP_SOURCE) as bluetooth.A2dpSourceProfile;
let retArray = a2dpSrc.getConnectionDevices(); let retArray = a2dpSrc.getConnectionDevices();
``` ```
...@@ -1322,7 +1322,7 @@ Obtains the connection state of the profile. ...@@ -1322,7 +1322,7 @@ Obtains the connection state of the profile.
**Example** **Example**
```js ```js
let a2dpSrc = bluetooth.getProfile(bluetooth.ProfileId.PROFILE_A2DP_SOURCE) let a2dpSrc = bluetooth.getProfile(bluetooth.ProfileId.PROFILE_A2DP_SOURCE) as bluetooth.A2dpSourceProfile;
let ret = a2dpSrc.getDeviceState('XX:XX:XX:XX:XX:XX'); let ret = a2dpSrc.getDeviceState('XX:XX:XX:XX:XX:XX');
``` ```
...@@ -1356,7 +1356,7 @@ Sets up an Advanced Audio Distribution Profile (A2DP) connection. ...@@ -1356,7 +1356,7 @@ Sets up an Advanced Audio Distribution Profile (A2DP) connection.
**Example** **Example**
```js ```js
let a2dpSrc = bluetooth.getProfile(bluetooth.ProfileId.PROFILE_A2DP_SOURCE) let a2dpSrc = bluetooth.getProfile(bluetooth.ProfileId.PROFILE_A2DP_SOURCE) as bluetooth.A2dpSourceProfile;
let ret = a2dpSrc.connect('XX:XX:XX:XX:XX:XX'); let ret = a2dpSrc.connect('XX:XX:XX:XX:XX:XX');
``` ```
...@@ -1386,7 +1386,7 @@ Disconnects an A2DP connection. ...@@ -1386,7 +1386,7 @@ Disconnects an A2DP connection.
**Example** **Example**
```js ```js
let a2dpSrc = bluetooth.getProfile(bluetooth.ProfileId.PROFILE_A2DP_SOURCE); let a2dpSrc = bluetooth.getProfile(bluetooth.ProfileId.PROFILE_A2DP_SOURCE) as bluetooth.A2dpSourceProfile;
let ret = a2dpSrc.disconnect('XX:XX:XX:XX:XX:XX'); let ret = a2dpSrc.disconnect('XX:XX:XX:XX:XX:XX');
``` ```
...@@ -1416,7 +1416,7 @@ No value is returned. ...@@ -1416,7 +1416,7 @@ No value is returned.
function onReceiveEvent(data) { function onReceiveEvent(data) {
console.info('a2dp state = '+ JSON.stringify(data)); console.info('a2dp state = '+ JSON.stringify(data));
} }
let a2dpSrc = bluetooth.getProfile(bluetooth.ProfileId.PROFILE_A2DP_SOURCE); let a2dpSrc = bluetooth.getProfile(bluetooth.ProfileId.PROFILE_A2DP_SOURCE) as bluetooth.A2dpSourceProfile;
a2dpSrc.on('connectionStateChange', onReceiveEvent); a2dpSrc.on('connectionStateChange', onReceiveEvent);
``` ```
...@@ -1446,7 +1446,7 @@ No value is returned. ...@@ -1446,7 +1446,7 @@ No value is returned.
function onReceiveEvent(data) { function onReceiveEvent(data) {
console.info('a2dp state = '+ JSON.stringify(data)); console.info('a2dp state = '+ JSON.stringify(data));
} }
let a2dpSrc = bluetooth.getProfile(bluetooth.ProfileId.PROFILE_A2DP_SOURCE); let a2dpSrc = bluetooth.getProfile(bluetooth.ProfileId.PROFILE_A2DP_SOURCE) as bluetooth.A2dpSourceProfile;
a2dpSrc.on('connectionStateChange', onReceiveEvent); a2dpSrc.on('connectionStateChange', onReceiveEvent);
a2dpSrc.off('connectionStateChange', onReceiveEvent); a2dpSrc.off('connectionStateChange', onReceiveEvent);
``` ```
...@@ -1475,7 +1475,7 @@ Obtains the playing state of a device. ...@@ -1475,7 +1475,7 @@ Obtains the playing state of a device.
**Example** **Example**
```js ```js
let a2dpSrc = bluetooth.getProfile(bluetooth.ProfileId.PROFILE_A2DP_SOURCE); let a2dpSrc = bluetooth.getProfile(bluetooth.ProfileId.PROFILE_A2DP_SOURCE) as bluetooth.A2dpSourceProfile;
let state = a2dpSrc.getPlayingState('XX:XX:XX:XX:XX:XX'); let state = a2dpSrc.getPlayingState('XX:XX:XX:XX:XX:XX');
``` ```
...@@ -1510,7 +1510,8 @@ Sets up a Hands-free Profile (HFP) connection of a device. ...@@ -1510,7 +1510,8 @@ Sets up a Hands-free Profile (HFP) connection of a device.
**Example** **Example**
```js ```js
let hfpAg = bluetooth.getProfile(bluetooth.ProfileId.PROFILE_HANDS_FREE_AUDIO_GATEWAY); let hfpAg = bluetooth.getProfile(bluetooth.ProfileId.PROFILE_HANDS_FREE_AUDIO_GATEWAY) as
bluetooth.HandsFreeAudioGatewayProfile;
let ret = hfpAg.connect('XX:XX:XX:XX:XX:XX'); let ret = hfpAg.connect('XX:XX:XX:XX:XX:XX');
``` ```
...@@ -1540,7 +1541,8 @@ Disconnects the HFP connection of a device. ...@@ -1540,7 +1541,8 @@ Disconnects the HFP connection of a device.
**Example** **Example**
```js ```js
let hfpAg = bluetooth.getProfile(bluetooth.ProfileId.PROFILE_HANDS_FREE_AUDIO_GATEWAY); let hfpAg = bluetooth.getProfile(bluetooth.ProfileId.PROFILE_HANDS_FREE_AUDIO_GATEWAY) as
bluetooth.HandsFreeAudioGatewayProfile;
let ret = hfpAg.disconnect('XX:XX:XX:XX:XX:XX'); let ret = hfpAg.disconnect('XX:XX:XX:XX:XX:XX');
``` ```
...@@ -1558,7 +1560,7 @@ Subscribes to the HFP connection state change events. ...@@ -1558,7 +1560,7 @@ Subscribes to the HFP connection state change events.
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- | | -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type | string | Yes | Event type. The value **connectionStateChange** indicates an HFP connection state change event.| | type | string | Yes | Event type. The value **connectionStateChange** indicates an HFP connection state change event.|
| callback | Callback&lt;[StateChangeParam](#StateChangeParam)&gt; | Yes | Callback used to return the HFP connection state change event. | | callback | Callback&lt;[StateChangeParam](#StateChangeParam)&gt; | Yes | Callback invoked to return the HFP connection state change event. |
**Return value** **Return value**
...@@ -1570,7 +1572,8 @@ No value is returned. ...@@ -1570,7 +1572,8 @@ No value is returned.
function onReceiveEvent(data) { function onReceiveEvent(data) {
console.info('hfp state = '+ JSON.stringify(data)); console.info('hfp state = '+ JSON.stringify(data));
} }
let hfpAg = bluetooth.getProfile(bluetooth.ProfileId.PROFILE_HANDS_FREE_AUDIO_GATEWAY); let hfpAg = bluetooth.getProfile(bluetooth.ProfileId.PROFILE_HANDS_FREE_AUDIO_GATEWAY) as
bluetooth.HandsFreeAudioGatewayProfile;
hfpAg.on('connectionStateChange', onReceiveEvent); hfpAg.on('connectionStateChange', onReceiveEvent);
``` ```
...@@ -1588,7 +1591,7 @@ Unsubscribes from the HFP connection state change events. ...@@ -1588,7 +1591,7 @@ Unsubscribes from the HFP connection state change events.
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- | | -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type | string | Yes | Event type. The value **connectionStateChange** indicates an HFP connection state change event.| | type | string | Yes | Event type. The value **connectionStateChange** indicates an HFP connection state change event.|
| callback | Callback&lt;[StateChangeParam](#StateChangeParam)&gt; | No | Callback used to return the HFP connection state change event. | | callback | Callback&lt;[StateChangeParam](#StateChangeParam)&gt; | No | Callback for the HFP connection state change event. |
**Return value** **Return value**
...@@ -1600,7 +1603,8 @@ No value is returned. ...@@ -1600,7 +1603,8 @@ No value is returned.
function onReceiveEvent(data) { function onReceiveEvent(data) {
console.info('hfp state = '+ JSON.stringify(data)); console.info('hfp state = '+ JSON.stringify(data));
} }
let hfpAg = bluetooth.getProfile(bluetooth.ProfileId.PROFILE_HANDS_FREE_AUDIO_GATEWAY); let hfpAg = bluetooth.getProfile(bluetooth.ProfileId.PROFILE_HANDS_FREE_AUDIO_GATEWAY) as
bluetooth.HandsFreeAudioGatewayProfile;
hfpAg.on('connectionStateChange', onReceiveEvent); hfpAg.on('connectionStateChange', onReceiveEvent);
hfpAg.off('connectionStateChange', onReceiveEvent); hfpAg.off('connectionStateChange', onReceiveEvent);
``` ```
...@@ -1617,7 +1621,7 @@ connect(device: string): boolean ...@@ -1617,7 +1621,7 @@ 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. **System API**: This is a system API.
**Required permissions**: ohos.permission.DISCOVER_BLUETOOTH **Required permissions**: ohos.permission.DISCOVER_BLUETOOTH
...@@ -1638,7 +1642,7 @@ This is a system API. ...@@ -1638,7 +1642,7 @@ This is a system API.
**Example** **Example**
```js ```js
let hidHostProfile = bluetooth.getProfile(bluetooth.ProfileId.PROFILE_HID_HOST); let hidHostProfile = bluetooth.getProfileInst(bluetooth.ProfileId.PROFILE_HID_HOST) as bluetooth.HidHostProfile;
let ret = hidHostProfile.connect('XX:XX:XX:XX:XX:XX'); let ret = hidHostProfile.connect('XX:XX:XX:XX:XX:XX');
``` ```
...@@ -1649,7 +1653,7 @@ disconnect(device: string): boolean ...@@ -1649,7 +1653,7 @@ 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. **System API**: This is a system API.
**Required permissions**: ohos.permission.DISCOVER_BLUETOOTH **Required permissions**: ohos.permission.DISCOVER_BLUETOOTH
...@@ -1670,7 +1674,7 @@ This is a system API. ...@@ -1670,7 +1674,7 @@ This is a system API.
**Example** **Example**
```js ```js
let hidHostProfile = bluetooth.getProfile(bluetooth.ProfileId.PROFILE_HID_HOST); let hidHostProfile = bluetooth.getProfileInst(bluetooth.ProfileId.PROFILE_HID_HOST) as bluetooth.HidHostProfile;
let ret = hidHostProfile.disconnect('XX:XX:XX:XX:XX:XX'); let ret = hidHostProfile.disconnect('XX:XX:XX:XX:XX:XX');
``` ```
...@@ -1700,7 +1704,7 @@ No value is returned. ...@@ -1700,7 +1704,7 @@ No value is returned.
function onReceiveEvent(data) { function onReceiveEvent(data) {
console.info('hidHost state = '+ JSON.stringify(data)); console.info('hidHost state = '+ JSON.stringify(data));
} }
let hidHost = bluetooth.getProfile(bluetooth.ProfileId.PROFILE_HID_HOST); let hidHost = bluetooth.getProfileInst(bluetooth.ProfileId.PROFILE_HID_HOST) as bluetooth.HidHostProfile;
hidHost.on('connectionStateChange', onReceiveEvent); hidHost.on('connectionStateChange', onReceiveEvent);
``` ```
...@@ -1718,7 +1722,7 @@ Unsubscribes from the HidHost connection state change events. ...@@ -1718,7 +1722,7 @@ Unsubscribes from the HidHost connection state change events.
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ----------------------------------------------------- | ---- | --------------------------------------------------------- | | -------- | ----------------------------------------------------- | ---- | --------------------------------------------------------- |
| type | string | Yes | Event type. The value **connectionStateChange** indicates a HidHost connection state change event.| | type | string | Yes | Event type. The value **connectionStateChange** indicates a HidHost connection state change event.|
| callback | Callback&lt;[StateChangeParam](#StateChangeParam)&gt; | No | Callback used to return the HidHost connection state change event. | | callback | Callback&lt;[StateChangeParam](#StateChangeParam)&gt; | No | Callback for the HidHost connection state change event. |
**Return value** **Return value**
...@@ -1730,7 +1734,7 @@ No value is returned. ...@@ -1730,7 +1734,7 @@ No value is returned.
function onReceiveEvent(data) { function onReceiveEvent(data) {
console.info('hidHost state = '+ JSON.stringify(data)); console.info('hidHost state = '+ JSON.stringify(data));
} }
let hidHost = bluetooth.getProfile(bluetooth.ProfileId.PROFILE_HID_HOST); let hidHost = bluetooth.getProfileInst(bluetooth.ProfileId.PROFILE_HID_HOST) as bluetooth.HidHostProfile;
hidHost.on('connectionStateChange', onReceiveEvent); hidHost.on('connectionStateChange', onReceiveEvent);
hidHost.off('connectionStateChange', onReceiveEvent); hidHost.off('connectionStateChange', onReceiveEvent);
``` ```
...@@ -1747,7 +1751,7 @@ disconnect(device: string): boolean ...@@ -1747,7 +1751,7 @@ disconnect(device: string): boolean
Disconnects from the Personal Area Network (PAN) service of a device. Disconnects from the Personal Area Network (PAN) service of a device.
This is a system API. **System API**: This is a system API.
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
...@@ -1768,7 +1772,7 @@ This is a system API. ...@@ -1768,7 +1772,7 @@ This is a system API.
**Example** **Example**
```js ```js
let panProfile = bluetooth.getProfile(bluetooth.ProfileId.PROFILE_PAN_NETWORK); let panProfile = bluetooth.getProfileInst(bluetooth.ProfileId.PROFILE_PAN_NETWORK) as bluetooth.PanProfile;
let ret = panProfile.disconnect('XX:XX:XX:XX:XX:XX'); let ret = panProfile.disconnect('XX:XX:XX:XX:XX:XX');
``` ```
...@@ -1786,7 +1790,7 @@ Subscribes to the PAN connection state change events. ...@@ -1786,7 +1790,7 @@ Subscribes to the PAN connection state change events.
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- | | -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type | string | Yes | Event type. The value **connectionStateChange** indicates a PAN connection state change event.| | type | string | Yes | Event type. The value **connectionStateChange** indicates a PAN connection state change event.|
| callback | Callback&lt;[StateChangeParam](#StateChangeParam)&gt; | Yes | Callback used to return the PAN connection state change event. | | callback | Callback&lt;[StateChangeParam](#StateChangeParam)&gt; | Yes | Callback invoked to return the PAN connection state change event. |
**Return value** **Return value**
...@@ -1798,7 +1802,7 @@ No value is returned. ...@@ -1798,7 +1802,7 @@ No value is returned.
function onReceiveEvent(data) { function onReceiveEvent(data) {
console.info('pan state = '+ JSON.stringify(data)); console.info('pan state = '+ JSON.stringify(data));
} }
let panProfile = bluetooth.getProfile(bluetooth.ProfileId.PROFILE_PAN_NETWORK); let panProfile = bluetooth.getProfileInst(bluetooth.ProfileId.PROFILE_PAN_NETWORK) as bluetooth.PanProfile;
panProfile.on('connectionStateChange', onReceiveEvent); panProfile.on('connectionStateChange', onReceiveEvent);
``` ```
...@@ -1816,7 +1820,7 @@ Unsubscribes from the PAN connection state change events. ...@@ -1816,7 +1820,7 @@ Unsubscribes from the PAN connection state change events.
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ----------------------------------------------------- | ---- | --------------------------------------------------------- | | -------- | ----------------------------------------------------- | ---- | --------------------------------------------------------- |
| type | string | Yes | Event type. The value **connectionStateChange** indicates a PAN connection state change event.| | type | string | Yes | Event type. The value **connectionStateChange** indicates a PAN connection state change event.|
| callback | Callback&lt;[StateChangeParam](#StateChangeParam)&gt; | No | Callback used to return the PAN connection state change event. | | callback | Callback&lt;[StateChangeParam](#StateChangeParam)&gt; | No | Callback for the PAN connection state change event. |
**Return value** **Return value**
...@@ -1828,7 +1832,7 @@ No value is returned. ...@@ -1828,7 +1832,7 @@ No value is returned.
function onReceiveEvent(data) { function onReceiveEvent(data) {
console.info('pan state = '+ JSON.stringify(data)); console.info('pan state = '+ JSON.stringify(data));
} }
let panProfile = bluetooth.getProfile(bluetooth.ProfileId.PROFILE_PAN_NETWORK); let panProfile = bluetooth.getProfileInst(bluetooth.ProfileId.PROFILE_PAN_NETWORK) as bluetooth.PanProfile;
panProfile.on('connectionStateChange', onReceiveEvent); panProfile.on('connectionStateChange', onReceiveEvent);
panProfile.off('connectionStateChange', onReceiveEvent); panProfile.off('connectionStateChange', onReceiveEvent);
``` ```
...@@ -1840,7 +1844,7 @@ setTethering(enable: boolean): void ...@@ -1840,7 +1844,7 @@ setTethering(enable: boolean): void
Sets tethering. Sets tethering.
This is a system API. **System API**: This is a system API.
**Required permissions**: ohos.permission.DISCOVER_BLUETOOTH **Required permissions**: ohos.permission.DISCOVER_BLUETOOTH
...@@ -1861,7 +1865,7 @@ This is a system API. ...@@ -1861,7 +1865,7 @@ This is a system API.
**Example** **Example**
```js ```js
let panProfile = bluetooth.getProfile(bluetooth.ProfileId.PROFILE_PAN_NETWORK); let panProfile = bluetooth.getProfileInst(bluetooth.ProfileId.PROFILE_PAN_NETWORK) as bluetooth.PanProfile;
let ret = panProfile.setTethering(true); let ret = panProfile.setTethering(true);
``` ```
...@@ -1872,7 +1876,7 @@ isTetheringOn(): boolean ...@@ -1872,7 +1876,7 @@ isTetheringOn(): boolean
Obtains the tethering state. Obtains the tethering state.
This is a system API. **System API**: This is a system API.
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
...@@ -1885,7 +1889,7 @@ This is a system API. ...@@ -1885,7 +1889,7 @@ This is a system API.
**Example** **Example**
```js ```js
let panProfile = bluetooth.getProfile(bluetooth.ProfileId.PROFILE_PAN_NETWORK); let panProfile = bluetooth.getProfileInst(bluetooth.ProfileId.PROFILE_PAN_NETWORK) as bluetooth.PanProfile;
let ret = panProfile.isTetheringOn(); let ret = panProfile.isTetheringOn();
``` ```
...@@ -2061,10 +2065,9 @@ Removes a service from this GATT server. ...@@ -2061,10 +2065,9 @@ Removes a service from this GATT server.
**Return value** **Return value**
| | | | Type | Description |
| ------- | -------------------------- | | ------- | -------------------------- |
| Type | Description | | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
| boolean | Returns **true** if the operation is successful; returns **false** otherwise. |
**Example** **Example**
...@@ -2111,10 +2114,9 @@ Notifies the connected client device when a characteristic value changes. ...@@ -2111,10 +2114,9 @@ Notifies the connected client device when a characteristic value changes.
**Return value** **Return value**
| | | | Type | Description |
| ------- | ------------------------ | | ------- | ------------------------ |
| Type | Description | | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
| boolean | Returns **true** if the operation is successful; returns **false** otherwise. |
**Example** **Example**
...@@ -2156,10 +2158,9 @@ Sends a response to a read or write request from the GATT client. ...@@ -2156,10 +2158,9 @@ Sends a response to a read or write request from the GATT client.
**Return value** **Return value**
| | | | Type | Description |
| ------- | -------------------------- | | ------- | -------------------------- |
| Type | Description | | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
| boolean | Returns **true** if the operation is successful; returns **false** otherwise. |
**Example** **Example**
...@@ -2220,7 +2221,7 @@ function ReadCharacteristicReq(CharacteristicReadReq) { ...@@ -2220,7 +2221,7 @@ function ReadCharacteristicReq(CharacteristicReadReq) {
let characteristicUuid = CharacteristicReadReq.characteristicUuid; let characteristicUuid = CharacteristicReadReq.characteristicUuid;
let serverResponse = {deviceId: deviceId, transId: transId, status: 0, offset: offset, value:arrayBufferCCC}; let serverResponse = {deviceId: deviceId, transId: transId, status: 0, offset: offset, value:arrayBufferCCC};
let ret = gattServer.sendResponse(serverResponse); let ret = gattServer.sendResponse(serverResponse);
if (ret) { if (ret) {
console.log('bluetooth sendResponse successfully'); console.log('bluetooth sendResponse successfully');
...@@ -2249,7 +2250,7 @@ Unsubscribes from the characteristic read request events. ...@@ -2249,7 +2250,7 @@ Unsubscribes from the characteristic read request events.
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- | | -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type | string | Yes | Event type. The value **characteristicRead** indicates a characteristic read request event. | | type | string | Yes | Event type. The value **characteristicRead** indicates a characteristic read request event. |
| callback | Callback&lt;[CharacteristicReadReq](#characteristicreadreq)&gt; | No | Callback used to report a characteristic read request event. If this parameter is not set, this method unsubscribes from all callbacks corresponding to **type**.| | callback | Callback&lt;[CharacteristicReadReq](#characteristicreadreq)&gt; | No | Callback for the characteristic read request event. If this parameter is not set, this method unsubscribes from all callbacks corresponding to **type**.|
**Return value** **Return value**
...@@ -2297,10 +2298,10 @@ function WriteCharacteristicReq(CharacteristicWriteReq) { ...@@ -2297,10 +2298,10 @@ function WriteCharacteristicReq(CharacteristicWriteReq) {
let needRsp = CharacteristicWriteReq.needRsp; let needRsp = CharacteristicWriteReq.needRsp;
let value = new Uint8Array(CharacteristicWriteReq.value); let value = new Uint8Array(CharacteristicWriteReq.value);
let characteristicUuid = CharacteristicWriteReq.characteristicUuid; let characteristicUuid = CharacteristicWriteReq.characteristicUuid;
cccValue[0] = value[0]; cccValue[0] = value[0];
let serverResponse = {deviceId: deviceId, transId: transId, status: 0, offset: offset, value:arrayBufferCCC}; let serverResponse = {deviceId: deviceId, transId: transId, status: 0, offset: offset, value:arrayBufferCCC};
let ret = gattServer.sendResponse(serverResponse); let ret = gattServer.sendResponse(serverResponse);
if (ret) { if (ret) {
console.log('bluetooth sendResponse successfully'); console.log('bluetooth sendResponse successfully');
...@@ -2329,7 +2330,7 @@ Unsubscribes from the characteristic write request events. ...@@ -2329,7 +2330,7 @@ Unsubscribes from the characteristic write request events.
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- | | -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type | string | Yes | Event type. The value **characteristicWrite** indicates a characteristic write request event. | | type | string | Yes | Event type. The value **characteristicWrite** indicates a characteristic write request event. |
| callback | Callback&lt;[CharacteristicWriteReq](#characteristicwritereq)&gt; | No | Callback used to report a characteristic write request event. If this parameter is not set, this method unsubscribes from all callbacks corresponding to **type**.| | callback | Callback&lt;[CharacteristicWriteReq](#characteristicwritereq)&gt; | No | Callback for the characteristic write request event. If this parameter is not set, this method unsubscribes from all callbacks corresponding to **type**.|
**Return value** **Return value**
...@@ -2377,7 +2378,7 @@ function ReadDescriptorReq(DescriptorReadReq) { ...@@ -2377,7 +2378,7 @@ function ReadDescriptorReq(DescriptorReadReq) {
let descriptorUuid = DescriptorReadReq.descriptorUuid; let descriptorUuid = DescriptorReadReq.descriptorUuid;
let serverResponse = {deviceId: deviceId, transId: transId, status: 0, offset: offset, value:arrayBufferDesc}; let serverResponse = {deviceId: deviceId, transId: transId, status: 0, offset: offset, value:arrayBufferDesc};
let ret = gattServer.sendResponse(serverResponse); let ret = gattServer.sendResponse(serverResponse);
if (ret) { if (ret) {
console.log('bluetooth sendResponse successfully'); console.log('bluetooth sendResponse successfully');
...@@ -2406,7 +2407,7 @@ Unsubscribes from the descriptor read request events. ...@@ -2406,7 +2407,7 @@ Unsubscribes from the descriptor read request events.
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- | | -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type | string | Yes | Event type. The value **descriptorRead** indicates a descriptor read request event. | | type | string | Yes | Event type. The value **descriptorRead** indicates a descriptor read request event. |
| callback | Callback&lt;[DescriptorReadReq](#descriptorreadreq)&gt; | No | Callback used to report a descriptor read request event. If this parameter is not set, this method unsubscribes from all callbacks corresponding to **type**.| | callback | Callback&lt;[DescriptorReadReq](#descriptorreadreq)&gt; | No | Callback for the descriptor read request event. If this parameter is not set, this method unsubscribes from all callbacks corresponding to **type**.|
**Return value** **Return value**
...@@ -2457,7 +2458,7 @@ function WriteDescriptorReq(DescriptorWriteReq) { ...@@ -2457,7 +2458,7 @@ function WriteDescriptorReq(DescriptorWriteReq) {
descValue[0] = value[0]; descValue[0] = value[0];
let serverResponse = {deviceId: deviceId, transId: transId, status: 0, offset: offset, value:arrayBufferDesc}; let serverResponse = {deviceId: deviceId, transId: transId, status: 0, offset: offset, value:arrayBufferDesc};
let ret = gattServer.sendResponse(serverResponse); let ret = gattServer.sendResponse(serverResponse);
if (ret) { if (ret) {
console.log('bluetooth sendResponse successfully'); console.log('bluetooth sendResponse successfully');
...@@ -2486,7 +2487,7 @@ Unsubscribes from the descriptor write request events. ...@@ -2486,7 +2487,7 @@ Unsubscribes from the descriptor write request events.
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- | | -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type | string | Yes | Event type. The value **descriptorWrite** indicates a descriptor write request event. | | type | string | Yes | Event type. The value **descriptorWrite** indicates a descriptor write request event. |
| callback | Callback&lt;[DescriptorWriteReq](#descriptorwritereq)&gt; | No | Callback used to report a descriptor write request event. If this parameter is not set, this method unsubscribes from all callbacks corresponding to **type**.| | callback | Callback&lt;[DescriptorWriteReq](#descriptorwritereq)&gt; | No | Callback for the descriptor write request event. If this parameter is not set, this method unsubscribes from all callbacks corresponding to **type**.|
**Return value** **Return value**
...@@ -2499,6 +2500,7 @@ let gattServer = bluetooth.BLE.createGattServer(); ...@@ -2499,6 +2500,7 @@ let gattServer = bluetooth.BLE.createGattServer();
gattServer.off("descriptorWrite"); gattServer.off("descriptorWrite");
``` ```
### on('connectStateChange') ### on('connectStateChange')
on(type: "connectStateChange", callback: Callback&lt;BLEConnectChangedState&gt;): void on(type: "connectStateChange", callback: Callback&lt;BLEConnectChangedState&gt;): void
...@@ -2548,7 +2550,7 @@ Unsubscribes from the BLE connection state change events. ...@@ -2548,7 +2550,7 @@ Unsubscribes from the BLE connection state change events.
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- | | -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type | string | Yes | Event type. The value **connectStateChange** indicates a BLE connection state change event.| | type | string | Yes | Event type. The value **connectStateChange** indicates a BLE connection state change event.|
| callback | Callback&lt;[BLEConnectChangedState](#bleconnectchangedstate)&gt; | No | Callback used to report the BLE connection state. If this parameter is not set, this method unsubscribes from all callbacks corresponding to **type**.| | 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**.|
**Return value** **Return value**
...@@ -2785,10 +2787,9 @@ Reads the characteristic value of the specific service of the remote BLE device. ...@@ -2785,10 +2787,9 @@ Reads the characteristic value of the specific service of the remote BLE device.
**Return value** **Return value**
| | | | Type | Description |
| ---------------------------------------- | -------------------------- | | ---------------------------------------- | -------------------------- |
| Type | Description | | Promise&lt;[BLECharacteristic](#blecharacteristic)&gt; | Promise used to return the characteristic value read.|
| Promise&lt;[BLECharacteristic](#blecharacteristic)&gt; | Promise used to return the characteristic value read. |
**Example** **Example**
...@@ -2876,10 +2877,9 @@ Reads the descriptor contained in the specific characteristic of the remote BLE ...@@ -2876,10 +2877,9 @@ Reads the descriptor contained in the specific characteristic of the remote BLE
**Return value** **Return value**
| | | | Type | Description |
| ---------------------------------------- | -------------------------- | | ---------------------------------------- | -------------------------- |
| Type | Description | | Promise&lt;[BLEDescriptor](#bledescriptor)&gt; | Promise used to return the descriptor read.|
| Promise&lt;[BLEDescriptor](#bledescriptor)&gt; | Promise used to return the descriptor read. |
**Example** **Example**
...@@ -2990,7 +2990,7 @@ if (retWriteDesc) { ...@@ -2990,7 +2990,7 @@ if (retWriteDesc) {
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 method 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).
**Required permissions**: ohos.permission.USE_BLUETOOTH **Required permissions**: ohos.permission.USE_BLUETOOTH
...@@ -3108,7 +3108,7 @@ Unsubscribes from the BLE characteristic change events. ...@@ -3108,7 +3108,7 @@ Unsubscribes from the BLE characteristic change events.
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- | | -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type | string | Yes | Event type. The value **BLECharacteristicChange** indicates a characteristic value change event.| | type | string | Yes | Event type. The value **BLECharacteristicChange** indicates a characteristic value change event.|
| callback | Callback&lt;[BLECharacteristic](#blecharacteristic)&gt; | No | Callback used to report the characteristic value. If this parameter is not set, this method unsubscribes from all callbacks corresponding to **type**.| | 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**.|
**Return value** **Return value**
...@@ -3170,7 +3170,7 @@ Unsubscribes from the BLE connection state change events. ...@@ -3170,7 +3170,7 @@ Unsubscribes from the BLE connection state change events.
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- | | -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type | string | Yes | Event type. The value **BLEConnectionStateChange** indicates a BLE connection state change event.| | type | string | Yes | Event type. The value **BLEConnectionStateChange** indicates a BLE connection state change event.|
| callback | Callback&lt;[BLEConnectChangedState](#bleconnectchangedstate)&gt; | No | Callback used to report the BLE connection state. If this parameter is not set, this method unsubscribes from all callbacks corresponding to **type**.| | 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**.|
**Return value** **Return value**
...@@ -3671,13 +3671,13 @@ Defines the pairing request parameters. ...@@ -3671,13 +3671,13 @@ Defines the pairing request parameters.
## BondStateParam<sup>8+</sup><a name="BondStateParam"></a> ## BondStateParam<sup>8+</sup><a name="BondStateParam"></a>
Defines the bond state parameters. Defines the pairing state parameters.
**System capability**: SystemCapability.Communication.Bluetooth.Core **System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Type | Readable | Writable | Description | | Name | Type | Readable | Writable | Description |
| -------- | ------ | ---- | ---- | ----------- | | -------- | ------ | ---- | ---- | ----------- |
| deviceId | string | Yes | No | ID of the device.| | deviceId | string | Yes | No | ID of the device to pair.|
| state | BondState | Yes | No | State of the device.| | state | BondState | Yes | No | State of the device.|
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册