1e41f4b71Sopenharmony_ci# @ohos.bluetooth.a2dp (蓝牙a2dp模块)(系统接口) 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_cia2dp模块提供了访问蓝牙音频接口的方法。 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ci> **说明:** 6e41f4b71Sopenharmony_ci> 7e41f4b71Sopenharmony_ci> 本模块首批接口从API version 10开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 8e41f4b71Sopenharmony_ci> 当前页面仅包含本模块的系统接口,其他公开接口参见[@ohos.bluetooth.a2dp (蓝牙a2dp模块)](js-apis-bluetooth-a2dp.md) 9e41f4b71Sopenharmony_ci 10e41f4b71Sopenharmony_ci 11e41f4b71Sopenharmony_ci## 导入模块 12e41f4b71Sopenharmony_ci 13e41f4b71Sopenharmony_ci```js 14e41f4b71Sopenharmony_ciimport { a2dp } from '@kit.ConnectivityKit'; 15e41f4b71Sopenharmony_ci``` 16e41f4b71Sopenharmony_ci 17e41f4b71Sopenharmony_ci 18e41f4b71Sopenharmony_ci### connect 19e41f4b71Sopenharmony_ci 20e41f4b71Sopenharmony_ciconnect(deviceId: string): void 21e41f4b71Sopenharmony_ci 22e41f4b71Sopenharmony_ci发起设备的A2dp服务连接请求。 23e41f4b71Sopenharmony_ci 24e41f4b71Sopenharmony_ci**系统接口**:此接口为系统接口。 25e41f4b71Sopenharmony_ci 26e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.ACCESS_BLUETOOTH 27e41f4b71Sopenharmony_ci 28e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Communication.Bluetooth.Core。 29e41f4b71Sopenharmony_ci 30e41f4b71Sopenharmony_ci**参数:** 31e41f4b71Sopenharmony_ci 32e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 33e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ------- | 34e41f4b71Sopenharmony_ci| deviceId | string | 是 | 远端设备地址。 | 35e41f4b71Sopenharmony_ci 36e41f4b71Sopenharmony_ci**错误码**: 37e41f4b71Sopenharmony_ci 38e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。 39e41f4b71Sopenharmony_ci 40e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 41e41f4b71Sopenharmony_ci| -------- | ---------------------------- | 42e41f4b71Sopenharmony_ci|201 | Permission denied. | 43e41f4b71Sopenharmony_ci|202 | Non-system applications are not allowed to use system APIs. | 44e41f4b71Sopenharmony_ci|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. | 45e41f4b71Sopenharmony_ci|801 | Capability not supported. | 46e41f4b71Sopenharmony_ci|2900001 | Service stopped. | 47e41f4b71Sopenharmony_ci|2900003 | Bluetooth disabled. | 48e41f4b71Sopenharmony_ci|2900004 | Profile not supported. | 49e41f4b71Sopenharmony_ci|2900099 | Operation failed. | 50e41f4b71Sopenharmony_ci 51e41f4b71Sopenharmony_ci**示例:** 52e41f4b71Sopenharmony_ci 53e41f4b71Sopenharmony_ci```js 54e41f4b71Sopenharmony_ciimport { AsyncCallback, BusinessError } from '@kit.BasicServicesKit'; 55e41f4b71Sopenharmony_citry { 56e41f4b71Sopenharmony_ci let a2dpSrc = a2dp.createA2dpSrcProfile(); 57e41f4b71Sopenharmony_ci a2dpSrc.connect('XX:XX:XX:XX:XX:XX'); 58e41f4b71Sopenharmony_ci} catch (err) { 59e41f4b71Sopenharmony_ci console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message); 60e41f4b71Sopenharmony_ci} 61e41f4b71Sopenharmony_ci``` 62e41f4b71Sopenharmony_ci 63e41f4b71Sopenharmony_ci 64e41f4b71Sopenharmony_ci### disconnect 65e41f4b71Sopenharmony_ci 66e41f4b71Sopenharmony_cidisconnect(deviceId: string): void 67e41f4b71Sopenharmony_ci 68e41f4b71Sopenharmony_ci断开设备的a2dp服务连接。 69e41f4b71Sopenharmony_ci 70e41f4b71Sopenharmony_ci**系统接口**:此接口为系统接口。 71e41f4b71Sopenharmony_ci 72e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.ACCESS_BLUETOOTH 73e41f4b71Sopenharmony_ci 74e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Communication.Bluetooth.Core。 75e41f4b71Sopenharmony_ci 76e41f4b71Sopenharmony_ci**参数:** 77e41f4b71Sopenharmony_ci 78e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 79e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ------- | 80e41f4b71Sopenharmony_ci| deviceId | string | 是 | 远端设备地址。 | 81e41f4b71Sopenharmony_ci 82e41f4b71Sopenharmony_ci**错误码**: 83e41f4b71Sopenharmony_ci 84e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。 85e41f4b71Sopenharmony_ci 86e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 87e41f4b71Sopenharmony_ci| -------- | ---------------------------- | 88e41f4b71Sopenharmony_ci|201 | Permission denied. | 89e41f4b71Sopenharmony_ci|202 | Non-system applications are not allowed to use system APIs. | 90e41f4b71Sopenharmony_ci|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. | 91e41f4b71Sopenharmony_ci|801 | Capability not supported. | 92e41f4b71Sopenharmony_ci|2900001 | Service stopped. | 93e41f4b71Sopenharmony_ci|2900003 | Bluetooth disabled. | 94e41f4b71Sopenharmony_ci|2900004 | Profile not supported. | 95e41f4b71Sopenharmony_ci|2900099 | Operation failed. | 96e41f4b71Sopenharmony_ci 97e41f4b71Sopenharmony_ci**示例:** 98e41f4b71Sopenharmony_ci 99e41f4b71Sopenharmony_ci```js 100e41f4b71Sopenharmony_ciimport { AsyncCallback, BusinessError } from '@kit.BasicServicesKit'; 101e41f4b71Sopenharmony_citry { 102e41f4b71Sopenharmony_ci let a2dpSrc = a2dp.createA2dpSrcProfile(); 103e41f4b71Sopenharmony_ci a2dpSrc.disconnect('XX:XX:XX:XX:XX:XX'); 104e41f4b71Sopenharmony_ci} catch (err) { 105e41f4b71Sopenharmony_ci console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message); 106e41f4b71Sopenharmony_ci} 107e41f4b71Sopenharmony_ci``` 108e41f4b71Sopenharmony_ci 109e41f4b71Sopenharmony_ci 110e41f4b71Sopenharmony_ci### isAbsoluteVolumeSupported<sup>11+</sup> 111e41f4b71Sopenharmony_ci 112e41f4b71Sopenharmony_ciisAbsoluteVolumeSupported(deviceId: string, callback: AsyncCallback<boolean>): void 113e41f4b71Sopenharmony_ci 114e41f4b71Sopenharmony_ci获取设备是否支持绝对音量能力。使用Callback异步回调。 115e41f4b71Sopenharmony_ci 116e41f4b71Sopenharmony_ci**系统接口**:此接口为系统接口。 117e41f4b71Sopenharmony_ci 118e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.ACCESS_BLUETOOTH 119e41f4b71Sopenharmony_ci 120e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Communication.Bluetooth.Core。 121e41f4b71Sopenharmony_ci 122e41f4b71Sopenharmony_ci**参数:** 123e41f4b71Sopenharmony_ci 124e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 125e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ------- | 126e41f4b71Sopenharmony_ci| deviceId | string | 是 | 远端设备地址。 | 127e41f4b71Sopenharmony_ci| callback | AsyncCallback<boolean> | 是 | 通过注册回调函数获取设备是否支持绝对音量。如果成功,值在supported中返回。 | 128e41f4b71Sopenharmony_ci 129e41f4b71Sopenharmony_ci 130e41f4b71Sopenharmony_ci**错误码**: 131e41f4b71Sopenharmony_ci 132e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。 133e41f4b71Sopenharmony_ci 134e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 135e41f4b71Sopenharmony_ci| -------- | ---------------------------- | 136e41f4b71Sopenharmony_ci|201 | Permission denied. | 137e41f4b71Sopenharmony_ci|202 | Non-system applications are not allowed to use system APIs. | 138e41f4b71Sopenharmony_ci|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. | 139e41f4b71Sopenharmony_ci|801 | Capability not supported. | 140e41f4b71Sopenharmony_ci|2900001 | Service stopped. | 141e41f4b71Sopenharmony_ci|2900003 | Bluetooth disabled. | 142e41f4b71Sopenharmony_ci|2900099 | Operation failed. | 143e41f4b71Sopenharmony_ci 144e41f4b71Sopenharmony_ci**示例:** 145e41f4b71Sopenharmony_ci 146e41f4b71Sopenharmony_ci```js 147e41f4b71Sopenharmony_ciimport { AsyncCallback, BusinessError } from '@kit.BasicServicesKit'; 148e41f4b71Sopenharmony_citry { 149e41f4b71Sopenharmony_ci let a2dpSrc = a2dp.createA2dpSrcProfile(); 150e41f4b71Sopenharmony_ci a2dpSrc.isAbsoluteVolumeSupported('XX:XX:XX:XX:XX:XX', (err, supported) => { 151e41f4b71Sopenharmony_ci console.info('device support absolute volume ' + supported); 152e41f4b71Sopenharmony_ci }); 153e41f4b71Sopenharmony_ci} catch (err) { 154e41f4b71Sopenharmony_ci console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message); 155e41f4b71Sopenharmony_ci} 156e41f4b71Sopenharmony_ci``` 157e41f4b71Sopenharmony_ci 158e41f4b71Sopenharmony_ci### isAbsoluteVolumeSupported<sup>11+</sup> 159e41f4b71Sopenharmony_ci 160e41f4b71Sopenharmony_ciisAbsoluteVolumeSupported(deviceId: string): Promise<boolean> 161e41f4b71Sopenharmony_ci 162e41f4b71Sopenharmony_ci获取设备是否支持绝对音量能力。使用Promise异步回调。 163e41f4b71Sopenharmony_ci 164e41f4b71Sopenharmony_ci**系统接口**:此接口为系统接口。 165e41f4b71Sopenharmony_ci 166e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.ACCESS_BLUETOOTH 167e41f4b71Sopenharmony_ci 168e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Communication.Bluetooth.Core。 169e41f4b71Sopenharmony_ci 170e41f4b71Sopenharmony_ci**参数:** 171e41f4b71Sopenharmony_ci 172e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 173e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ------- | 174e41f4b71Sopenharmony_ci| deviceId | string | 是 | 远端设备地址。 | 175e41f4b71Sopenharmony_ci 176e41f4b71Sopenharmony_ci**返回值:** 177e41f4b71Sopenharmony_ci 178e41f4b71Sopenharmony_ci| 类型 | 说明 | 179e41f4b71Sopenharmony_ci| ----------------------------- | ---------- | 180e41f4b71Sopenharmony_ci| Promise<boolean> | 通过promise形式获取设备是否支持绝对音量。如果成功,值在supported中返回。 | 181e41f4b71Sopenharmony_ci 182e41f4b71Sopenharmony_ci**错误码**: 183e41f4b71Sopenharmony_ci 184e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。 185e41f4b71Sopenharmony_ci 186e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 187e41f4b71Sopenharmony_ci| -------- | ---------------------------- | 188e41f4b71Sopenharmony_ci|201 | Permission denied. | 189e41f4b71Sopenharmony_ci|202 | Non-system applications are not allowed to use system APIs. | 190e41f4b71Sopenharmony_ci|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. | 191e41f4b71Sopenharmony_ci|801 | Capability not supported. | 192e41f4b71Sopenharmony_ci|2900001 | Service stopped. | 193e41f4b71Sopenharmony_ci|2900003 | Bluetooth disabled. | 194e41f4b71Sopenharmony_ci|2900099 | Operation failed. | 195e41f4b71Sopenharmony_ci 196e41f4b71Sopenharmony_ci**示例:** 197e41f4b71Sopenharmony_ci 198e41f4b71Sopenharmony_ci```js 199e41f4b71Sopenharmony_ciimport { AsyncCallback, BusinessError } from '@kit.BasicServicesKit'; 200e41f4b71Sopenharmony_citry { 201e41f4b71Sopenharmony_ci let a2dpSrc = a2dp.createA2dpSrcProfile(); 202e41f4b71Sopenharmony_ci a2dpSrc.isAbsoluteVolumeSupported('XX:XX:XX:XX:XX:XX').then((supported) => { 203e41f4b71Sopenharmony_ci console.info('device support absolute volume ' + supported); 204e41f4b71Sopenharmony_ci }); 205e41f4b71Sopenharmony_ci} catch (err) { 206e41f4b71Sopenharmony_ci console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message); 207e41f4b71Sopenharmony_ci} 208e41f4b71Sopenharmony_ci``` 209e41f4b71Sopenharmony_ci 210e41f4b71Sopenharmony_ci### isAbsoluteVolumeEnabled<sup>11+</sup> 211e41f4b71Sopenharmony_ci 212e41f4b71Sopenharmony_ciisAbsoluteVolumeEnabled(deviceId: string, callback: AsyncCallback<boolean>): void 213e41f4b71Sopenharmony_ci 214e41f4b71Sopenharmony_ci获取设备绝对音量能力是否开启。需要在设备支持绝对音量的情况下(参考[isAbsoluteVolumeSupported](#isabsolutevolumesupported11)),再获取设备绝对音量能力是否开启。使用Callback异步回调。 215e41f4b71Sopenharmony_ci 216e41f4b71Sopenharmony_ci**系统接口**:此接口为系统接口。 217e41f4b71Sopenharmony_ci 218e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.ACCESS_BLUETOOTH 219e41f4b71Sopenharmony_ci 220e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Communication.Bluetooth.Core。 221e41f4b71Sopenharmony_ci 222e41f4b71Sopenharmony_ci**参数:** 223e41f4b71Sopenharmony_ci 224e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 225e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ------- | 226e41f4b71Sopenharmony_ci| deviceId | string | 是 | 远端设备地址。 | 227e41f4b71Sopenharmony_ci| callback | AsyncCallback<boolean> | 是 | 通过注册回调函数获取设备绝对音量是否开启。如果成功,值在enabled中返回。 | 228e41f4b71Sopenharmony_ci 229e41f4b71Sopenharmony_ci 230e41f4b71Sopenharmony_ci**错误码**: 231e41f4b71Sopenharmony_ci 232e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。 233e41f4b71Sopenharmony_ci 234e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 235e41f4b71Sopenharmony_ci| -------- | ---------------------------- | 236e41f4b71Sopenharmony_ci|201 | Permission denied. | 237e41f4b71Sopenharmony_ci|202 | Non-system applications are not allowed to use system APIs. | 238e41f4b71Sopenharmony_ci|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. | 239e41f4b71Sopenharmony_ci|801 | Capability not supported. | 240e41f4b71Sopenharmony_ci|2900001 | Service stopped. | 241e41f4b71Sopenharmony_ci|2900003 | Bluetooth disabled. | 242e41f4b71Sopenharmony_ci|2900099 | Operation failed. | 243e41f4b71Sopenharmony_ci 244e41f4b71Sopenharmony_ci**示例:** 245e41f4b71Sopenharmony_ci 246e41f4b71Sopenharmony_ci```js 247e41f4b71Sopenharmony_ciimport { AsyncCallback, BusinessError } from '@kit.BasicServicesKit'; 248e41f4b71Sopenharmony_citry { 249e41f4b71Sopenharmony_ci let a2dpSrc = a2dp.createA2dpSrcProfile(); 250e41f4b71Sopenharmony_ci a2dpSrc.isAbsoluteVolumeEnabled('XX:XX:XX:XX:XX:XX', (err, enabled) => { 251e41f4b71Sopenharmony_ci console.info('device absolute volume enable ' + enabled); 252e41f4b71Sopenharmony_ci }); 253e41f4b71Sopenharmony_ci} catch (err) { 254e41f4b71Sopenharmony_ci console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message); 255e41f4b71Sopenharmony_ci} 256e41f4b71Sopenharmony_ci``` 257e41f4b71Sopenharmony_ci 258e41f4b71Sopenharmony_ci### isAbsoluteVolumeEnabled<sup>11+</sup> 259e41f4b71Sopenharmony_ci 260e41f4b71Sopenharmony_ciisAbsoluteVolumeEnabled(deviceId: string): Promise<boolean> 261e41f4b71Sopenharmony_ci 262e41f4b71Sopenharmony_ci获取设备绝对音量能力是否开启。需要在设备支持绝对音量的情况下(参考[isAbsoluteVolumeSupported](#isabsolutevolumesupported11)),再获取设备绝对音量能力是否开启。使用Promise异步回调。 263e41f4b71Sopenharmony_ci 264e41f4b71Sopenharmony_ci**系统接口**:此接口为系统接口。 265e41f4b71Sopenharmony_ci 266e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.ACCESS_BLUETOOTH 267e41f4b71Sopenharmony_ci 268e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Communication.Bluetooth.Core。 269e41f4b71Sopenharmony_ci 270e41f4b71Sopenharmony_ci**参数:** 271e41f4b71Sopenharmony_ci 272e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 273e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ------- | 274e41f4b71Sopenharmony_ci| deviceId | string | 是 | 远端设备地址。 | 275e41f4b71Sopenharmony_ci 276e41f4b71Sopenharmony_ci**返回值:** 277e41f4b71Sopenharmony_ci 278e41f4b71Sopenharmony_ci| 类型 | 说明 | 279e41f4b71Sopenharmony_ci| ----------------------------- | ---------- | 280e41f4b71Sopenharmony_ci| Promise<boolean> | 通过promise形式获取设备绝对音量是否开启。如果成功,值在enabled中返回。 | 281e41f4b71Sopenharmony_ci 282e41f4b71Sopenharmony_ci**错误码**: 283e41f4b71Sopenharmony_ci 284e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。 285e41f4b71Sopenharmony_ci 286e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 287e41f4b71Sopenharmony_ci| -------- | ---------------------------- | 288e41f4b71Sopenharmony_ci|201 | Permission denied. | 289e41f4b71Sopenharmony_ci|202 | Non-system applications are not allowed to use system APIs. | 290e41f4b71Sopenharmony_ci|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. | 291e41f4b71Sopenharmony_ci|801 | Capability not supported. | 292e41f4b71Sopenharmony_ci|2900001 | Service stopped. | 293e41f4b71Sopenharmony_ci|2900003 | Bluetooth disabled. | 294e41f4b71Sopenharmony_ci|2900099 | Operation failed. | 295e41f4b71Sopenharmony_ci 296e41f4b71Sopenharmony_ci**示例:** 297e41f4b71Sopenharmony_ci 298e41f4b71Sopenharmony_ci```js 299e41f4b71Sopenharmony_ciimport { AsyncCallback, BusinessError } from '@kit.BasicServicesKit'; 300e41f4b71Sopenharmony_citry { 301e41f4b71Sopenharmony_ci let a2dpSrc = a2dp.createA2dpSrcProfile(); 302e41f4b71Sopenharmony_ci a2dpSrc.isAbsoluteVolumeEnabled('XX:XX:XX:XX:XX:XX').then((enabled) => { 303e41f4b71Sopenharmony_ci console.info('device absolute volume enable ' + enabled); 304e41f4b71Sopenharmony_ci }); 305e41f4b71Sopenharmony_ci} catch (err) { 306e41f4b71Sopenharmony_ci console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message); 307e41f4b71Sopenharmony_ci} 308e41f4b71Sopenharmony_ci``` 309e41f4b71Sopenharmony_ci 310e41f4b71Sopenharmony_ci### enableAbsoluteVolume<sup>11+</sup> 311e41f4b71Sopenharmony_ci 312e41f4b71Sopenharmony_cienableAbsoluteVolume(deviceId: string, callback: AsyncCallback<void>): void 313e41f4b71Sopenharmony_ci 314e41f4b71Sopenharmony_ci开启设备绝对音量能力。需要在设备支持绝对音量的情况下(参考[isAbsoluteVolumeSupported](#isabsolutevolumesupported11)),再开启设备绝对音量能力。使用Callback异步回调。 315e41f4b71Sopenharmony_ci 316e41f4b71Sopenharmony_ci**系统接口**:此接口为系统接口。 317e41f4b71Sopenharmony_ci 318e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.ACCESS_BLUETOOTH 和 ohos.permission.MANAGE_BLUETOOTH 319e41f4b71Sopenharmony_ci 320e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Communication.Bluetooth.Core。 321e41f4b71Sopenharmony_ci 322e41f4b71Sopenharmony_ci**参数:** 323e41f4b71Sopenharmony_ci 324e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 325e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ------- | 326e41f4b71Sopenharmony_ci| deviceId | string | 是 | 远端设备地址。 | 327e41f4b71Sopenharmony_ci| callback | AsyncCallback<void> | 是 | 回调函数。如果成功,err为undefined,否则为错误对象。 | 328e41f4b71Sopenharmony_ci 329e41f4b71Sopenharmony_ci 330e41f4b71Sopenharmony_ci**错误码**: 331e41f4b71Sopenharmony_ci 332e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。 333e41f4b71Sopenharmony_ci 334e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 335e41f4b71Sopenharmony_ci| -------- | ---------------------------- | 336e41f4b71Sopenharmony_ci|201 | Permission denied. | 337e41f4b71Sopenharmony_ci|202 | Non-system applications are not allowed to use system APIs. | 338e41f4b71Sopenharmony_ci|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. | 339e41f4b71Sopenharmony_ci|801 | Capability not supported. | 340e41f4b71Sopenharmony_ci|2900001 | Service stopped. | 341e41f4b71Sopenharmony_ci|2900003 | Bluetooth disabled. | 342e41f4b71Sopenharmony_ci|2900099 | Operation failed. | 343e41f4b71Sopenharmony_ci 344e41f4b71Sopenharmony_ci**示例:** 345e41f4b71Sopenharmony_ci 346e41f4b71Sopenharmony_ci```js 347e41f4b71Sopenharmony_ciimport { AsyncCallback, BusinessError } from '@kit.BasicServicesKit'; 348e41f4b71Sopenharmony_citry { 349e41f4b71Sopenharmony_ci let a2dpSrc = a2dp.createA2dpSrcProfile(); 350e41f4b71Sopenharmony_ci a2dpSrc.enableAbsoluteVolume('XX:XX:XX:XX:XX:XX', (err) => { 351e41f4b71Sopenharmony_ci if (err) { 352e41f4b71Sopenharmony_ci console.error("enableAbsoluteVolume error"); 353e41f4b71Sopenharmony_ci } 354e41f4b71Sopenharmony_ci }); 355e41f4b71Sopenharmony_ci} catch (err) { 356e41f4b71Sopenharmony_ci console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message); 357e41f4b71Sopenharmony_ci} 358e41f4b71Sopenharmony_ci``` 359e41f4b71Sopenharmony_ci 360e41f4b71Sopenharmony_ci### enableAbsoluteVolume<sup>11+</sup> 361e41f4b71Sopenharmony_ci 362e41f4b71Sopenharmony_cienableAbsoluteVolume(deviceId: string): Promise<void> 363e41f4b71Sopenharmony_ci 364e41f4b71Sopenharmony_ci开启设备绝对音量能力。需要在设备支持绝对音量的情况下(参考[isAbsoluteVolumeSupported](#isabsolutevolumesupported11)),再开启设备绝对音量能力。使用Promise异步回调。 365e41f4b71Sopenharmony_ci 366e41f4b71Sopenharmony_ci**系统接口**:此接口为系统接口。 367e41f4b71Sopenharmony_ci 368e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.ACCESS_BLUETOOTH 和 ohos.permission.MANAGE_BLUETOOTH 369e41f4b71Sopenharmony_ci 370e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Communication.Bluetooth.Core。 371e41f4b71Sopenharmony_ci 372e41f4b71Sopenharmony_ci**参数:** 373e41f4b71Sopenharmony_ci 374e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 375e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ------- | 376e41f4b71Sopenharmony_ci| deviceId | string | 是 | 远端设备地址。 | 377e41f4b71Sopenharmony_ci 378e41f4b71Sopenharmony_ci**返回值:** 379e41f4b71Sopenharmony_ci 380e41f4b71Sopenharmony_ci| 类型 | 说明 | 381e41f4b71Sopenharmony_ci| ----------------------------- | ---------- | 382e41f4b71Sopenharmony_ci| Promise<void> | 以Promise的形式返回结果。如果成功,err为undefined,否则为错误对象。 | 383e41f4b71Sopenharmony_ci 384e41f4b71Sopenharmony_ci**错误码**: 385e41f4b71Sopenharmony_ci 386e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。 387e41f4b71Sopenharmony_ci 388e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 389e41f4b71Sopenharmony_ci| -------- | ---------------------------- | 390e41f4b71Sopenharmony_ci|201 | Permission denied. | 391e41f4b71Sopenharmony_ci|202 | Non-system applications are not allowed to use system APIs. | 392e41f4b71Sopenharmony_ci|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. | 393e41f4b71Sopenharmony_ci|801 | Capability not supported. | 394e41f4b71Sopenharmony_ci|2900001 | Service stopped. | 395e41f4b71Sopenharmony_ci|2900003 | Bluetooth disabled. | 396e41f4b71Sopenharmony_ci|2900099 | Operation failed. | 397e41f4b71Sopenharmony_ci 398e41f4b71Sopenharmony_ci**示例:** 399e41f4b71Sopenharmony_ci 400e41f4b71Sopenharmony_ci```js 401e41f4b71Sopenharmony_ciimport { AsyncCallback, BusinessError } from '@kit.BasicServicesKit'; 402e41f4b71Sopenharmony_citry { 403e41f4b71Sopenharmony_ci let a2dpSrc = a2dp.createA2dpSrcProfile(); 404e41f4b71Sopenharmony_ci a2dpSrc.enableAbsoluteVolume('XX:XX:XX:XX:XX:XX').then(() => { 405e41f4b71Sopenharmony_ci console.info("enableAbsoluteVolume"); 406e41f4b71Sopenharmony_ci } 407e41f4b71Sopenharmony_ci ); 408e41f4b71Sopenharmony_ci} catch (err) { 409e41f4b71Sopenharmony_ci console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message); 410e41f4b71Sopenharmony_ci} 411e41f4b71Sopenharmony_ci``` 412e41f4b71Sopenharmony_ci 413e41f4b71Sopenharmony_ci### disableAbsoluteVolume<sup>11+</sup> 414e41f4b71Sopenharmony_ci 415e41f4b71Sopenharmony_cidisableAbsoluteVolume(deviceId: string, callback: AsyncCallback<void>): void 416e41f4b71Sopenharmony_ci 417e41f4b71Sopenharmony_ci关闭设备绝对音量能力。需要在设备支持绝对音量的情况下(参考[isAbsoluteVolumeSupported](#isabsolutevolumesupported11)),再关闭设备绝对音量能力。使用Callback异步回调。 418e41f4b71Sopenharmony_ci 419e41f4b71Sopenharmony_ci**系统接口**:此接口为系统接口。 420e41f4b71Sopenharmony_ci 421e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.ACCESS_BLUETOOTH 和 ohos.permission.MANAGE_BLUETOOTH 422e41f4b71Sopenharmony_ci 423e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Communication.Bluetooth.Core。 424e41f4b71Sopenharmony_ci 425e41f4b71Sopenharmony_ci**参数:** 426e41f4b71Sopenharmony_ci 427e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 428e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ------- | 429e41f4b71Sopenharmony_ci| deviceId | string | 是 | 远端设备地址。 | 430e41f4b71Sopenharmony_ci| callback | AsyncCallback<void> | 是 | 回调函数。如果成功,err为undefined,否则为错误对象。 | 431e41f4b71Sopenharmony_ci 432e41f4b71Sopenharmony_ci 433e41f4b71Sopenharmony_ci**错误码**: 434e41f4b71Sopenharmony_ci 435e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。 436e41f4b71Sopenharmony_ci 437e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 438e41f4b71Sopenharmony_ci| -------- | ---------------------------- | 439e41f4b71Sopenharmony_ci|201 | Permission denied. | 440e41f4b71Sopenharmony_ci|202 | Non-system applications are not allowed to use system APIs. | 441e41f4b71Sopenharmony_ci|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. | 442e41f4b71Sopenharmony_ci|801 | Capability not supported. | 443e41f4b71Sopenharmony_ci|2900001 | Service stopped. | 444e41f4b71Sopenharmony_ci|2900003 | Bluetooth disabled. | 445e41f4b71Sopenharmony_ci|2900099 | Operation failed. | 446e41f4b71Sopenharmony_ci 447e41f4b71Sopenharmony_ci**示例:** 448e41f4b71Sopenharmony_ci 449e41f4b71Sopenharmony_ci```js 450e41f4b71Sopenharmony_ciimport { AsyncCallback, BusinessError } from '@kit.BasicServicesKit'; 451e41f4b71Sopenharmony_citry { 452e41f4b71Sopenharmony_ci let a2dpSrc = a2dp.createA2dpSrcProfile(); 453e41f4b71Sopenharmony_ci a2dpSrc.disableAbsoluteVolume('XX:XX:XX:XX:XX:XX', (err) => { 454e41f4b71Sopenharmony_ci if (err) { 455e41f4b71Sopenharmony_ci console.error("disableAbsoluteVolume error"); 456e41f4b71Sopenharmony_ci } 457e41f4b71Sopenharmony_ci }); 458e41f4b71Sopenharmony_ci} catch (err) { 459e41f4b71Sopenharmony_ci console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message); 460e41f4b71Sopenharmony_ci} 461e41f4b71Sopenharmony_ci``` 462e41f4b71Sopenharmony_ci 463e41f4b71Sopenharmony_ci### disableAbsoluteVolume<sup>11+</sup> 464e41f4b71Sopenharmony_ci 465e41f4b71Sopenharmony_cidisableAbsoluteVolume(deviceId: string): Promise<void> 466e41f4b71Sopenharmony_ci 467e41f4b71Sopenharmony_ci关闭设备绝对音量能力。需要在设备支持绝对音量的情况下(参考[isAbsoluteVolumeSupported](#isabsolutevolumesupported11)),再关闭设备绝对音量能力。使用Promise异步回调。 468e41f4b71Sopenharmony_ci 469e41f4b71Sopenharmony_ci**系统接口**:此接口为系统接口。 470e41f4b71Sopenharmony_ci 471e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.ACCESS_BLUETOOTH 和 ohos.permission.MANAGE_BLUETOOTH 472e41f4b71Sopenharmony_ci 473e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Communication.Bluetooth.Core。 474e41f4b71Sopenharmony_ci 475e41f4b71Sopenharmony_ci**参数:** 476e41f4b71Sopenharmony_ci 477e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 478e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ------- | 479e41f4b71Sopenharmony_ci| deviceId | string | 是 | 远端设备地址。 | 480e41f4b71Sopenharmony_ci 481e41f4b71Sopenharmony_ci**返回值:** 482e41f4b71Sopenharmony_ci 483e41f4b71Sopenharmony_ci| 类型 | 说明 | 484e41f4b71Sopenharmony_ci| ----------------------------- | ---------- | 485e41f4b71Sopenharmony_ci| Promise<void> | 以Promise的形式返回结果。如果成功,err为undefined,否则为错误对象。 | 486e41f4b71Sopenharmony_ci 487e41f4b71Sopenharmony_ci**错误码**: 488e41f4b71Sopenharmony_ci 489e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。 490e41f4b71Sopenharmony_ci 491e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 492e41f4b71Sopenharmony_ci| -------- | ---------------------------- | 493e41f4b71Sopenharmony_ci|201 | Permission denied. | 494e41f4b71Sopenharmony_ci|202 | Non-system applications are not allowed to use system APIs. | 495e41f4b71Sopenharmony_ci|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. | 496e41f4b71Sopenharmony_ci|801 | Capability not supported. | 497e41f4b71Sopenharmony_ci|2900001 | Service stopped. | 498e41f4b71Sopenharmony_ci|2900003 | Bluetooth disabled. | 499e41f4b71Sopenharmony_ci|2900099 | Operation failed. | 500e41f4b71Sopenharmony_ci 501e41f4b71Sopenharmony_ci**示例:** 502e41f4b71Sopenharmony_ci 503e41f4b71Sopenharmony_ci```js 504e41f4b71Sopenharmony_ciimport { AsyncCallback, BusinessError } from '@kit.BasicServicesKit'; 505e41f4b71Sopenharmony_citry { 506e41f4b71Sopenharmony_ci let a2dpSrc = a2dp.createA2dpSrcProfile(); 507e41f4b71Sopenharmony_ci a2dpSrc.disableAbsoluteVolume('XX:XX:XX:XX:XX:XX').then(() => { 508e41f4b71Sopenharmony_ci console.info("disableAbsoluteVolume"); 509e41f4b71Sopenharmony_ci }); 510e41f4b71Sopenharmony_ci} catch (err) { 511e41f4b71Sopenharmony_ci console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message); 512e41f4b71Sopenharmony_ci} 513e41f4b71Sopenharmony_ci``` 514e41f4b71Sopenharmony_ci 515e41f4b71Sopenharmony_ci### getCurrentCodecInfo<sup>11+</sup> 516e41f4b71Sopenharmony_ci 517e41f4b71Sopenharmony_cigetCurrentCodecInfo(deviceId: string): CodecInfo 518e41f4b71Sopenharmony_ci 519e41f4b71Sopenharmony_ci获取当前编码器信息。 520e41f4b71Sopenharmony_ci 521e41f4b71Sopenharmony_ci**系统接口**:此接口为系统接口。 522e41f4b71Sopenharmony_ci 523e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.ACCESS_BLUETOOTH 524e41f4b71Sopenharmony_ci 525e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Communication.Bluetooth.Core。 526e41f4b71Sopenharmony_ci 527e41f4b71Sopenharmony_ci**参数:** 528e41f4b71Sopenharmony_ci 529e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 530e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ------- | 531e41f4b71Sopenharmony_ci| deviceId | string | 是 | 远端设备地址。 | 532e41f4b71Sopenharmony_ci 533e41f4b71Sopenharmony_ci**返回值:** 534e41f4b71Sopenharmony_ci 535e41f4b71Sopenharmony_ci| 类型 | 说明 | 536e41f4b71Sopenharmony_ci| ----------------------------- | ---------- | 537e41f4b71Sopenharmony_ci| [CodecInfo](js-apis-bluetooth-a2dp#codecinfo11)| 当前编码器信息。 | 538e41f4b71Sopenharmony_ci 539e41f4b71Sopenharmony_ci**错误码**: 540e41f4b71Sopenharmony_ci 541e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。 542e41f4b71Sopenharmony_ci 543e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 544e41f4b71Sopenharmony_ci| -------- | ---------------------------- | 545e41f4b71Sopenharmony_ci|201 | Permission denied. | 546e41f4b71Sopenharmony_ci|202 | Non-system applications are not allowed to use system APIs. | 547e41f4b71Sopenharmony_ci|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. | 548e41f4b71Sopenharmony_ci|801 | Capability not supported. | 549e41f4b71Sopenharmony_ci|2900001 | Service stopped. | 550e41f4b71Sopenharmony_ci|2900003 | Bluetooth disabled. | 551e41f4b71Sopenharmony_ci|2900099 | Operation failed. | 552e41f4b71Sopenharmony_ci 553e41f4b71Sopenharmony_ci**示例:** 554e41f4b71Sopenharmony_ci 555e41f4b71Sopenharmony_ci```js 556e41f4b71Sopenharmony_ciimport { AsyncCallback, BusinessError } from '@kit.BasicServicesKit'; 557e41f4b71Sopenharmony_citry { 558e41f4b71Sopenharmony_ci let a2dpSrc = a2dp.createA2dpSrcProfile(); 559e41f4b71Sopenharmony_ci let codecInfo : a2dp.CodecInfo = a2dpSrc.getCurrentCodecInfo('XX:XX:XX:XX:XX:XX'); 560e41f4b71Sopenharmony_ci} catch (err) { 561e41f4b71Sopenharmony_ci console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message); 562e41f4b71Sopenharmony_ci} 563e41f4b71Sopenharmony_ci``` 564e41f4b71Sopenharmony_ci 565e41f4b71Sopenharmony_ci### setCurrentCodecInfo<sup>11+</sup> 566e41f4b71Sopenharmony_ci 567e41f4b71Sopenharmony_cisetCurrentCodecInfo(deviceId: string, codecInfo: CodecInfo): void 568e41f4b71Sopenharmony_ci 569e41f4b71Sopenharmony_ci设置当前编码器信息。 570e41f4b71Sopenharmony_ci 571e41f4b71Sopenharmony_ci**系统接口**:此接口为系统接口。 572e41f4b71Sopenharmony_ci 573e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.ACCESS_BLUETOOTH 和 ohos.permission.MANAGE_BLUETOOTH 574e41f4b71Sopenharmony_ci 575e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Communication.Bluetooth.Core。 576e41f4b71Sopenharmony_ci 577e41f4b71Sopenharmony_ci**参数:** 578e41f4b71Sopenharmony_ci 579e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 580e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ------- | 581e41f4b71Sopenharmony_ci| deviceId | string | 是 | 远端设备地址。 | 582e41f4b71Sopenharmony_ci| codecInfo | [CodecInfo](js-apis-bluetooth-a2dp.md#codecinfo11) | 是 | 编码器信息。 | 583e41f4b71Sopenharmony_ci 584e41f4b71Sopenharmony_ci**错误码**: 585e41f4b71Sopenharmony_ci 586e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。 587e41f4b71Sopenharmony_ci 588e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 589e41f4b71Sopenharmony_ci| -------- | ---------------------------- | 590e41f4b71Sopenharmony_ci|201 | Permission denied. | 591e41f4b71Sopenharmony_ci|202 | Non-system applications are not allowed to use system APIs. | 592e41f4b71Sopenharmony_ci|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. | 593e41f4b71Sopenharmony_ci|801 | Capability not supported. | 594e41f4b71Sopenharmony_ci|2900001 | Service stopped. | 595e41f4b71Sopenharmony_ci|2900003 | Bluetooth disabled. | 596e41f4b71Sopenharmony_ci|2900099 | Operation failed. | 597e41f4b71Sopenharmony_ci 598e41f4b71Sopenharmony_ci**示例:** 599e41f4b71Sopenharmony_ci 600e41f4b71Sopenharmony_ci```js 601e41f4b71Sopenharmony_ciimport { AsyncCallback, BusinessError } from '@kit.BasicServicesKit'; 602e41f4b71Sopenharmony_citry { 603e41f4b71Sopenharmony_ci let a2dpSrc = a2dp.createA2dpSrcProfile(); 604e41f4b71Sopenharmony_ci let codecInfo : a2dp.CodecInfo = { 605e41f4b71Sopenharmony_ci codecType: 0, 606e41f4b71Sopenharmony_ci codecBitsPerSample: 1, 607e41f4b71Sopenharmony_ci codecChannelMode: 2, 608e41f4b71Sopenharmony_ci codecSampleRate: 1 609e41f4b71Sopenharmony_ci } 610e41f4b71Sopenharmony_ci a2dpSrc.setCurrentCodecInfo('XX:XX:XX:XX:XX:XX', codecInfo); 611e41f4b71Sopenharmony_ci} catch (err) { 612e41f4b71Sopenharmony_ci console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message); 613e41f4b71Sopenharmony_ci} 614e41f4b71Sopenharmony_ci``` 615e41f4b71Sopenharmony_ci 616e41f4b71Sopenharmony_ci 617e41f4b71Sopenharmony_ci### disableAutoPlay<sup>12+</sup> 618e41f4b71Sopenharmony_ci 619e41f4b71Sopenharmony_cidisableAutoPlay(deviceId: string, duration: number): Promise<void> 620e41f4b71Sopenharmony_ci 621e41f4b71Sopenharmony_ci限制设备在连接成功的若干毫秒内播放音乐。使用Promise异步回调。 622e41f4b71Sopenharmony_ci 623e41f4b71Sopenharmony_ci**系统接口**:此接口为系统接口。 624e41f4b71Sopenharmony_ci 625e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.ACCESS_BLUETOOTH 和 ohos.permission.MANAGE_BLUETOOTH 626e41f4b71Sopenharmony_ci 627e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Communication.Bluetooth.Core。 628e41f4b71Sopenharmony_ci 629e41f4b71Sopenharmony_ci**参数:** 630e41f4b71Sopenharmony_ci 631e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 632e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ------- | 633e41f4b71Sopenharmony_ci| deviceId | string | 是 | 远端设备地址,例如:"11:22:33:AA:BB:FF"。 | 634e41f4b71Sopenharmony_ci| duration | number | 是 | 拦截时长,单位毫秒。 | 635e41f4b71Sopenharmony_ci 636e41f4b71Sopenharmony_ci**返回值:** 637e41f4b71Sopenharmony_ci 638e41f4b71Sopenharmony_ci| 类型 | 说明 | 639e41f4b71Sopenharmony_ci| ----------------------------- | ---------- | 640e41f4b71Sopenharmony_ci| Promise<void> | 以Promise的形式返回结果。如果成功,err为undefined,否则为错误对象。 | 641e41f4b71Sopenharmony_ci 642e41f4b71Sopenharmony_ci**错误码**: 643e41f4b71Sopenharmony_ci 644e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。 645e41f4b71Sopenharmony_ci 646e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 647e41f4b71Sopenharmony_ci| -------- | ---------------------------- | 648e41f4b71Sopenharmony_ci|201 | Permission denied. | 649e41f4b71Sopenharmony_ci|202 | Non-system applications are not allowed to use system APIs. | 650e41f4b71Sopenharmony_ci|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. | 651e41f4b71Sopenharmony_ci|801 | Capability not supported. | 652e41f4b71Sopenharmony_ci|2900001 | Service stopped. | 653e41f4b71Sopenharmony_ci|2900003 | Bluetooth disabled. | 654e41f4b71Sopenharmony_ci|2900099 | Operation failed. | 655e41f4b71Sopenharmony_ci 656e41f4b71Sopenharmony_ci**示例:** 657e41f4b71Sopenharmony_ci 658e41f4b71Sopenharmony_ci```js 659e41f4b71Sopenharmony_ciimport { AsyncCallback, BusinessError } from '@kit.BasicServicesKit'; 660e41f4b71Sopenharmony_citry { 661e41f4b71Sopenharmony_ci let a2dpSrc = a2dp.createA2dpSrcProfile(); 662e41f4b71Sopenharmony_ci let durationNumber = 1000; 663e41f4b71Sopenharmony_ci a2dpSrc.disableAutoPlay('XX:XX:XX:XX:XX:XX', durationNumber).then(() => { 664e41f4b71Sopenharmony_ci console.info("disableAutoPlay"); 665e41f4b71Sopenharmony_ci }); 666e41f4b71Sopenharmony_ci} catch (err) { 667e41f4b71Sopenharmony_ci console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message); 668e41f4b71Sopenharmony_ci} 669e41f4b71Sopenharmony_ci``` 670e41f4b71Sopenharmony_ci 671e41f4b71Sopenharmony_ci 672e41f4b71Sopenharmony_ci### enableAutoPlay<sup>12+</sup> 673e41f4b71Sopenharmony_ci 674e41f4b71Sopenharmony_cienableAutoPlay(deviceId: string): Promise<void> 675e41f4b71Sopenharmony_ci 676e41f4b71Sopenharmony_ci允许设备在连接成功后自动播放音乐。使用Promise异步回调。 677e41f4b71Sopenharmony_ci 678e41f4b71Sopenharmony_ci**系统接口**:此接口为系统接口。 679e41f4b71Sopenharmony_ci 680e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.ACCESS_BLUETOOTH 和 ohos.permission.MANAGE_BLUETOOTH 681e41f4b71Sopenharmony_ci 682e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Communication.Bluetooth.Core。 683e41f4b71Sopenharmony_ci 684e41f4b71Sopenharmony_ci**参数:** 685e41f4b71Sopenharmony_ci 686e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 687e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ------- | 688e41f4b71Sopenharmony_ci| deviceId | string | 是 | 远端设备地址,例如:"11:22:33:AA:BB:FF"。 | 689e41f4b71Sopenharmony_ci 690e41f4b71Sopenharmony_ci**返回值:** 691e41f4b71Sopenharmony_ci 692e41f4b71Sopenharmony_ci| 类型 | 说明 | 693e41f4b71Sopenharmony_ci| ----------------------------- | ---------- | 694e41f4b71Sopenharmony_ci| Promise<void> | 以Promise的形式返回结果。如果成功,err为undefined,否则为错误对象。 | 695e41f4b71Sopenharmony_ci 696e41f4b71Sopenharmony_ci**错误码**: 697e41f4b71Sopenharmony_ci 698e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。 699e41f4b71Sopenharmony_ci 700e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 701e41f4b71Sopenharmony_ci| -------- | ---------------------------- | 702e41f4b71Sopenharmony_ci|201 | Permission denied. | 703e41f4b71Sopenharmony_ci|202 | Non-system applications are not allowed to use system APIs. | 704e41f4b71Sopenharmony_ci|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. | 705e41f4b71Sopenharmony_ci|801 | Capability not supported. | 706e41f4b71Sopenharmony_ci|2900001 | Service stopped. | 707e41f4b71Sopenharmony_ci|2900003 | Bluetooth disabled. | 708e41f4b71Sopenharmony_ci|2900099 | Operation failed. | 709e41f4b71Sopenharmony_ci 710e41f4b71Sopenharmony_ci**示例:** 711e41f4b71Sopenharmony_ci 712e41f4b71Sopenharmony_ci```js 713e41f4b71Sopenharmony_ciimport { AsyncCallback, BusinessError } from '@kit.BasicServicesKit'; 714e41f4b71Sopenharmony_citry { 715e41f4b71Sopenharmony_ci let a2dpSrc = a2dp.createA2dpSrcProfile(); 716e41f4b71Sopenharmony_ci a2dpSrc.enableAutoPlay('XX:XX:XX:XX:XX:XX').then(() => { 717e41f4b71Sopenharmony_ci console.info("enableAutoPlay"); 718e41f4b71Sopenharmony_ci }); 719e41f4b71Sopenharmony_ci} catch (err) { 720e41f4b71Sopenharmony_ci console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message); 721e41f4b71Sopenharmony_ci} 722e41f4b71Sopenharmony_ci``` 723e41f4b71Sopenharmony_ci 724e41f4b71Sopenharmony_ci 725e41f4b71Sopenharmony_ci### getAutoPlayDisabledDuration<sup>12+</sup> 726e41f4b71Sopenharmony_ci 727e41f4b71Sopenharmony_cigetAutoPlayDisabledDuration(deviceId: string): Promise<number> 728e41f4b71Sopenharmony_ci 729e41f4b71Sopenharmony_ci获取拦截时长或自动播放开关。使用Promise异步回调。 730e41f4b71Sopenharmony_ci 731e41f4b71Sopenharmony_ci**系统接口**:此接口为系统接口。 732e41f4b71Sopenharmony_ci 733e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.ACCESS_BLUETOOTH 和 ohos.permission.MANAGE_BLUETOOTH 734e41f4b71Sopenharmony_ci 735e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Communication.Bluetooth.Core。 736e41f4b71Sopenharmony_ci 737e41f4b71Sopenharmony_ci**参数:** 738e41f4b71Sopenharmony_ci 739e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 740e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ------- | 741e41f4b71Sopenharmony_ci| deviceId | string | 是 | 远端设备地址,例如:"11:22:33:AA:BB:FF"。 | 742e41f4b71Sopenharmony_ci 743e41f4b71Sopenharmony_ci**返回值:** 744e41f4b71Sopenharmony_ci 745e41f4b71Sopenharmony_ci| 类型 | 说明 | 746e41f4b71Sopenharmony_ci| ----------------------------- | ---------- | 747e41f4b71Sopenharmony_ci| Promise<number> | 以Promise的形式返回结果。number为返回的拦截时长,单位为毫秒;如果返回-1,则表示允许设备在连接成功后自动播放音乐。 | 748e41f4b71Sopenharmony_ci 749e41f4b71Sopenharmony_ci**错误码**: 750e41f4b71Sopenharmony_ci 751e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。 752e41f4b71Sopenharmony_ci 753e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 754e41f4b71Sopenharmony_ci| -------- | ---------------------------- | 755e41f4b71Sopenharmony_ci|201 | Permission denied. | 756e41f4b71Sopenharmony_ci|202 | Non-system applications are not allowed to use system APIs. | 757e41f4b71Sopenharmony_ci|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. | 758e41f4b71Sopenharmony_ci|801 | Capability not supported. | 759e41f4b71Sopenharmony_ci|2900001 | Service stopped. | 760e41f4b71Sopenharmony_ci|2900003 | Bluetooth disabled. | 761e41f4b71Sopenharmony_ci|2900099 | Operation failed. | 762e41f4b71Sopenharmony_ci 763e41f4b71Sopenharmony_ci**示例:** 764e41f4b71Sopenharmony_ci 765e41f4b71Sopenharmony_ci```js 766e41f4b71Sopenharmony_ciimport { AsyncCallback, BusinessError } from '@kit.BasicServicesKit'; 767e41f4b71Sopenharmony_citry { 768e41f4b71Sopenharmony_ci let a2dpSrc = a2dp.createA2dpSrcProfile(); 769e41f4b71Sopenharmony_ci a2dpSrc.getAutoPlayDisabledDuration('XX:XX:XX:XX:XX:XX').then((data: number) => { 770e41f4b71Sopenharmony_ci console.info('number' + JSON.stringify(data)); 771e41f4b71Sopenharmony_ci }); 772e41f4b71Sopenharmony_ci} catch (err) { 773e41f4b71Sopenharmony_ci console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message); 774e41f4b71Sopenharmony_ci} 775e41f4b71Sopenharmony_ci```