From 1d4328ee8ea0f9a897cfc3cb0a6d26ef6d7f6a8b Mon Sep 17 00:00:00 2001 From: smartbao Date: Fri, 18 Mar 2022 16:47:00 +0800 Subject: [PATCH] md modify Signed-off-by: smartbao --- .../reference/apis/js-apis-bluetooth.md | 1144 ++++++++++++++--- 1 file changed, 960 insertions(+), 184 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 4a21a3d900..a6e87bf748 100755 --- a/zh-cn/application-dev/reference/apis/js-apis-bluetooth.md +++ b/zh-cn/application-dev/reference/apis/js-apis-bluetooth.md @@ -1,7 +1,7 @@ # 蓝牙 > ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:** -> 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 +> 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 > > 蓝牙模块提供了基础的传统蓝牙能力以及BLE的扫描、广播等功能。 @@ -26,12 +26,16 @@ ohos.permission.LOCATION -## bluetooth.enableBluetooth +## bluetooth.enableBluetooth8+ enableBluetooth(): boolean 开启蓝牙。 +**需要权限**:ohos.permission.DISCOVER_BLUETOOTH + +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + **返回值:** | 类型 | 说明 | @@ -40,17 +44,21 @@ enableBluetooth(): boolean **示例:** -``` +```js let enable = bluetooth.enableBluetooth(); ``` -## bluetooth.disableBluetooth +## bluetooth.disableBluetooth8+ disableBluetooth(): boolean 关闭蓝牙。 +**需要权限**:ohos.permission.DISCOVER_BLUETOOTH + +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + **返回值:** | 类型 | 说明 | @@ -59,17 +67,21 @@ disableBluetooth(): boolean **示例:** -``` +```js let disable = bluetooth.disableBluetooth(); ``` -## bluetooth.getLocalName +## bluetooth.getLocalName8+ getLocalName(): string 获取蓝牙本地设备名称。 +**需要权限**:ohos.permission.USE_BLUETOOTH + +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + **返回值:** | 类型 | 说明 | @@ -78,7 +90,7 @@ getLocalName(): string **示例:** -``` +```js let localName = bluetooth.getLocalName(); ``` @@ -89,6 +101,10 @@ getState(): BluetoothState 获取蓝牙开关状态。 +**需要权限**:ohos.permission.USE_BLUETOOTH + +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + **返回值:** | 类型 | 说明 | @@ -97,7 +113,7 @@ getState(): BluetoothState **示例:** -``` +```js let state = bluetooth.getState(); ``` @@ -108,6 +124,10 @@ getBtConnectionState(): ProfileConnectionState 获取蓝牙设备的Profile连接状态。 +**需要权限**:ohos.permission.USE_BLUETOOTH + +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + **返回值:** | 类型 | 说明 | @@ -116,33 +136,36 @@ getBtConnectionState(): ProfileConnectionState **示例:** -``` +```js let connectionState = bluetooth.getBtConnectionState(); ``` -## bluetooth.setLocalName +## bluetooth.setLocalName8+ setLocalName(name: string): boolean 设置蓝牙本地设备名称。 +**需要权限**:ohos.permission.DISCOVER_BLUETOOTH + +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | -------- | -------- | -------- | -| name | string | 是 | 要设置的蓝牙名称,最大长度为128。 | +| name | string | 是 | 要设置的蓝牙名称,最大长度为248。 | **返回值:** -| | | -| -------- | -------- | | 类型 | 说明 | +| -------- | -------- | | boolean | 设置蓝牙本地设备名称,成功返回true,否则返回false。 | **示例:** -``` +```js let ret = bluetooth.setLocalName('device_name'); ``` @@ -153,6 +176,10 @@ pairDevice(deviceId: string): boolean 发起蓝牙配对。 +**需要权限**:ohos.permission.DISCOVER_BLUETOOTH + +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + **参数:** | 参数名 | 类型 | 必填 | 说明 | @@ -167,18 +194,51 @@ pairDevice(deviceId: string): boolean **示例:** -``` +```js // 实际的地址可由扫描流程获取 let result = bluetooth.pairDevice("XX:XX:XX:XX:XX:XX"); ``` -## bluetooth.cancelPairedDevice +## bluetooth.getProfileConnState8+ + +getProfileConnState(profileId: ProfileId): ProfileConnectionState + +获取profile的连接状态。 + +**需要权限**:ohos.permission.USE_BLUETOOTH + +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | -------- | -------- | -------- | +| ProfileId | profileId | 是 | 表示profile的枚举值,例如:PROFILE_A2DP_SOURCE。 | + +**返回值:** + +| 类型 | 说明 | +| -------- | -------- | +| [ProfileConnectionState](#ProfileConnectionState) | profile的连接状态。 | + +**示例:** + +```js +let result = bluetooth.getProfileConnState(PROFILE_A2DP_SOURCE); +``` + + +## bluetooth.cancelPairedDevice8+ cancelPairedDevice(deviceId: string): boolean 删除配对的远程设备。 +**需要权限**:ohos.permission.DISCOVER_BLUETOOTH + +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + **参数:** | 参数名 | 类型 | 必填 | 说明 | @@ -193,17 +253,21 @@ cancelPairedDevice(deviceId: string): boolean **示例:** -``` +```js let result = bluetooth.cancelPairedDevice("XX:XX:XX:XX:XX:XX"); ``` -## bluetooth.getRemoteDeviceName +## bluetooth.getRemoteDeviceName8+ getRemoteDeviceName(deviceId: string): string 获取对端蓝牙设备的名称。 +**需要权限**:ohos.permission.USE_BLUETOOTH + +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + **参数:** | 参数名 | 类型 | 必填 | 说明 | @@ -218,17 +282,21 @@ getRemoteDeviceName(deviceId: string): string **示例:** -``` +```js let remoteDeviceName = bluetooth.getRemoteDeviceName("XX:XX:XX:XX:XX:XX"); ``` -## bluetooth.getRemoteDeviceClass +## bluetooth.getRemoteDeviceClass8+ getRemoteDeviceClass(deviceId: string): DeviceClass 获取对端蓝牙设备的类别。 +**需要权限**:ohos.permission.USE_BLUETOOTH + +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + **参数:** | 参数名 | 类型 | 必填 | 说明 | @@ -243,17 +311,21 @@ getRemoteDeviceClass(deviceId: string): DeviceClass **示例:** -``` +```js let remoteDeviceClass = bluetooth.getRemoteDeviceClass("XX:XX:XX:XX:XX:XX"); ``` -## bluetooth.getPairedDevices +## bluetooth.getPairedDevices8+ getPairedDevices(): Array<string> 获取蓝牙配对列表。 +**需要权限**:ohos.permission.USE_BLUETOOTH + +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + **返回值:** | 类型 | 说明 | @@ -262,17 +334,21 @@ getPairedDevices(): Array<string> **示例:** -``` +```js let devices = bluetooth.getPairedDevices(); ``` -## bluetooth.setBluetoothScanMode +## bluetooth.setBluetoothScanMode8+ setBluetoothScanMode(mode: ScanMode, duration: number): boolean 设置蓝牙扫描模式,可以被远端设备发现。 +**需要权限**:ohos.permission.USE_BLUETOOTH + +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + **参数:** | 参数名 | 类型 | 必填 | 说明 | @@ -288,18 +364,22 @@ setBluetoothScanMode(mode: ScanMode, duration: number): boolean **示例:** -``` +```js // 设置为可连接可发现才可被远端设备扫描到,可以连接。 let result = bluetooth.setBluetoothScanMode(ScanMode.SCAN_MODE_CONNECTABLE_GENERAL_DISCOVERABLE, 100); ``` -## bluetooth.getBluetoothScanMode +## bluetooth.getBluetoothScanMode8+ getBluetoothScanMode(): ScanMode 获取蓝牙扫描模式。 +**需要权限**:ohos.permission.USE_BLUETOOTH + +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + **返回值:** | 类型 | 说明 | @@ -308,17 +388,21 @@ getBluetoothScanMode(): ScanMode **示例:** -``` +```js let scanMode = bluetooth.getBluetoothScanMode(); ``` -## bluetooth.startBluetoothDiscovery +## bluetooth.startBluetoothDiscovery8+ startBluetoothDiscovery(): boolean 开启蓝牙扫描,可以发现远端设备。 +**需要权限**:ohos.permission.USE_BLUETOOTH;ohos.permission.LOCATION + +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + **返回值:** | 类型 | 说明 | @@ -327,7 +411,7 @@ startBluetoothDiscovery(): boolean **示例:** -``` +```js let deviceId; function onReceiveEvent(data) { deviceId = data; @@ -337,12 +421,16 @@ let result = bluetooth.startBluetoothDiscovery(); ``` -## bluetooth.stopBluetoothDiscovery +## bluetooth.stopBluetoothDiscovery8+ stopBluetoothDiscovery(): boolean 关闭蓝牙扫描。 +**需要权限**:ohos.permission.DISCOVER_BLUETOOTH + +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + **返回值:** | 类型 | 说明 | @@ -351,17 +439,21 @@ stopBluetoothDiscovery(): boolean **示例:** -``` +```js let result = bluetooth.stopBluetoothDiscovery(); ``` -## bluetooth.setDevicePairingConfirmation +## bluetooth.setDevicePairingConfirmation8+ setDevicePairingConfirmation(device: string, accept: boolean): boolean 设置设备配对请求确认。 +**需要权限**:ohos.permission.MANAGE_BLUETOOTH + +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + **参数:** | 参数名 | 类型 | 必填 | 说明 | @@ -377,7 +469,7 @@ setDevicePairingConfirmation(device: string, accept: boolean): boolean **示例:** -``` +```js // 订阅“pinRequired”配对请求事件,收到远端配对请求后设置配对确认 function onReceivePinRequiredEvent(data) { // data为配对请求的入参,配对请求参数 console.info('pin required = '+ JSON.stringify(data)); @@ -387,12 +479,16 @@ bluetooth.on("pinRequired", onReceivePinRequiredEvent); ``` -## bluetooth.on('bluetoothDeviceFind') +## bluetooth.on('bluetoothDeviceFind')8+ on(type: "bluetoothDeviceFind", callback: Callback<Array<string>>): void 订阅蓝牙设备发现上报事件。 +**需要权限**:ohos.permission.USE_BLUETOOTH + +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + **参数:** | 参数名 | 类型 | 必填 | 说明 | @@ -406,7 +502,7 @@ on(type: "bluetoothDeviceFind", callback: Callback<Array<string>>): **示例:** -``` +```js function onReceiveEvent(data) { // data为蓝牙设备地址集合 console.info('bluetooth device find = '+ JSON.stringify(data)); } @@ -414,12 +510,16 @@ bluetooth.on('bluetoothDeviceFind', onReceiveEvent); ``` -## bluetooth.off('bluetoothDeviceFind') +## bluetooth.off('bluetoothDeviceFind')8+ off(type: "bluetoothDeviceFind", callback?: Callback<Array<string>>): void 取消订阅蓝牙设备发现上报事件。 +**需要权限**:ohos.permission.USE_BLUETOOTH + +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + **参数:** | 参数名 | 类型 | 必填 | 说明 | @@ -433,7 +533,7 @@ off(type: "bluetoothDeviceFind", callback?: Callback<Array<string>>) **示例:** -``` +```js function onReceiveEvent(data) { console.info('bluetooth device find = '+ JSON.stringify(data)); } @@ -442,12 +542,16 @@ bluetooth.off('bluetoothDeviceFind', onReceiveEvent); ``` -## bluetooth.on('pinRequired') +## bluetooth.on('pinRequired')8+ on(type: "pinRequired", callback: Callback<PinRequiredParam>): void 订阅远端蓝牙设备的配对请求事件。 +**需要权限**:ohos.permission.DISCOVER_BLUETOOTH + +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + **参数:** | 参数名 | 类型 | 必填 | 说明 | @@ -461,7 +565,7 @@ on(type: "pinRequired", callback: Callback<PinRequiredParam>): void **示例:** -``` +```js function onReceiveEvent(data) { // data为配对请求参数 console.info('pin required = '+ JSON.stringify(data)); } @@ -469,12 +573,16 @@ bluetooth.on('pinRequired', onReceiveEvent); ``` -## bluetooth.off('pinRequired') +## bluetooth.off('pinRequired')8+ off(type: "pinRequired", callback?: Callback<PinRequiredParam>): void 取消订阅远端蓝牙设备的配对请求事件。 +**需要权限**:ohos.permission.DISCOVER_BLUETOOTH + +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + **参数:** | 参数名 | 类型 | 必填 | 说明 | @@ -488,7 +596,7 @@ off(type: "pinRequired", callback?: Callback<PinRequiredParam>): void **示例:** -``` +```js function onReceiveEvent(data) { console.info('pin required = '+ JSON.stringify(data)); } @@ -497,12 +605,16 @@ bluetooth.off('pinRequired', onReceiveEvent); ``` -## bluetooth.on('bondStateChange') +## bluetooth.on('bondStateChange')8+ on(type: "bondStateChange", callback: Callback<BondState>): void 订阅蓝牙配对状态改变事件。 +**需要权限**:ohos.permission.USE_BLUETOOTH + +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + **参数:** | 参数名 | 类型 | 必填 | 说明 | @@ -516,7 +628,7 @@ on(type: "bondStateChange", callback: Callback<BondState>): void **示例:** -``` +```js function onReceiveEvent(data) { // data为回调函数入参,表示配对的状态 console.info('pair state = '+ JSON.stringify(data)); } @@ -524,12 +636,16 @@ bluetooth.on('bondStateChange', onReceiveEvent); ``` -## bluetooth.off('bondStateChange') +## bluetooth.off('bondStateChange')8+ off(type: "bondStateChange", callback?: Callback<BondState>): void 取消订阅蓝牙配对状态改变事件。 +**需要权限**:ohos.permission.USE_BLUETOOTH + +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + **参数:** | 参数名 | 类型 | 必填 | 说明 | @@ -543,7 +659,7 @@ off(type: "bondStateChange", callback?: Callback<BondState>): void **示例:** -``` +```js function onReceiveEvent(data) { console.info('bond state = '+ JSON.stringify(data)); } @@ -552,12 +668,16 @@ bluetooth.off('bondStateChange', onReceiveEvent); ``` -## bluetooth.on('stateChange') +## bluetooth.on('stateChange')8+ on(type: "stateChange", callback: Callback<BluetoothState>): void 订阅蓝牙连接状态改变事件。 +**需要权限**:ohos.permission.USE_BLUETOOTH + +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + **参数:** | 参数名 | 类型 | 必填 | 说明 | @@ -571,7 +691,7 @@ on(type: "stateChange", callback: Callback<BluetoothState>): void **示例:** -``` +```js function onReceiveEvent(data) { console.info('bluetooth state = '+ JSON.stringify(data)); } @@ -579,12 +699,16 @@ bluetooth.on('stateChange', onReceiveEvent); ``` -## bluetooth.off('stateChange') +## bluetooth.off('stateChange')8+ off(type: "stateChange", callback?: Callback<BluetoothState>): void 取消订阅蓝牙连接状态改变事件。 +**需要权限**:ohos.permission.USE_BLUETOOTH + +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + **参数:** | 参数名 | 类型 | 必填 | 说明 | @@ -598,7 +722,7 @@ off(type: "stateChange", callback?: Callback<BluetoothState>): void **示例:** -``` +```js function onReceiveEvent(data) { console.info('bluetooth state = '+ JSON.stringify(data)); } @@ -607,12 +731,16 @@ bluetooth.off('stateChange', onReceiveEvent); ``` -## bluetooth.sppListen +## bluetooth.sppListen8+ sppListen(name: string, option: SppOption, callback: AsyncCallback<number>): void 创建一个服务端监听Socket。 +**需要权限**:ohos.permission.USE_BLUETOOTH + +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + **参数:** | 参数名 | 类型 | 必填 | 说明 | @@ -623,7 +751,7 @@ sppListen(name: string, option: SppOption, callback: AsyncCallback<number> **示例:** -``` +```js let serverNumber = -1; function serverSocket(code, number) { console.log('bluetooth error code: ' + code.code); @@ -638,12 +766,14 @@ bluetooth.sppListen('server1', sppOption, serverSocket); ``` -## bluetooth.sppAccept +## bluetooth.sppAccept8+ sppAccept(serverSocket: number, callback: AsyncCallback<number>): void 服务端监听socket等待客户端连接。 +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + **参数:** | 参数名 | 类型 | 必填 | 说明 | @@ -653,7 +783,7 @@ sppAccept(serverSocket: number, callback: AsyncCallback<number>): void **示例:** -``` +```js let clientNumber = -1; function acceptClientSocket(code, number) { console.log('bluetooth error code: ' + code.code); @@ -667,12 +797,16 @@ bluetooth.sppAccept(serverNumber, acceptClientSocket); ``` -## bluetooth.sppConnect +## bluetooth.sppConnect8+ sppConnect(device: string, option: SppOption, callback: AsyncCallback<number>): void 客户端向远端设备发起spp连接。 +**需要权限**:ohos.permission.USE_BLUETOOTH + +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + **参数:** | 参数名 | 类型 | 必填 | 说明 | @@ -683,7 +817,7 @@ sppConnect(device: string, option: SppOption, callback: AsyncCallback<number& **示例:** -``` +```js let clientNumber = -1; function clientSocket(code, number) { if (code.code != 0) { @@ -698,12 +832,14 @@ bluetooth.sppConnect('XX:XX:XX:XX:XX:XX', sppOption, clientSocket); ``` -## bluetooth.sppCloseServerSocket +## bluetooth.sppCloseServerSocket8+ sppCloseServerSocket(socket: number): void 关闭服务端监听Socket,入参socket由sppListen接口返回。 +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + **参数:** | 参数名 | 类型 | 必填 | 说明 | @@ -712,17 +848,19 @@ sppCloseServerSocket(socket: number): void **示例:** -``` +```js bluetooth.sppCloseServerSocket(serverNumber); ``` -## bluetooth.sppCloseClientSocket +## bluetooth.sppCloseClientSocket8+ sppCloseClientSocket(socket: number): void 关闭客户端socket,入参socket由sppAccept或sppConnect接口获取。 +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + **参数:** | 参数名 | 类型 | 必填 | 说明 | @@ -732,17 +870,19 @@ sppCloseClientSocket(socket: number): void **示例:** -``` +```js bluetooth.sppCloseClientSocket(clientNumber); ``` -## bluetooth.sppWrite +## bluetooth.sppWrite8+ sppWrite(clientSocket: number, data: ArrayBuffer): boolean 通过socket向远端发送数据,入参clientSocket由sppAccept或sppConnect接口获取 。 +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + **参数:** | 参数名 | 类型 | 必填 | 说明 | @@ -759,7 +899,7 @@ sppWrite(clientSocket: number, data: ArrayBuffer): boolean **示例:** -``` +```js let arrayBuffer = new ArrayBuffer(8); let data = new Uint8Array(arrayBuffer); data[0] = 123; @@ -772,12 +912,14 @@ if (ret) { ``` -## bluetooth.on('sppRead') +## bluetooth.on('sppRead')8+ on(type: "sppRead", clientSocket: number, callback: Callback<ArrayBuffer>): void 订阅spp读请求事件,入参clientSocket由sppAccept或sppConnect接口获取。 +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + **参数:** | 参数名 | 类型 | 必填 | 说明 | @@ -792,7 +934,7 @@ on(type: "sppRead", clientSocket: number, callback: Callback<ArrayBuffer>) **示例:** -``` +```js function dataRead(dataBuffer) { let data = new Uint8Array(dataBuffer); console.log('bluetooth data is: ' + data[0]); @@ -801,12 +943,14 @@ bluetooth.on('sppRead', clientNumber, dataRead); ``` -## bluetooth.off('sppRead') +## bluetooth.off('sppRead')8+ off(type: "sppRead", clientSocket: number, callback?: Callback<ArrayBuffer>): void 取消订阅spp读请求事件,入参clientSocket由sppAccept或sppConnect接口获取。 +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + **参数:** | 参数名 | 类型 | 必填 | 说明 | @@ -821,11 +965,39 @@ off(type: "sppRead", clientSocket: number, callback?: Callback<ArrayBuffer> **示例:** -``` +```js bluetooth.off('sppRead', clientNumber); ``` +## bluetooth.getProfile8+ + +getProfile(profileId: ProfileId): A2dpSourceProfile | HandsFreeAudioGatewayProfile + +通过ProfileId,获取profile的对象实例。 + +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | -------- | -------- | -------- | +| ProfileId | profileId | 是 | 表示profile的枚举值,例如:PROFILE_A2DP_SOURCE。 | + +**返回值:** + +| | | +| -------- | -------- | +| 类型 | 说明 | +| A2dpSourceProfile 或者 HandsFreeAudioGatewayProfile | 对应的profile的对象实例,当前支持A2dpSourceProfile, HandsFreeAudioGatewayProfile。 | + +**示例:** + +```js +A2dpSourceProfile a2dpSrc = bluetooth.getProfile(PROFILE_A2DP_SOURCE); +``` + + ## bluetooth.BLE ### bluetooth.BLE.createGattServer @@ -834,6 +1006,8 @@ createGattServer(): GattServer 创建一个可使用的GattServer实例。 +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + **返回值:** | 类型 | 说明 | @@ -842,123 +1016,479 @@ createGattServer(): GattServer **示例:** -``` +```js let gattServer = bluetooth.BLE.createGattServer(); ``` -### bluetooth.BLE.createGattClientDevice +### bluetooth.BLE.createGattClientDevice + +createGattClientDevice(deviceId: string): GattClientDevice + +创建一个可使用的GattClientDevice实例。 + +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | -------- | -------- | -------- | +| deviceId | string | 是 | 对端设备地址, 例如:"XX:XX:XX:XX:XX:XX"。 | + +**返回值:** + +| 类型 | 说明 | +| -------- | -------- | +| [GattClientDevice](#gattclientdevice) | client端类,使用client端方法之前需要创建该类的实例进行操作。 | + +**示例:** + +```js +let device = bluetooth.BLE.createGattClientDevice('XX:XX:XX:XX:XX:XX'); +``` + + +### bluetooth.BLE.getConnectedBLEDevices + +getConnectedBLEDevices(): Array<string> + +获取和当前设备连接的BLE设备。 + +**需要权限**:ohos.permission.USE_BLUETOOTH + +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + +**返回值:** + +| 类型 | 说明 | +| -------- | -------- | +| Array<string> | 返回和当前设备连接BLE设备地址集合。 | + +**示例:** + +```js +let result = bluetooth.BLE.getConnectedBLEDevices(); +``` + + +### bluetooth.BLE.startBLEScan + +startBLEScan(filters: Array<ScanFilter>, options?: ScanOptions): void + +发起BLE扫描流程。 + +**需要权限**:ohos.permission.DISCOVER_BLUETOOTH;ohos.permission.MANAGE_BLUETOOTH; ohos.permission.LOCATION + +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | -------- | -------- | -------- | +| filters | Array<[ScanFilter](#scanfilter)> | 是 | 表示扫描结果过滤策略集合,如果不使用过滤的方式,该参数设置为null。 | +| options | [ScanOptions](#scanoptions) | 否 | 表示扫描的参数配置,可选参数。 | + +**返回值:** + +无 + +**示例:** + +```js +function onReceiveEvent(data) { + console.info('BLE scan device find result = '+ JSON.stringify(data)); +} +bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent); +bluetooth.BLE.startBLEScan( + [{ + deviceId:"XX:XX:XX:XX:XX:XX", + name:"test", + serviceUuid:"00001888-0000-1000-8000-00805f9b34fb" + }], + { + interval: 500, + dutyMode: bluetooth.ScanDuty.SCAN_MODE_LOW_POWER, + matchMode: bluetooth.MatchMode.MATCH_MODE_AGGRESSIVE, + } +); +``` + + +### bluetooth.BLE.stopBLEScan + +stopBLEScan(): void + +停止BLE扫描流程。 + +**需要权限**:ohos.permission.DISCOVER_BLUETOOTH + +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + +**返回值:** + +无 + +**示例:** + +```js +bluetooth.BLE.stopBLEScan(); +``` + + +### bluetooth.BLE.on('BLEDeviceFind') + +on(type: "BLEDeviceFind", callback: Callback<Array<ScanResult>>): void + +订阅BLE设备发现上报事件。 + +**需要权限**:ohos.permission.USE_BLUETOOTH + +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | -------- | -------- | -------- | +| type | string | 是 | 填写"BLEDeviceFind"字符串,表示BLE设备发现事件。 | +| callback | Callback<Array<[ScanResult](#scanresult)>> | 是 | 表示回调函数的入参,发现的设备集合。回调函数由用户创建通过该接口注册。 | + +**返回值:** + +无 + +**示例:** + +```js +function onReceiveEvent(data) { + console.info('bluetooth device find = '+ JSON.stringify(data)); +} +bluetooth.BLE.on('BLEDeviceFind', onReceiveEvent); +``` + + +### bluetooth.BLE.off('BLEDeviceFind') + +off(type: "BLEDeviceFind", callback?: Callback<Array<ScanResult>>): void + +取消订阅BLE设备发现上报事件。 + +**需要权限**:ohos.permission.USE_BLUETOOTH + +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | -------- | -------- | -------- | +| type | string | 是 | 填写"BLEDeviceFind"字符串,表示BLE设备发现事件。 | +| callback | Callback<Array<[ScanResult](#scanresult)>> | 否 | 表示取消订阅BLE设备发现事件上报。不填该参数则取消订阅该type对应的所有回调。 | + +**返回值:** + +无 + +**示例:** + +```js +function onReceiveEvent(data) { + console.info('bluetooth device find = '+ JSON.stringify(data)); +} +bluetooth.BLE.on('BLEDeviceFind', onReceiveEvent); +bluetooth.BLE.off('BLEDeviceFind', onReceiveEvent); +``` + + +## BaseProfile + +profile基类。 + + +### getConnectionDevices8+ + +getConnectionDevices(): Array<string> + +获取已连接设备列表。 + +**需要权限**:ohos.permission.USE_BLUETOOTH + +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + +**参数:** + +无 + +**返回值:** + +| | | +| -------- | -------- | +| 类型 | 说明 | +| Array<string> | 返回已连接设备的地址列表。 | + + +### getDeviceState8+ + +getDeviceState(device: string): ProfileConnectionState + +获取设备profile的连接状态。 + +**需要权限**:ohos.permission.USE_BLUETOOTH + +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | -------- | -------- | -------- | +| device | string | 是 | 远端设备地址。 | +| + +**返回值:** + +| | | +| -------- | -------- | +| 类型 | 说明 | +| [ProfileConnectionState](#profileconnectionState) | 返回profile的连接状态。 | + + +## A2dpSourceProfile + +使用A2dpSourceProfile方法之前需要创建该类的实例进行操作,通过getProfile()方法构造此实例。 + + +### connect8+ + +connect(device: string): boolean + +发起设备的A2dp服务连接请求。 + +**需要权限**:ohos.permission.DISCOVER_BLUETOOTH + +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | -------- | -------- | -------- | +| device | string | 是 | 远端设备地址。 | +| + +**返回值:** + +| | | +| -------- | -------- | +| 类型 | 说明 | +| boolean | 成功返回true,失败返回false。 | + +**示例:** + +```js +A2dpSourceProfile a2dpSrc = bluetooth.getProfile(PROFILE_A2DP_SOURCE); +boolean ret = a2dpSrc.connect('XX:XX:XX:XX:XX:XX'); +``` + + +### disconnect8+ + +disconnect(device: string): boolean + +断开设备的a2dp服务连接。 + +**需要权限**:ohos.permission.DISCOVER_BLUETOOTH + +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | -------- | -------- | -------- | +| device | string | 是 | 远端设备地址。 | +| + +**返回值:** + +| | | +| -------- | -------- | +| 类型 | 说明 | +| boolean | 成功返回true,失败返回false。 | + +**示例:** + +```js +A2dpSourceProfile a2dpSrc = bluetooth.getProfile(PROFILE_A2DP_SOURCE); +boolean ret = a2dpSrc.disconnect('XX:XX:XX:XX:XX:XX'); +``` + + +### A2dpSourceProfile.on('connectionStateChange')8+ + +on(type: "connectionStateChange", callback: Callback<[StateChangeParam](#StateChangeParam)>): void + +订阅a2dp连接状态变化事件。 + +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | -------- | -------- | -------- | +| type | string | 是 | 填写"connectionStateChange"字符串,表示连接状态变化事件。 | +| callback | Callback<[StateChangeParam](#StateChangeParam)> | 是 | 表示回调函数的入参。 | + +**返回值:** + +无 + +**示例:** + +```js +function onReceiveEvent(data) { + console.info('a2dp state = '+ JSON.stringify(data)); +} +A2dpSourceProfile.on('connectionStateChange', onReceiveEvent); +``` + + +### A2dpSourceProfile.off('connectionStateChange')8+ + +off(type: "connectionStateChange", callback: Callback<[StateChangeParam](#StateChangeParam)>): void + +取消订阅a2dp连接状态变化事件。 + +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | -------- | -------- | -------- | +| type | string | 是 | 填写"connectionStateChange"字符串,表示连接状态变化事件。 | +| callback | Callback<[StateChangeParam](#StateChangeParam)> | 是 | 表示回调函数的入参。 | + +**返回值:** + +无 + +**示例:** + +```js +function onReceiveEvent(data) { + console.info('a2dp state = '+ JSON.stringify(data)); +} +A2dpSourceProfile.off('connectionStateChange', onReceiveEvent); +``` + + +### getPlayingState -createGattClientDevice(deviceId: string): GattClientDevice +getPlayingState(device: string): PlayingState -创建一个可使用的GattClientDevice实例。 +获取设备的播放状态。 + +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | -------- | -------- | -------- | -| deviceId | string | 是 | 对端设备地址, 例如:"XX:XX:XX:XX:XX:XX"。 | +| device | string | 是 | 远端设备地址。 | **返回值:** -| 类型 | 说明 | +| | | | -------- | -------- | -| [GattClientDevice](#gattclientdevice) | client端类,使用client端方法之前需要创建该类的实例进行操作。 | +| 类型 | 说明 | +| [PlayingState](#PlayingState) | 远端设备的播放状态。 | **示例:** +```js +A2dpSourceProfile a2dpSrc = bluetooth.getProfile(PROFILE_A2DP_SOURCE); +PlayingState state = a2dpSrc.getPlayingState('XX:XX:XX:XX:XX:XX'); ``` -let device = bluetooth.BLE.createGattClientDevice('XX:XX:XX:XX:XX:XX'); -``` - - -### bluetooth.BLE.getConnectedBLEDevices - -getConnectedBLEDevices(): Array<string> -获取和当前设备连接的BLE设备。 -**返回值:** +## HandsFreeAudioGatewayProfile -| 类型 | 说明 | -| -------- | -------- | -| Array<string> | 返回和当前设备连接BLE设备地址集合。 | +使用HandsFreeAudioGatewayProfile方法之前需要创建该类的实例进行操作,通过getProfile()方法构造此实例。 -**示例:** -``` -let result = bluetooth.BLE.getConnectedBLEDevices(); -``` +### connect8+ +connect(device: string): boolean -### bluetooth.BLE.startBLEScan +连接设备的HFP服务。 -startBLEScan(filters: Array<ScanFilter>, options?: ScanOptions): void +**需要权限**:ohos.permission.DISCOVER_BLUETOOTH -发起BLE扫描流程。 +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | -------- | -------- | -------- | -| filters | Array<[ScanFilter](#scanfilter)> | 是 | 表示扫描结果过滤策略集合,如果不使用过滤的方式,该参数设置为null。 | -| options | [ScanOptions](#scanoptions) | 否 | 表示扫描的参数配置,可选参数。 | +| device | string | 是 | 远端设备地址。 | +| **返回值:** -无 +| | | +| -------- | -------- | +| 类型 | 说明 | +| boolean | 成功返回true,失败返回false。 | **示例:** -``` -function onReceiveEvent(data) { - console.info('BLE scan device find result = '+ JSON.stringify(data)); -} -bluetooth.BLE.on("BLEDeviceFind", onReceiveEvent); -bluetooth.BLE.startBLEScan( - [{ - deviceId:"XX:XX:XX:XX:XX:XX", - name:"test", - serviceUuid:"00001888-0000-1000-8000-00805f9b34fb" - }], - { - interval: 500, - dutyMode: bluetooth.ScanDuty.SCAN_MODE_LOW_POWER, - matchMode: bluetooth.MatchMode.MATCH_MODE_AGGRESSIVE, - } -); +```js +HandsFreeAudioGatewayProfile hfpAg = bluetooth.getProfile(PROFILE_HANDS_FREE_AUDIO_GATEWAY); +boolean ret = hfpAg.connect('XX:XX:XX:XX:XX:XX'); ``` -### bluetooth.BLE.stopBLEScan +### disconnect8+ -stopBLEScan(): void +disconnect(device: string): boolean -停止BLE扫描流程。 +连接设备的HFP服务。 + +**需要权限**:ohos.permission.DISCOVER_BLUETOOTH + +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | -------- | -------- | -------- | +| device | string | 是 | 远端设备地址。 | +| **返回值:** -无 +| | | +| -------- | -------- | +| 类型 | 说明 | +| boolean | 成功返回true,失败返回false。 | **示例:** -``` -bluetooth.BLE.stopBLEScan(); +```js +HandsFreeAudioGatewayProfile hfpAg = bluetooth.getProfile(PROFILE_HANDS_FREE_AUDIO_GATEWAY); +boolean ret = hfpAg.disconnect('XX:XX:XX:XX:XX:XX'); ``` -### bluetooth.BLE.on('BLEDeviceFind') +### HandsFreeAudioGatewayProfile.on('connectionStateChange')8+ -on(type: "BLEDeviceFind", callback: Callback<Array<ScanResult>>): void +on(type: "connectionStateChange", callback: Callback<[StateChangeParam](#StateChangeParam)>): void -订阅BLE设备发现上报事件。 +订阅HFP连接状态变化事件。 + +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | -------- | -------- | -------- | -| type | string | 是 | 填写"BLEDeviceFind"字符串,表示BLE设备发现事件。 | -| callback | Callback<Array<[ScanResult](#scanresult)>> | 是 | 表示回调函数的入参,发现的设备集合。回调函数由用户创建通过该接口注册。 | +| type | string | 是 | 填写"connectionStateChange"字符串,表示连接状态变化事件。 | +| callback | Callback<[StateChangeParam](#StateChangeParam)> | 是 | 表示回调函数的入参。 | **返回值:** @@ -966,26 +1496,28 @@ on(type: "BLEDeviceFind", callback: Callback<Array<ScanResult>>): vo **示例:** -``` +```js function onReceiveEvent(data) { - console.info('bluetooth device find = '+ JSON.stringify(data)); + console.info('hfp state = '+ JSON.stringify(data)); } -bluetooth.BLE.on('BLEDeviceFind', onReceiveEvent); +HandsFreeAudioGatewayProfile.on('connectionStateChange', onReceiveEvent); ``` -### bluetooth.BLE.off('BLEDeviceFind') +### HandsFreeAudioGatewayProfile.off('connectionStateChange')8+ -off(type: "BLEDeviceFind", callback?: Callback<Array<ScanResult>>): void +off(type: "connectionStateChange", callback: Callback<[StateChangeParam](#StateChangeParam)>): void -取消订阅BLE设备发现上报事件。 +取消订阅HFP连接状态变化事件。 + +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | -------- | -------- | -------- | -| type | string | 是 | 填写"BLEDeviceFind"字符串,表示BLE设备发现事件。 | -| callback | Callback<Array<[ScanResult](#scanresult)>> | 否 | 表示取消订阅BLE设备发现事件上报。不填该参数则取消订阅该type对应的所有回调。 | +| type | string | 是 | 填写"connectionStateChange"字符串,表示连接状态变化事件。 | +| callback | Callback<[StateChangeParam](#StateChangeParam)> | 是 | 表示回调函数的入参。 | **返回值:** @@ -993,12 +1525,11 @@ off(type: "BLEDeviceFind", callback?: Callback<Array<ScanResult>>): **示例:** -``` +```js function onReceiveEvent(data) { - console.info('bluetooth device find = '+ JSON.stringify(data)); + console.info('hfp state = '+ JSON.stringify(data)); } -bluetooth.BLE.on('BLEDeviceFind', onReceiveEvent); -bluetooth.BLE.off('BLEDeviceFind', onReceiveEvent); +HandsFreeAudioGatewayProfile.off('connectionStateChange', onReceiveEvent); ``` @@ -1013,6 +1544,10 @@ startAdvertising(setting: AdvertiseSetting, advData: AdvertiseData, advResponse? 开始发送BLE广播。 +**需要权限**:ohos.permission.DISCOVER_BLUETOOTH + +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + **参数:** | 参数名 | 类型 | 必填 | 说明 | @@ -1027,7 +1562,7 @@ startAdvertising(setting: AdvertiseSetting, advData: AdvertiseData, advResponse? **示例:** -``` +```js let manufactureValueBuffer = new Uint8Array(4); manufactureValueBuffer[0] = 1; manufactureValueBuffer[1] = 2; @@ -1076,13 +1611,17 @@ stopAdvertising(): void 停止发送BLE广播。 +**需要权限**:ohos.permission.DISCOVER_BLUETOOTH + +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + **返回值:** 无 **示例:** -``` +```js let server = bluetooth.BLE.createGattServer(); server.stopAdvertising(); ``` @@ -1094,6 +1633,10 @@ addService(service: GattService): boolean server端添加服务。 +**需要权限**:ohos.permission.USE_BLUETOOTH + +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + **参数:** | 参数名 | 类型 | 必填 | 说明 | @@ -1108,7 +1651,7 @@ server端添加服务。 **示例:** -``` +```js // 创建descriptors let descriptors = []; let arrayBuffer = new ArrayBuffer(8); @@ -1149,6 +1692,10 @@ removeService(serviceUuid: string): boolean 删除已添加的服务。 +**需要权限**:ohos.permission.USE_BLUETOOTH + +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + **参数:** | 参数名 | 类型 | 必填 | 说明 | @@ -1164,7 +1711,7 @@ removeService(serviceUuid: string): boolean **示例:** -``` +```js let server = bluetooth.BLE.createGattServer(); server.removeService('00001810-0000-1000-8000-00805F9B34FB'); ``` @@ -1176,9 +1723,13 @@ close(): void 关闭服务端功能,去注册server在协议栈的注册,调用该接口后[GattServer](#gattserver)实例将不能再使用。 +**需要权限**:ohos.permission.USE_BLUETOOTH + +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + **示例:** -``` +```js let server = bluetooth.BLE.createGattServer(); server.close(); ``` @@ -1190,6 +1741,10 @@ notifyCharacteristicChanged(deviceId: string, notifyCharacteristic: NotifyCharac server端特征值发生变化时,主动通知已连接的client设备。 +**需要权限**:ohos.permission.USE_BLUETOOTH + +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + **参数:** | 参数名 | 类型 | 必填 | 说明 | @@ -1206,7 +1761,7 @@ server端特征值发生变化时,主动通知已连接的client设备。 **示例:** -``` +```js let notifyCharacteristic = {serviceUuid: '00001810-0000-1000-8000-00805F9B34FB', characteristicUuid: '00001821-0000-1000-8000-00805F9B34FB', characteristicValue: notifyCcc.characteristicValue, confirm: false}; let server = bluetooth.BLE.createGattServer(); @@ -1220,6 +1775,10 @@ sendResponse(serverResponse: ServerResponse): boolean server端回复client端的读写请求。 +**需要权限**:ohos.permission.USE_BLUETOOTH + +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + **参数:** | 参数名 | 类型 | 必填 | 说明 | @@ -1235,7 +1794,7 @@ server端回复client端的读写请求。 **示例:** -``` +```js /* send response */ let arrayBufferCCC = new ArrayBuffer(8); let cccValue = new Uint8Array(arrayBufferCCC); @@ -1264,6 +1823,10 @@ on(type: "characteristicRead", callback: Callback<CharacteristicReadReq>): server端订阅特征值读请求事件。 +**需要权限**:ohos.permission.USE_BLUETOOTH + +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + **参数:** | 参数名 | 类型 | 必填 | 说明 | @@ -1277,7 +1840,7 @@ server端订阅特征值读请求事件。 **示例:** -``` +```js let arrayBufferCCC = new ArrayBuffer(8); let cccValue = new Uint8Array(arrayBufferCCC); cccValue[0] = 1123; @@ -1308,6 +1871,10 @@ off(type: "characteristicRead", callback?: Callback<CharacteristicReadReq> server端取消订阅特征值读请求事件。 +**需要权限**:ohos.permission.USE_BLUETOOTH + +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + **参数:** | 参数名 | 类型 | 必填 | 说明 | @@ -1321,7 +1888,7 @@ server端取消订阅特征值读请求事件。 **示例:** -``` +```js let gattServer = bluetooth.BLE.createGattServer(); gattServer.off("characteristicRead"); ``` @@ -1333,6 +1900,10 @@ on(type: "characteristicWrite", callback: Callback<CharacteristicWriteReq> server端订阅特征值写请求事件。 +**需要权限**:ohos.permission.USE_BLUETOOTH + +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + **参数:** | 参数名 | 类型 | 必填 | 说明 | @@ -1346,7 +1917,7 @@ server端订阅特征值写请求事件。 **示例:** -``` +```js let arrayBufferCCC = new ArrayBuffer(8); let cccValue = new Uint8Array(arrayBufferCCC); function WriteCharacteristicReq(CharacteristicWriteReq) { @@ -1380,6 +1951,10 @@ off(type: "characteristicWrite", callback?: Callback<CharacteristicWriteReq&g server端取消订阅特征值写请求事件。 +**需要权限**:ohos.permission.USE_BLUETOOTH + +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + **参数:** | 参数名 | 类型 | 必填 | 说明 | @@ -1393,7 +1968,7 @@ server端取消订阅特征值写请求事件。 **示例:** -``` +```js let gattServer = bluetooth.BLE.createGattServer(); gattServer.off("characteristicWrite"); ``` @@ -1405,6 +1980,10 @@ on(type: "descriptorRead", callback: Callback<DescriptorReadReq>): void server端订阅描述符读请求事件。 +**需要权限**:ohos.permission.USE_BLUETOOTH + +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + **参数:** | 参数名 | 类型 | 必填 | 说明 | @@ -1418,7 +1997,7 @@ server端订阅描述符读请求事件。 **示例:** -``` +```js let arrayBufferDesc = new ArrayBuffer(8); let descValue = new Uint8Array(arrayBufferDesc); descValue[0] = 1101; @@ -1449,6 +2028,10 @@ off(type: "descriptorRead", callback?: Callback<DescriptorReadReq>): void server端取消订阅描述符读请求事件。 +**需要权限**:ohos.permission.USE_BLUETOOTH + +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + **参数:** | 参数名 | 类型 | 必填 | 说明 | @@ -1462,7 +2045,7 @@ server端取消订阅描述符读请求事件。 **示例:** -``` +```js let gattServer = bluetooth.BLE.createGattServer(); gattServer.off("descriptorRead"); ``` @@ -1474,6 +2057,10 @@ on(type: "descriptorWrite", callback: Callback<DescriptorWriteReq>): void server端订阅描述符写请求事件。 +**需要权限**:ohos.permission.USE_BLUETOOTH + +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + **参数:** | 参数名 | 类型 | 必填 | 说明 | @@ -1487,7 +2074,7 @@ server端订阅描述符写请求事件。 **示例:** -``` +```js let arrayBufferDesc = new ArrayBuffer(8); let descValue = new Uint8Array(arrayBufferDesc); function WriteDescriptorReq(DescriptorWriteReq) { @@ -1521,6 +2108,10 @@ off(type: "descriptorWrite", callback?: Callback<DescriptorWriteReq>): voi server端取消订阅描述符写请求事件。 +**需要权限**:ohos.permission.USE_BLUETOOTH + +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + **参数:** | 参数名 | 类型 | 必填 | 说明 | @@ -1534,7 +2125,7 @@ server端取消订阅描述符写请求事件。 **示例:** -``` +```js let gattServer = bluetooth.BLE.createGattServer(); gattServer.off("descriptorWrite"); ``` @@ -1546,6 +2137,10 @@ on(type: "connectStateChange", callback: Callback<BLEConnectChangedState>) server端订阅BLE连接状态变化事件。 +**需要权限**:ohos.permission.USE_BLUETOOTH + +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + **参数:** | 参数名 | 类型 | 必填 | 说明 | @@ -1559,7 +2154,7 @@ server端订阅BLE连接状态变化事件。 **示例:** -``` +```js function Connected(BLEConnectChangedState) { let deviceId = BLEConnectChangedState.deviceId; let status = BLEConnectChangedState.state; @@ -1576,6 +2171,10 @@ off(type: "connectStateChange", callback?: Callback<BLEConnectChangedState> server端取消订阅BLE连接状态变化事件。 +**需要权限**:ohos.permission.USE_BLUETOOTH + +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + **参数:** | 参数名 | 类型 | 必填 | 说明 | @@ -1589,7 +2188,7 @@ server端取消订阅BLE连接状态变化事件。 **示例:** -``` +```js let gattServer = bluetooth.BLE.createGattServer(); gattServer.off("connectStateChange"); ``` @@ -1606,6 +2205,10 @@ connect(): boolean client端发起连接远端蓝牙低功耗设备。 +**需要权限**:ohos.permission.USE_BLUETOOTH + +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + **返回值:** | 类型 | 说明 | @@ -1614,7 +2217,7 @@ client端发起连接远端蓝牙低功耗设备。 **示例:** -``` +```js let device = bluetooth.BLE.createGattClientDevice('XX:XX:XX:XX:XX:XX'); let ret = device.connect(); ``` @@ -1626,6 +2229,10 @@ disconnect(): boolean client端断开与远端蓝牙低功耗设备的连接。 +**需要权限**:ohos.permission.USE_BLUETOOTH + +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + **返回值:** | 类型 | 说明 | @@ -1634,7 +2241,7 @@ client端断开与远端蓝牙低功耗设备的连接。 **示例:** -``` +```js let device = bluetooth.BLE.createGattClientDevice('XX:XX:XX:XX:XX:XX'); let ret = device.disconnect(); ``` @@ -1646,6 +2253,10 @@ close(): boolean 关闭客户端功能,注销client在协议栈的注册,调用该接口后[GattClientDevice](#gattclientdevice)实例将不能再使用。 +**需要权限**:ohos.permission.USE_BLUETOOTH + +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + **返回值:** | 类型 | 说明 | @@ -1654,7 +2265,7 @@ close(): boolean **示例:** -``` +```js let device = bluetooth.BLE.createGattClientDevice('XX:XX:XX:XX:XX:XX'); let ret = device.close(); ``` @@ -1668,6 +2279,10 @@ getServices(callback: AsyncCallback<Array<GattService>>): void client端获取蓝牙低功耗设备的所有服务,即服务发现 。 +**需要权限**:ohos.permission.USE_BLUETOOTH + +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + **参数:** | 参数名 | 类型 | 必填 | 说明 | @@ -1680,7 +2295,7 @@ client端获取蓝牙低功耗设备的所有服务,即服务发现 。 **示例:** -``` +```js // callkback 模式 function getServices(code, gattServices) { if (code.code == 0) { @@ -1706,6 +2321,10 @@ getServices(): Promise<Array<GattService>> client端获取蓝牙低功耗设备的所有服务,即服务发现。 +**需要权限**:ohos.permission.USE_BLUETOOTH + +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + **参数:** **返回值:** @@ -1716,7 +2335,7 @@ client端获取蓝牙低功耗设备的所有服务,即服务发现。 **示例:** -``` +```js // Promise 模式 let device = bluetooth.BLE.createGattClientDevice('XX:XX:XX:XX:XX:XX'); device.connect(); @@ -1735,6 +2354,10 @@ readCharacteristicValue(characteristic: BLECharacteristic, callback: AsyncCallba client端读取蓝牙低功耗设备特定服务的特征值。 +**需要权限**:ohos.permission.USE_BLUETOOTH + +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + **参数:** | 参数名 | 类型 | 必填 | 说明 | @@ -1748,7 +2371,7 @@ client端读取蓝牙低功耗设备特定服务的特征值。 **示例:** -``` +```js function readCcc(code, BLECharacteristic) { if (code.code != 0) { return; @@ -1785,6 +2408,10 @@ readCharacteristicValue(characteristic: BLECharacteristic): Promise<BLECharac client端读取蓝牙低功耗设备特定服务的特征值。 +**需要权限**:ohos.permission.USE_BLUETOOTH + +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + **参数:** | 参数名 | 类型 | 必填 | 说明 | @@ -1800,7 +2427,7 @@ client端读取蓝牙低功耗设备特定服务的特征值。 **示例:** -``` +```js let device = bluetooth.BLE.createGattClientDevice('XX:XX:XX:XX:XX:XX'); let descriptors = []; let bufferDesc = new ArrayBuffer(8); @@ -1828,6 +2455,10 @@ readDescriptorValue(descriptor: BLEDescriptor, callback: AsyncCallback<BLEDes client端读取蓝牙低功耗设备特定的特征包含的描述符。 +**需要权限**:ohos.permission.USE_BLUETOOTH + +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + **参数:** | 参数名 | 类型 | 必填 | 说明 | @@ -1841,7 +2472,7 @@ client端读取蓝牙低功耗设备特定的特征包含的描述符。 **示例:** -``` +```js function readDesc(code, BLEDescriptor) { if (code.code != 0) { return; @@ -1868,6 +2499,10 @@ readDescriptorValue(descriptor: BLEDescriptor): Promise<BLEDescriptor> client端读取蓝牙低功耗设备特定的特征包含的描述符。 +**需要权限**:ohos.permission.USE_BLUETOOTH + +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + **参数:** | 参数名 | 类型 | 必填 | 说明 | @@ -1883,7 +2518,7 @@ client端读取蓝牙低功耗设备特定的特征包含的描述符。 **示例:** -``` +```js let device = bluetooth.BLE.createGattClientDevice('XX:XX:XX:XX:XX:XX'); let bufferDesc = new ArrayBuffer(8); let descV = new Uint8Array(bufferDesc); @@ -1901,6 +2536,10 @@ writeCharacteristicValue(characteristic: BLECharacteristic): boolean client端向低功耗蓝牙设备写入特定的特征值。 +**需要权限**:ohos.permission.USE_BLUETOOTH + +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + **参数:** | 参数名 | 类型 | 必填 | 说明 | @@ -1915,7 +2554,7 @@ client端向低功耗蓝牙设备写入特定的特征值。 **示例:** -``` +```js let device = bluetooth.BLE.createGattClientDevice('XX:XX:XX:XX:XX:XX'); let descriptors = []; let bufferDesc = new ArrayBuffer(8); @@ -1947,6 +2586,10 @@ writeDescriptorValue(descriptor: BLEDescriptor): boolean client端向低功耗蓝牙设备特定的描述符写入二进制数据。 +**需要权限**:ohos.permission.USE_BLUETOOTH + +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + **参数:** | 参数名 | 类型 | 必填 | 说明 | @@ -1961,7 +2604,7 @@ client端向低功耗蓝牙设备特定的描述符写入二进制数据。 **示例:** -``` +```js let device = bluetooth.BLE.createGattClientDevice('XX:XX:XX:XX:XX:XX'); let bufferDesc = new ArrayBuffer(8); let descV = new Uint8Array(bufferDesc); @@ -1984,6 +2627,10 @@ setBLEMtuSize(mtu: number): boolean client协商远端蓝牙低功耗设备的最大传输单元(Maximum Transmission Unit, MTU),调用[connect](#connect)接口连接成功后才能使用。 +**需要权限**:ohos.permission.USE_BLUETOOTH + +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + **参数:** | 参数名 | 类型 | 必填 | 说明 | @@ -1998,7 +2645,7 @@ client协商远端蓝牙低功耗设备的最大传输单元(Maximum Transmiss **示例:** -``` +```js let device = bluetooth.BLE.createGattClientDevice('XX:XX:XX:XX:XX:XX'); device.setBLEMtuSize(128); ``` @@ -2010,6 +2657,10 @@ setNotifyCharacteristicChanged(characteristic: BLECharacteristic, enable: boolea 向服务端发送设置通知此特征值请求。 +**需要权限**:ohos.permission.USE_BLUETOOTH + +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + **参数:** | 参数名 | 类型 | 必填 | 说明 | @@ -2025,7 +2676,7 @@ setNotifyCharacteristicChanged(characteristic: BLECharacteristic, enable: boolea **示例:** -``` +```js let device = bluetooth.BLE.createGattClientDevice('XX:XX:XX:XX:XX:XX'); device.setNotifyCharacteristicChanged(notifyCcc, false); ``` @@ -2037,6 +2688,10 @@ on(type: "BLECharacteristicChange", callback: Callback<BLECharacteristic>) 订阅蓝牙低功耗设备的特征值变化事件。需要先调用setNotifyCharacteristicChanged接口才能接收server端的通知。 +**需要权限**:ohos.permission.USE_BLUETOOTH + +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + **参数:** | 参数名 | 类型 | 必填 | 说明 | @@ -2050,7 +2705,7 @@ on(type: "BLECharacteristicChange", callback: Callback<BLECharacteristic>) **示例:** -``` +```js function CharacteristicChange(CharacteristicChangeReq) { let serviceUuid = CharacteristicChangeReq.serviceUuid; let characteristicUuid = CharacteristicChangeReq.characteristicUuid; @@ -2067,6 +2722,10 @@ off(type: "BLECharacteristicChange", callback?: Callback<BLECharacteristic> 取消订阅蓝牙低功耗设备的特征值变化事件。 +**需要权限**:ohos.permission.USE_BLUETOOTH + +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + **参数:** | 参数名 | 类型 | 必填 | 说明 | @@ -2080,7 +2739,7 @@ off(type: "BLECharacteristicChange", callback?: Callback<BLECharacteristic> **示例:** -``` +```js let device = bluetooth.BLE.createGattClientDevice('XX:XX:XX:XX:XX:XX'); device.off('BLECharacteristicChange'); ``` @@ -2092,6 +2751,10 @@ on(type: "BLEConnectionStateChange", callback: Callback<BLEConnectChangedStat client端订阅蓝牙低功耗设备的连接状态变化事件。 +**需要权限**:ohos.permission.USE_BLUETOOTH + +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + **参数:** | 参数名 | 类型 | 必填 | 说明 | @@ -2105,7 +2768,7 @@ client端订阅蓝牙低功耗设备的连接状态变化事件。 **示例:** -``` +```js function ConnectStateChanged(state) { console.log('bluetooth connect state changed'); let connectState = state.state; @@ -2121,6 +2784,10 @@ off(type: "BLEConnectionStateChange", callback?: Callback<BLEConnectChangedSt 取消订阅蓝牙低功耗设备的连接状态变化事件。 +**需要权限**:ohos.permission.USE_BLUETOOTH + +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + **参数:** | 参数名 | 类型 | 必填 | 说明 | @@ -2134,7 +2801,7 @@ off(type: "BLEConnectionStateChange", callback?: Callback<BLEConnectChangedSt **示例:** -``` +```js let device = bluetooth.BLE.createGattClientDevice('XX:XX:XX:XX:XX:XX'); device.off('BLEConnectionStateChange'); ``` @@ -2146,6 +2813,10 @@ getDeviceName(callback: AsyncCallback<string>): void client获取远端蓝牙低功耗设备名。 +**需要权限**:ohos.permission.USE_BLUETOOTH + +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + **参数:** | 参数名 | 类型 | 必填 | 说明 | @@ -2158,7 +2829,7 @@ client获取远端蓝牙低功耗设备名。 **示例:** -``` +```js // callback let gattClient = bluetooth.BLE.createGattClientDevice("XX:XX:XX:XX:XX:XX"); let deviceName = gattClient.getDeviceName((err, data)=> { @@ -2174,6 +2845,10 @@ getDeviceName(): Promise<string> client获取远端蓝牙低功耗设备名。 +**需要权限**:ohos.permission.USE_BLUETOOTH + +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + **返回值:** | 类型 | 说明 | @@ -2182,7 +2857,7 @@ client获取远端蓝牙低功耗设备名。 **示例:** -``` +```js // promise let gattClient = bluetooth.BLE.createGattClientDevice("XX:XX:XX:XX:XX:XX"); let ret = device.connect(); @@ -2198,6 +2873,10 @@ getRssiValue(callback: AsyncCallback<number>): void client获取远端蓝牙低功耗设备的信号强度 (Received Signal Strength Indication, RSSI),调用[connect](#connect)接口连接成功后才能使用。 +**需要权限**:ohos.permission.USE_BLUETOOTH + +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + **参数:** | 参数名 | 类型 | 必填 | 说明 | @@ -2210,7 +2889,7 @@ client获取远端蓝牙低功耗设备的信号强度 (Received Signal Strength **示例:** -``` +```js // callback let gattClient = bluetooth.BLE.createGattClientDevice("XX:XX:XX:XX:XX:XX"); let ret = device.connect(); @@ -2227,6 +2906,10 @@ getRssiValue(): Promise<number> client获取远端蓝牙低功耗设备的信号强度 (Received Signal Strength Indication, RSSI),调用[connect](#connect)接口连接成功后才能使用。 +**需要权限**:ohos.permission.USE_BLUETOOTH + +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + **返回值:** | 类型 | 说明 | @@ -2235,7 +2918,7 @@ client获取远端蓝牙低功耗设备的信号强度 (Received Signal Strength **示例:** -``` +```js // promise let gattClient = bluetooth.BLE.createGattClientDevice("XX:XX:XX:XX:XX:XX"); let rssi = gattClient.getRssiValue().then((data) => { @@ -2243,11 +2926,12 @@ let rssi = gattClient.getRssiValue().then((data) => { }) ``` - -## ScanMode +## ScanMode8+ 枚举,扫描模式。 +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + | 名称 | 默认值 | 说明 | | -------- | -------- | -------- | | SCAN_MODE_NONE | 0 | 没有扫描模式。 | @@ -2257,11 +2941,12 @@ let rssi = gattClient.getRssiValue().then((data) => { | SCAN_MODE_CONNECTABLE_GENERAL_DISCOVERABLE | 4 | 可连接general发现模式。 | | SCAN_MODE_CONNECTABLE_LIMITED_DISCOVERABLE | 5 | 可连接limited发现模式。 | - -## BondState +## BondState8+ 枚举,配对状态。 +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + | 名称 | 默认值 | 说明 | | -------- | -------- | -------- | | BOND_STATE_INVALID | 0 | 无效的配对。 | @@ -2269,21 +2954,25 @@ let rssi = gattClient.getRssiValue().then((data) => { | BOND_STATE_BONDED | 2 | 已配对。 | -## SppOption +## SppOption8+ 描述spp的配置参数。 +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + | 名称 | 参数类型 | 可读 | 可写 | 说明 | | -------- | -------- | -------- | -------- | -------- | | uuid | string | 是 | 是 | spp单据的uuid。 | -| isPrimary | boolean | 是 | 是 | 是否是安全通道。 | +| secure | boolean | 是 | 是 | 是否是安全通道。 | | type | [SppType](#spptype) | 是 | 是 | Spp链路类型。 | -## SppType +## SppType8+ 枚举,Spp链路类型。 +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + | 名称 | 默认值 | 说明 | | -------- | -------- | -------- | | SPP_RFCOMM | 0 | 表示rfcomm链路类型。 | @@ -2293,6 +2982,8 @@ let rssi = gattClient.getRssiValue().then((data) => { 描述service的接口参数定义。 +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + | 名称 | 参数类型 | 可读 | 可写 | 说明 | | -------- | -------- | -------- | -------- | -------- | | serviceUuid | string | 是 | 是 | 特定服务(service)的UUID,例如:00001888-0000-1000-8000-00805f9b34fb。 | @@ -2305,6 +2996,8 @@ let rssi = gattClient.getRssiValue().then((data) => { 描述characteristic的接口参数定义 。 +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + | 名称 | 参数类型 | 可读 | 可写 | 说明 | | -------- | -------- | -------- | -------- | -------- | | serviceUuid | string | 是 | 是 | 特定服务(service)的UUID,例如:00001888-0000-1000-8000-00805f9b34fb。 | @@ -2317,6 +3010,8 @@ let rssi = gattClient.getRssiValue().then((data) => { 描述descriptor的接口参数定义 。 +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + | 名称 | 参数类型 | 可读 | 可写 | 说明 | | -------- | -------- | -------- | -------- | -------- | | serviceUuid | string | 是 | 是 | 特定服务(service)的UUID,例如:00001888-0000-1000-8000-00805f9b34fb。 | @@ -2329,6 +3024,8 @@ let rssi = gattClient.getRssiValue().then((data) => { 描述server端特征值变化时发送的特征通知参数定义。 +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + | 名称 | 参数类型 | 可读 | 可写 | 说明 | | -------- | -------- | -------- | -------- | -------- | | serviceUuid | string | 是 | 是 | 特定服务(service)的UUID,例如:00001888-0000-1000-8000-00805f9b34fb。 | @@ -2341,6 +3038,8 @@ let rssi = gattClient.getRssiValue().then((data) => { 描述server端订阅后收到的特征值读请求事件参数结构。 +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + | 名称 | 参数类型 | 可读 | 可写 | 说明 | | -------- | -------- | -------- | -------- | -------- | | deviceId | string | 是 | 否 | 表示发送特征值读请求的远端设备地址,例如:"XX:XX:XX:XX:XX:XX"。 | @@ -2354,6 +3053,8 @@ let rssi = gattClient.getRssiValue().then((data) => { 描述server端订阅后收到的特征值写请求事件参数结构。 +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + | 名称 | 参数类型 | 可读 | 可写 | 说明 | | -------- | -------- | -------- | -------- | -------- | | deviceId | string | 是 | 否 | 表示发送特征值写请求的远端设备地址,例如:"XX:XX:XX:XX:XX:XX"。 | @@ -2368,6 +3069,8 @@ let rssi = gattClient.getRssiValue().then((data) => { 描述server端订阅后收到的描述符读请求事件参数结构。 +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + | 名称 | 参数类型 | 可读 | 可写 | 说明 | | -------- | -------- | -------- | -------- | -------- | | deviceId | string | 是 | 否 | 表示发送描述符读请求的远端设备地址,例如:"XX:XX:XX:XX:XX:XX"。 | @@ -2382,6 +3085,8 @@ let rssi = gattClient.getRssiValue().then((data) => { 描述server端订阅后收到的描述符写请求事件参数结构。 +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + | 名称 | 参数类型 | 可读 | 可写 | 说明 | | -------- | -------- | -------- | -------- | -------- | | deviceId | string | 是 | 否 | 表示发送描述符写请求的远端设备地址,例如:"XX:XX:XX:XX:XX:XX"。 | @@ -2399,6 +3104,8 @@ let rssi = gattClient.getRssiValue().then((data) => { 描述server端回复client端读/写请求的响应参数结构。 +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + | 名称 | 参数类型 | 可读 | 可写 | 说明 | | -------- | -------- | -------- | -------- | -------- | | deviceId | string | 是 | 否 | 表示远端设备地址,例如:"XX:XX:XX:XX:XX:XX"。 | @@ -2412,6 +3119,8 @@ let rssi = gattClient.getRssiValue().then((data) => { 描述Gatt profile连接状态 。 +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + | 名称 | 参数类型 | 可读 | 可写 | 说明 | | -------- | -------- | -------- | -------- | -------- | | deviceId | string | 是 | 否 | 表示远端设备地址,例如:"XX:XX:XX:XX:XX:XX"。 | @@ -2422,6 +3131,8 @@ let rssi = gattClient.getRssiValue().then((data) => { 枚举,蓝牙设备的profile连接状态。 +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + | 名称 | 默认值 | 说明 | | -------- | -------- | -------- | | STATE_DISCONNECTED | 0 | 表示profile已断连。 | @@ -2434,6 +3145,8 @@ let rssi = gattClient.getRssiValue().then((data) => { 扫描过滤参数。 +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + | 名称 | 参数类型 | 可读 | 可写 | 说明 | | -------- | -------- | -------- | -------- | -------- | | deviceId | string | 是 | 是 | 表示过滤的BLE设备地址,例如:"XX:XX:XX:XX:XX:XX"。 | @@ -2445,6 +3158,8 @@ let rssi = gattClient.getRssiValue().then((data) => { 扫描的配置参数。 +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + | 名称 | 参数类型 | 可读 | 可写 | 说明 | | -------- | -------- | -------- | -------- | -------- | | interval | number | 是 | 是 | 表示扫描结果上报延迟时间,默认值为0。 | @@ -2456,6 +3171,8 @@ let rssi = gattClient.getRssiValue().then((data) => { 枚举,扫描模式。 +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + | 名称 | 默认值 | 说明 | | -------- | -------- | -------- | | SCAN_MODE_LOW_POWER | 0 | 表示低功耗模式,默认值。 | @@ -2467,16 +3184,20 @@ let rssi = gattClient.getRssiValue().then((data) => { 枚举,硬件过滤匹配模式。 +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + | 名称 | 默认值 | 说明 | | -------- | -------- | -------- | | MATCH_MODE_AGGRESSIVE | 1 | 表示硬件上报扫描结果门限较低,比如扫描到的功率较低或者一段时间扫描到的次数较少也触发上报,默认值。 | -| SCAN_MODE_LOW_LATENCY | 2 | 表示硬件上报扫描结果门限较高,更高的功率门限以及扫描到多次才会上报。 | +| MATCH_MODE_STICKY | 2 | 表示硬件上报扫描结果门限较高,更高的功率门限以及扫描到多次才会上报。 | ## ScanResult 扫描结果上报数据。 +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + | 名称 | 参数类型 | 可读 | 可写 | 说明 | | -------- | -------- | -------- | -------- | -------- | | deviceId | string | 是 | 否 | 表示扫描到的设备地址,例如:"XX:XX:XX:XX:XX:XX"。 | @@ -2488,6 +3209,8 @@ let rssi = gattClient.getRssiValue().then((data) => { 枚举,蓝牙开关状态。 +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + | 名称 | 默认值 | 说明 | | -------- | -------- | -------- | | STATE_OFF | 0 | 表示蓝牙已关闭。 | @@ -2503,6 +3226,8 @@ let rssi = gattClient.getRssiValue().then((data) => { 描述蓝牙低功耗设备发送广播的参数。 +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + | 名称 | 参数类型 | 可读 | 可写 | 说明 | | -------- | -------- | -------- | -------- | -------- | | interval | number | 是 | 是 | 表示广播间隔,最小值设置32个slot表示20ms,最大值设置16777215个slot,默认值设置为1600个slot表示1s。 | @@ -2514,6 +3239,8 @@ let rssi = gattClient.getRssiValue().then((data) => { 描述BLE广播数据包的内容。 +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + | 名称 | 参数类型 | 可读 | 可写 | 说明 | | -------- | -------- | -------- | -------- | -------- | | serviceUuids | Array<string> | 是 | 是 | 表示要广播的服务 UUID 列表。 | @@ -2525,6 +3252,8 @@ let rssi = gattClient.getRssiValue().then((data) => { 描述BLE广播数据包的内容。 +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + | 名称 | 参数类型 | 可读 | 可写 | 说明 | | -------- | -------- | -------- | -------- | -------- | | manufactureId | Array<string> | 是 | 是 | 表示制造商的ID,由蓝牙SIG分配。 | @@ -2535,26 +3264,44 @@ let rssi = gattClient.getRssiValue().then((data) => { 描述广播包中服务数据内容。 +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + | 名称 | 参数类型 | 可读 | 可写 | 说明 | | -------- | -------- | -------- | -------- | -------- | | serviceUuid | string | 是 | 是 | 表示服务的UUID。 | | serviceValue | ArrayBuffer | 是 | 是 | 表示服务数据。 | -## PinRequiredParam +## PinRequiredParam8+ 描述配对请求参数。 +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + | 名称 | 参数类型 | 可读 | 可写 | 说明 | | -------- | -------- | -------- | -------- | -------- | | deviceId | string | 是 | 否 | 表示要配对的设备ID。 | | pinCode | string | 是 | 否 | 表示要配对的密钥。 | -## DeviceClass +## StateChangeParam8+ + +描述profile状态改变参数。 + +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + +| 名称 | 参数类型 | 可读 | 可写 | 说明 | +| -------- | -------- | -------- | -------- | -------- | +| deviceId | string | 是 | 否 | 表示蓝牙设备地址。 | +| state | [ProfileConnectionState](#ProfileConnectionState) | 是 | 否 | 表示蓝牙设备的profile连接状态。 | + + +## DeviceClass8+ 描述蓝牙设备的类别。 +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + | 名称 | 参数类型 | 可读 | 可写 | 说明 | | -------- | -------- | -------- | -------- | -------- | | majorClass | [MajorClass](#majorclass) | 是 | 否 | 表示蓝牙设备主要类别的枚举。 | @@ -2562,10 +3309,13 @@ let rssi = gattClient.getRssiValue().then((data) => { | classOfDevice | number | 是 | 否 | 表示设备类别。 | -## MajorClass + +## MajorClass8+ 枚举,蓝牙设备主要类别。 +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + | 名称 | 默认值 | 说明 | | -------- | -------- | -------- | | MAJOR_MISC | 0x0000 | 表示杂项设备。 | @@ -2581,10 +3331,12 @@ let rssi = gattClient.getRssiValue().then((data) => { | MAJOR_UNCATEGORIZED | 0x1F00 | 表示未分类设备。 | -## MajorMinorClass +## MajorMinorClass8+ 枚举,主要次要蓝牙设备类别。 +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + | 名称 | 默认值 | 说明 | | -------- | -------- | -------- | | COMPUTER_UNCATEGORIZED | 0x0100 | 表示未分类计算机设备。 | @@ -2673,3 +3425,27 @@ let rssi = gattClient.getRssiValue().then((data) => { | HEALTH_ANKLE_PROSTHESIS | 0x0934 | 表示脚踝假肢健康设备。 | | HEALTH_GENERIC_HEALTH_MANAGER | 0x0938 | 表示通用健康管理设备。 | | HEALTH_PERSONAL_MOBILITY_DEVICE | 0x093C | 表示个人移动健康设备。 | + + +## PlayingState8+ + +枚举,蓝牙A2DP 播放状态。 + +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + +| 名称 | 默认值 | 说明 | +| -------- | -------- | -------- | +| STATE_NOT_PLAYING | 0x0000 | 表示未播放。 | +| STATE_PLAYING | 0x0001 | 表示正在播放。 | + + +## ProfileId8+ + +枚举,蓝牙profile id。 + +**系统能力**:SystemCapability.Communication.Bluetooth.Core。 + +| 名称 | 默认值 | 说明 | +| -------- | -------- | -------- | +| PROFILE_A2DP_SOURCE | 0x0001 | 表示A2DP profile。 | +| PROFILE_HANDS_FREE_AUDIO_GATEWAY | 0x0004 | 表示HFP profile。 | \ No newline at end of file -- GitLab