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

!21673 [翻译完成】#I7KIUC

Merge pull request !21673 from Annie_wang/PR20671
......@@ -317,8 +317,18 @@
- [@ohos.request (Upload and Download)](js-apis-request.md)
- Connectivity
- [@ohos.bluetooth.a2dp (Bluetooth a2dp Module)(Recommended)](js-apis-bluetooth-a2dp.md)
- [@ohos.bluetooth.access (Bluetooth access Module)(Recommended)](js-apis-bluetooth-access.md)
- [@ohos.bluetooth.baseProfile (Bluetooth baseProfile Module)(Recommended)](js-apis-bluetooth-baseProfile.md)
- [@ohos.bluetooth.ble (Bluetooth ble Module)(Recommended)](js-apis-bluetooth-ble.md)
- [@ohos.bluetooth.connection (Bluetooth connection Module)(Recommended)](js-apis-bluetooth-connection.md)
- [@ohos.bluetooth.constant (Bluetooth constant Module)(Recommended)](js-apis-bluetooth-constant.md)
- [@ohos.bluetooth.hfp (Bluetooth hfp Module)(Recommended)](js-apis-bluetooth-hfp.md)
- [@ohos.bluetooth.hid (Bluetooth hid Module)(Recommended)(js-apis-bluetooth-hid.md)
- [@ohos.bluetooth.pan (Bluetooth pan Module)(Recommended)](js-apis-bluetooth-pan.md)
- [@ohos.bluetooth.socket (Bluetooth socket Module)(Recommended)](js-apis-bluetooth-socket.md)
- [@ohos.bluetooth (Bluetooth) (To Be Deprecated Soon)](js-apis-bluetooth.md)
- [@ohos.bluetoothManager (Bluetooth) (Recommended)](js-apis-bluetoothManager.md)
- [@ohos.bluetoothManager (Bluetooth) (To Be Deprecated Soon)](js-apis-bluetoothManager.md)
- [@ohos.connectedTag (Active Tags)](js-apis-connectedTag.md)
- [@ohos.nfc.cardEmulation (Standard NFC Card Emulation)](js-apis-cardEmulation.md)
- [@ohos.nfc.controller (Standard NFC)](js-apis-nfcController.md)
......
# @ohos.bluetooth.a2dp (Bluetooth A2DP Module)
The **a2dp** module provides APIs for using the Bluetooth Advanced Audio Distribution Profile (A2DP), which defines how to stream high quality audio from one device to another over a Bluetooth connection.
> **NOTE**
>
> The initial APIs of this module are supported since API version 10. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import
```js
import a2dp from '@ohos.bluetooth.a2dp';
```
## a2dp.createA2dpSrcProfile<a name="createA2dpSrcProfile"></a>
createA2dpSrcProfile(): A2dpSourceProfile
Creates an **A2dpSrcProfile** instance.
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Return value**
| Type | Description |
| ----------------------------- | ---------- |
| A2dpSourceProfile | **A2dpSrcProfile** instance created.|
**Example**
```js
try {
let a2dpProfile = a2dp.createA2dpSrcProfile();
console.info('a2dp success');
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
## A2dpSourceProfile
Provides APIs for using the A2DP. Before using any API of **A2dpSourceProfile**, you need to create an instance of this class by using **createA2dpSrcProfile()**.
### connect<a name="a2dp-connect"></a>
connect(deviceId: string): void
Connects to an A2DP device.
**System API**: This is a system API.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | ------- |
| deviceId | string | Yes | Address of the device to connect. |
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900003 | Bluetooth switch is off. |
|2900004 | Profile is not supported. |
|2900099 | Operation failed. |
**Example**
```js
try {
let a2dpSrc = a2dp.createA2dpSrcProfile();
a2dpSrc.connect('XX:XX:XX:XX:XX:XX');
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
### disconnect<a name="a2dp-disconnect"></a>
disconnect(deviceId: string): void
Disconnects from an A2DP device.
**System API**: This is a system API.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | ------- |
| deviceId | string | Yes | Address of the device to disconnect. |
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900003 | Bluetooth switch is off. |
|2900004 | Profile is not supported. |
|2900099 | Operation failed. |
**Example**
```js
try {
let a2dpSrc = a2dp.createA2dpSrcProfile();
a2dpSrc.disconnect('XX:XX:XX:XX:XX:XX');
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
### getPlayingState
getPlayingState(deviceId: string): PlayingState
Obtains the playing state of a device.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | ------- |
| device | string | Yes | Address of the remote device.|
**Return value**
| Type | Description |
| ----------------------------- | ---------- |
| [PlayingState](#PlayingState) | Playing state of the remote device obtained.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900003 | Bluetooth switch is off. |
|2900004 | Profile is not supported. |
|2900099 | Operation failed. |
**Example**
```js
try {
let a2dpSrc = a2dp.createA2dpSrcProfile();
let state = a2dpSrc.getPlayingState('XX:XX:XX:XX:XX:XX');
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
## PlayingState<a name="PlayingState"></a>
Enumerates the A2DP playing states.
**System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Value | Description |
| ----------------- | ------ | ------- |
| STATE_NOT_PLAYING | 0x0000 | Not playing. |
| STATE_PLAYING | 0x0001 | Playing.|
# @ohos.bluetooth.access (Bluetooth Access Module)
The **access** module provides APIs for enabling and disabling Bluetooth and obtaining the Bluetooth status.
> **NOTE**
>
> The initial APIs of this module are supported since API version 10. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import
```js
import access from '@ohos.bluetooth.access';
```
## access.enableBluetooth<a name="enableBluetooth"></a>
enableBluetooth(): void
Enables Bluetooth.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message |
| -------- | ------------------ |
|2900001 | Service stopped. |
|2900099 | Operation failed. |
**Example**
```js
try {
access.enableBluetooth();
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
## access.disableBluetooth<a name="disableBluetooth"></a>
disableBluetooth(): void
Disables Bluetooth.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
|ID | Error Message |
| -------- | ------------------ |
|2900001 | Service stopped. |
|2900099 | Operation failed. |
**Example**
```js
try {
access.disableBluetooth();
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
## access.getState<a name="getState"></a>
getState(): BluetoothState
Obtains the Bluetooth state.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Return value**
| Type | Description |
| --------------------------------- | ---------------- |
| [BluetoothState](#bluetoothstate) | Bluetooth state obtained.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
|ID | Error Message |
| -------- | ------------------ |
|2900001 | Service stopped. |
|2900099 | Operation failed. |
**Example**
```js
try {
let state = access.getState();
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
## access.on('stateChange')<a name="stateChange"></a>
on(type: "stateChange", callback: Callback&lt;BluetoothState&gt;): void
Subscribes to Bluetooth state changes.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ------------------------------------------------- | ----- | ---------------------------------------------------------- |
| type | string | Yes | Event type. The value is **stateChange**, which indicates a Bluetooth state change event. |
| callback | Callback&lt;[BluetoothState](#bluetoothstate)&gt; | Yes | Callback invoked to return the Bluetooth state. You need to implement this callback.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
|ID | Error Message |
| -------- | ------------------ |
|2900099 | Operation failed. |
**Example**
```js
function onReceiveEvent(data) {
console.info('bluetooth state = '+ JSON.stringify(data));
}
try {
access.on('stateChange', onReceiveEvent);
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
## access.off('stateChange')<a name="stateChange"></a>
off(type: "stateChange", callback?: Callback&lt;BluetoothState&gt;): void
Unsubscribes from Bluetooth state changes.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type | string | Yes | Event type. The value is **stateChange**, which indicates a Bluetooth state change event. |
| callback | Callback&lt;[BluetoothState](#bluetoothstate)&gt; | No | Callback for the Bluetooth state change event. If this parameter is not set, this API unsubscribes from all callbacks corresponding to **type**.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900099 | Operation failed. |
**Example**
```js
function onReceiveEvent(data) {
console.info('bluetooth state = '+ JSON.stringify(data));
}
try {
access.on('stateChange', onReceiveEvent);
access.off('stateChange', onReceiveEvent);
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
## BluetoothState<a name="BluetoothState"></a>
Enumerates the Bluetooth states.
**System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Value | Description |
| --------------------- | ---- | ------------------ |
| STATE_OFF | 0 | Bluetooth is turned off. |
| STATE_TURNING_ON | 1 | Bluetooth is being turned on. |
| STATE_ON | 2 | Bluetooth is turned on. |
| STATE_TURNING_OFF | 3 | Bluetooth is being turned off. |
| STATE_BLE_TURNING_ON | 4 | The LE-only mode is being turned on for Bluetooth.|
| STATE_BLE_ON | 5 | Bluetooth is in LE-only mode. |
| STATE_BLE_TURNING_OFF | 6 | The LE-only mode is being turned off for Bluetooth.|
# @ohos.bluetooth.baseProfile (Bluetooth baseProfile Module)
The **baseProfile** module provides APIs for using basic Bluetooth profiles.
> **NOTE**
>
> The initial APIs of this module are supported since API version 10. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import
```js
import baseProfile from '@ohos.bluetooth.baseProfile';
```
## ConnectionStrategy<a name="ConnectionStrategy"></a>
Enumerates the profile connection strategies.
**System API**: This is a system API.
**System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Value | Description |
| -------------------------------- | ------ | --------------- |
| CONNECTION_STRATEGY_UNSUPPORTED | 0 | Default connection strategy to use when the device is not paired.<br>This is a system API.|
| CONNECTION_STRATEGY_ALLOWED | 1 | Connection strategy to use when the device is allowed to accept or initiate pairing.<br>This is a system API.|
| CONNECTION_STRATEGY_FORBIDDEN | 2 | Connection strategy to use when the device is not allowed to accept or initiate pairing.<br>This is a system API. |
## StateChangeParam<a name="StateChangeParam"></a>
Represents the profile state change parameters.
**System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Type | Readable| Writable| Description |
| -------- | ----------------------------- | ---- | ---- | ------------------------------- |
| deviceId | string | Yes | No | Address of the Bluetooth device. |
| state | ProfileConnectionState | Yes | No | Profile connection state of the device.|
## baseProfile.setConnectionStrategy<a name="setConnectionStrategy"></a>
setConnectionStrategy(deviceId: string, strategy: ConnectionStrategy, callback: AsyncCallback&lt;void&gt;): void
Sets the profile connection strategy for this device. This API uses an asynchronous callback to return the result.
**System API**: This is a system API.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH and ohos.permission.MANAGE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ------ | ---- | ----------------------------------- |
| deviceId | string | Yes | Address of the device to pair, for example, XX:XX:XX:XX:XX:XX. |
| strategy | [ConnectionStrategy](#connectionstrategy) | Yes |Profile connection strategy to set.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900003 | Bluetooth switch is off. |
|2900004 | Profile is not supported. |
|2900099 | Operation failed. |
**Example**
```js
import a2dp from '@ohos.bluetooth.a2dp';
try {
let a2dpSrc = a2dp.createA2dpSrcProfile();
let setRet = a2dpSrc.setConnectionStrategy('XX:XX:XX:XX:XX:XX', 0, (err, data) => {
console.info('setConnectionStrategy, err: ' + JSON.stringify(err) + ', data: ' + JSON.stringify(data));
});
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
## baseProfile.setConnectionStrategy<a name="setConnectionStrategy"></a>
setConnectionStrategy(deviceId: string, strategy: ConnectionStrategy): Promise&lt;void&gt;
Sets the profile connection strategy for this device. This API uses a promise to return the result.
**System API**: This is a system API.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH and ohos.permission.MANAGE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ------ | ---- | ----------------------------------- |
| deviceId | string | Yes | Address of the device to pair, for example, XX:XX:XX:XX:XX:XX. |
| strategy | [ConnectionStrategy](#connectionstrategy) | Yes |Profile connection strategy to set.|
**Return value**
| Type | Description |
| ------------------- | ------------- |
| Promise&lt;void&gt; | Promise used to return the result.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900003 | Bluetooth switch is off. |
|2900004 | Profile is not supported. |
|2900099 | Operation failed. |
**Example**
```js
import a2dp from '@ohos.bluetooth.a2dp';
try {
let a2dpSrc = a2dp.createA2dpSrcProfile();
let setRet = a2dpSrc.setConnectionStrategy('XX:XX:XX:XX:XX:XX', 1).then((data) => {
console.info('setConnectionStrategy');
}, (err) => {
console.error('setConnectionStrategy errCode: ' + err.code + ', errMessage: ' + err.message);
});
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
## baseProfile.getConnectionStrategy<a name="getConnectionStrategy"></a>
getConnectionStrategy(deviceId: string, callback: AsyncCallback&lt;ConnectionStrategy&gt;): void
Obtains the profile connection strategy. This API uses an asynchronous callback to return the result.
**System API**: This is a system API.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH and ohos.permission.MANAGE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ------ | ---- | ----------------------------------- |
| deviceId | string | Yes | Address of the device to pair, for example, XX:XX:XX:XX:XX:XX. |
| callback | AsyncCallback&lt;[ConnectionStrategy](#connectionstrategy)&gt; | Yes | Callback invoked to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900003 | Bluetooth switch is off. |
|2900004 | Profile is not supported. |
|2900099 | Operation failed. |
**Example**
```js
import a2dp from '@ohos.bluetooth.a2dp';
try {
let a2dpSrc = a2dp.createA2dpSrcProfile();
let setRet = a2dpSrc.getConnectionStrategy('XX:XX:XX:XX:XX:XX', 0, (err, data) => {
console.info('getConnectionStrategy, err: ' + JSON.stringify(err) + ', data: ' + JSON.stringify(data));
});
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
## baseProfile.getConnectionStrategy<a name="getConnectionStrategy"></a>
getConnectionStrategy(deviceId: string): Promise&lt;ConnectionStrategy&gt;
Obtains the profile connection strategy. This API uses a promise to return the result.
**System API**: This is a system API.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH and ohos.permission.MANAGE_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ------ | ---- | ----------------------------------- |
| deviceId | string | Yes | Address of the device to pair, for example, XX:XX:XX:XX:XX:XX. |
**Return value**
| Type | Description |
| ------------------- | ------------- |
| Promise&lt;[ConnectionStrategy](#connectionstrategy)&gt; | Promise used to return the profile connection strategy obtained.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900003 | Bluetooth switch is off. |
|2900004 | Profile is not supported. |
|2900099 | Operation failed. |
**Example**
```js
import a2dp from '@ohos.bluetooth.a2dp';
try {
let a2dpSrc = a2dp.createA2dpSrcProfile();
let setRet = a2dpSrc.getConnectionStrategy('XX:XX:XX:XX:XX:XX', 1).then((data) => {
console.info('getConnectionStrategy');
}, (error) => {
console.error('getConnectionStrategy errCode: ' + err.code + ', errMessage: ' + err.message);
});
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
## baseProfile.getConnectedDevices<a name="getConnectedDevices"></a>
getConnectedDevices(): Array&lt;string&gt;
Obtains the connected devices.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Return value**
| Type | Description |
| ------------------- | ------------------- |
| Array&lt;string&gt; | Addresses of the connected devices.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900003 | Bluetooth switch is off. |
|2900004 | Profile is not supported. |
|2900099 | Operation failed. |
**Example**
```js
import a2dp from '@ohos.bluetooth.a2dp';
try {
let a2dpSrc = a2dp.createA2dpSrcProfile();
let retArray = a2dpSrc.getConnectedDevices();
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
```
## baseProfile.getConnectionState<a name="getConnectionState"></a>
getConnectionState(deviceId: string): ProfileConnectionState
Obtains the profile connection state of a device.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | ------- |
| deviceId | string | Yes | Address of the remote device.|
**Return value**
| Type | Description |
| ------------------------------------------------- | ----------------------- |
| [ProfileConnectionState](js-apis-bluetooth-constant.md#profileconnectionstate) | Profile connection state obtained.|
**Error codes**
For details about the error codes, see [Bluetooth Error Codes](../errorcodes/errorcode-bluetoothManager.md).
| ID| Error Message|
| -------- | ---------------------------- |
|2900001 | Service stopped. |
|2900003 | Bluetooth switch is off. |
|2900004 | Profile is not supported. |
|2900099 | Operation failed. |
**Example**
```js
import a2dp from '@ohos.bluetooth.a2dp';
try {
let a2dpSrc = a2dp.createA2dpSrcProfile();
let ret = a2dpSrc.getConnectionState('XX:XX:XX:XX:XX:XX');
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
## baseProfile.on('connectionStateChange')
on(type: 'connectionStateChange', callback: Callback&lt;StateChangeParam&gt;): void
Subscribes to profile connection state changes.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type | string | Yes | Event type. The value is **connectionStateChange**, which indicates a profile connection state change event.|
| callback | Callback&lt;[StateChangeParam](#statechangeparam)&gt; | Yes | Callback invoked to return the profile connection state change. |
**Example**
```js
import a2dp from '@ohos.bluetooth.a2dp';
try {
function onReceiveEvent(data) {
console.info('a2dp state = '+ JSON.stringify(data));
}
let a2dpSrc = a2dp.createA2dpSrcProfile();
a2dpSrc.on('connectionStateChange', onReceiveEvent);
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
## baseProfile.off('connectionStateChange')
off(type: 'connectionStateChange', callback?: Callback&lt;[StateChangeParam](#StateChangeParam)&gt;): void
Unsubscribes from profile connection state changes.
**Required permissions**: ohos.permission.ACCESS_BLUETOOTH
**System capability**: SystemCapability.Communication.Bluetooth.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type | string | Yes | Event type. The value is **connectionStateChange**, which indicates a profile connection state change event.|
| callback | Callback&lt;[StateChangeParam](#StateChangeParam)&gt; | No | Callback for the profile connection state change. |
**Example**
```js
import a2dp from '@ohos.bluetooth.a2dp';
try {
function onReceiveEvent(data) {
console.info('a2dp state = '+ JSON.stringify(data));
}
let a2dpSrc = a2dp.createA2dpSrcProfile();
a2dpSrc.on('connectionStateChange', onReceiveEvent);
a2dpSrc.off('connectionStateChange', onReceiveEvent);
} catch (err) {
console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}
```
# @ohos.bluetooth.constant (Bluetooth constant Module)
The **constant** module provides definitions of the constants used in Bluetooth.
> **NOTE**
>
> The initial APIs of this module are supported since API version 10. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import
```js
import constant from '@ohos.bluetooth.constant';
```
## ProfileId<a name="ProfileId"></a>
Enumerates profiles.
**System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Value | Description |
| -------------------------------- | ------ | --------------- |
| PROFILE_A2DP_SOURCE | 1 | Advanced Audio Distribution Profile (A2DP).|
| PROFILE_HANDSFREE_AUDIO_GATEWAY | 4 | Hands-Free Profile (HFP). |
| PROFILE_HID_HOST | 6 | Human Interface Device (HID) profile. |
| PROFILE_PAN_NETWORK | 7 | Bluetooth personal area network (PAN) profile. |
## ProfileUuids<a name="ProfileUuids"></a>
Enumerates profile UUIDs.
**System API**: This is a system API.
**System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Value | Description |
| ------------------------------------| ------ | --------------- |
| PROFILE_UUID_HFP_AG | '0000111F-0000-1000-8000-00805F9B34FB' | UUID of the HFPAG Profile.<br>This is a system API.|
| PROFILE_UUID_HFP_HF | '0000111E-0000-1000-8000-00805F9B34FB' | UUID of the HFPHF Profile.<br>This is a system API. |
| PROFILE_UUID_HSP_AG | '00001112-0000-1000-8000-00805F9B34FB' | UUID of the HSPAG Profile.<br>This is a system API. |
| PROFILE_UUID_HSP_HS | '00001108-0000-1000-8000-00805F9B34FB' | UUID of the HSPHS Profile.<br>This is a system API. |
| PROFILE_UUID_A2DP_SRC | '0000110A-0000-1000-8000-00805F9B34FB' | Indicates the UID of the A2DPSRC Profile.<br>This is a system API. |
| PROFILE_UUID_A2DP_SINK | '0000110B-0000-1000-8000-00805F9B34FB' | UUID of the A2DPSINK Profile.<br>This is a system API. |
| PROFILE_UUID_AVRCP_CT | '0000110E-0000-1000-8000-00805F9B34FB' | UUID of the AVRCPCT Profile.<br>This is a system API. |
| PROFILE_UUID_AVRCP_TG | '0000110C-0000-1000-8000-00805F9B34FB' | UUID of the AVRCPTG Profile.<br>This is a system API. |
| PROFILE_UUID_HID | '00001124-0000-1000-8000-00805F9B34FB' | UUID of the HID Profile.<br>This is a system API. |
| PROFILE_UUID_HOGP | '00001812-0000-1000-8000-00805F9B34FB' | UUID of the HOGP Profile.<br>This is a system API. |
## ProfileConnectionState
Enumerates the profile connection states.
**System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Value | Description |
| ------------------- | ---- | -------------- |
| STATE_DISCONNECTED | 0 | Disconnected. |
| STATE_CONNECTING | 1 | Connecting.|
| STATE_CONNECTED | 2 | Connected. |
| STATE_DISCONNECTING | 3 | Disconnecting.|
## MajorClass<a name="MajorClass"></a>
Enumerates the major classes of Bluetooth devices.
**System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Value | Description |
| ------------------- | ------ | ---------- |
| MAJOR_MISC | 0x0000 | Miscellaneous device. |
| MAJOR_COMPUTER | 0x0100 | Computer. |
| MAJOR_PHONE | 0x0200 | Mobile phone. |
| MAJOR_NETWORKING | 0x0300 | Network device. |
| MAJOR_AUDIO_VIDEO | 0x0400 | Audio or video device.|
| MAJOR_PERIPHERAL | 0x0500 | Peripheral device. |
| MAJOR_IMAGING | 0x0600 | Imaging device. |
| MAJOR_WEARABLE | 0x0700 | Wearable device. |
| MAJOR_TOY | 0x0800 | Toy. |
| MAJOR_HEALTH | 0x0900 | Health device. |
| MAJOR_UNCATEGORIZED | 0x1F00 | Unclassified device. |
## MajorMinorClass<a name="MajorMinorClass"></a>
Enumerates the major and minor classes of Bluetooth devices.
**System capability**: SystemCapability.Communication.Bluetooth.Core
| Name | Value | Description |
| ---------------------------------------- | ------ | --------------- |
| COMPUTER_UNCATEGORIZED | 0x0100 | Unclassified computer. |
| COMPUTER_DESKTOP | 0x0104 | Desktop computer. |
| COMPUTER_SERVER | 0x0108 | Server. |
| COMPUTER_LAPTOP | 0x010C | Laptop. |
| COMPUTER_HANDHELD_PC_PDA | 0x0110 | Hand-held computer. |
| COMPUTER_PALM_SIZE_PC_PDA | 0x0114 | Palmtop computer. |
| COMPUTER_WEARABLE | 0x0118 | Wearable computer. |
| COMPUTER_TABLET | 0x011C | Tablet. |
| PHONE_UNCATEGORIZED | 0x0200 | Unclassified mobile phone. |
| PHONE_CELLULAR | 0x0204 | Portable phone. |
| PHONE_CORDLESS | 0x0208 | Cordless phone. |
| PHONE_SMART | 0x020C | Smartphone. |
| PHONE_MODEM_OR_GATEWAY | 0x0210 | Modem or gateway phone.|
| PHONE_ISDN | 0x0214 | ISDN phone. |
| NETWORK_FULLY_AVAILABLE | 0x0300 | Device with network fully available. |
| NETWORK_1_TO_17_UTILIZED | 0x0320 | Device used on network 1 to 17. |
| NETWORK_17_TO_33_UTILIZED | 0x0340 | Device used on network 17 to 33. |
| NETWORK_33_TO_50_UTILIZED | 0x0360 | Device used on network 33 to 50. |
| NETWORK_60_TO_67_UTILIZED | 0x0380 | Device used on network 60 to 67. |
| NETWORK_67_TO_83_UTILIZED | 0x03A0 | Device used on network 67 to 83. |
| NETWORK_83_TO_99_UTILIZED | 0x03C0 | Device used on network 83 to 99. |
| NETWORK_NO_SERVICE | 0x03E0 | Device without network service |
| AUDIO_VIDEO_UNCATEGORIZED | 0x0400 | Unclassified audio or video device. |
| AUDIO_VIDEO_WEARABLE_HEADSET | 0x0404 | Wearable audio or video headset. |
| AUDIO_VIDEO_HANDSFREE | 0x0408 | Hands-free audio or video device. |
| AUDIO_VIDEO_MICROPHONE | 0x0410 | Audio or video microphone. |
| AUDIO_VIDEO_LOUDSPEAKER | 0x0414 | Audio or video loudspeaker. |
| AUDIO_VIDEO_HEADPHONES | 0x0418 | Audio or video headphones. |
| AUDIO_VIDEO_PORTABLE_AUDIO | 0x041C | Portable audio or video device. |
| AUDIO_VIDEO_CAR_AUDIO | 0x0420 | In-vehicle audio or video device. |
| AUDIO_VIDEO_SET_TOP_BOX | 0x0424 | Audio or video STB device. |
| AUDIO_VIDEO_HIFI_AUDIO | 0x0428 | High-fidelity speaker device. |
| AUDIO_VIDEO_VCR | 0x042C | Video cassette recording (VCR) device. |
| AUDIO_VIDEO_VIDEO_CAMERA | 0x0430 | Camera. |
| AUDIO_VIDEO_CAMCORDER | 0x0434 | Camcorder |
| AUDIO_VIDEO_VIDEO_MONITOR | 0x0438 | Audio or video monitor. |
| AUDIO_VIDEO_VIDEO_DISPLAY_AND_LOUDSPEAKER | 0x043C | Video display or loudspeaker. |
| AUDIO_VIDEO_VIDEO_CONFERENCING | 0x0440 | Video conferencing device. |
| AUDIO_VIDEO_VIDEO_GAMING_TOY | 0x0448 | Audio or video gaming toy. |
| PERIPHERAL_NON_KEYBOARD_NON_POINTING | 0x0500 | Non-keyboard or non-pointing peripheral device. |
| PERIPHERAL_KEYBOARD | 0x0540 | Keyboard device. |
| PERIPHERAL_POINTING_DEVICE | 0x0580 | Pointing peripheral device. |
| PERIPHERAL_KEYBOARD_POINTING | 0x05C0 | Keyboard pointing device. |
| PERIPHERAL_UNCATEGORIZED | 0x0500 | Unclassified peripheral device. |
| PERIPHERAL_JOYSTICK | 0x0504 | Peripheral joystick. |
| PERIPHERAL_GAMEPAD | 0x0508 | Peripheral game pad |
| PERIPHERAL_REMOTE_CONTROL | 0x05C0 | Peripheral remote control device |
| PERIPHERAL_SENSING_DEVICE | 0x0510 | Peripheral sensing device. |
| PERIPHERAL_DIGITIZER_TABLET | 0x0514 | Peripheral digitizer tablet.|
| PERIPHERAL_CARD_READER | 0x0518 | Peripheral card reader. |
| PERIPHERAL_DIGITAL_PEN | 0x051C | Peripheral digital pen. |
| PERIPHERAL_SCANNER_RFID | 0x0520 | Peripheral RFID scanner. |
| PERIPHERAL_GESTURAL_INPUT | 0x0522 | Gesture input device. |
| IMAGING_UNCATEGORIZED | 0x0600 | Unclassified imaging device. |
| IMAGING_DISPLAY | 0x0610 | Imaging display device. |
| IMAGING_CAMERA | 0x0620 | Imaging camera device. |
| IMAGING_SCANNER | 0x0640 | Imaging scanner. |
| IMAGING_PRINTER | 0x0680 | Imaging printer. |
| WEARABLE_UNCATEGORIZED | 0x0700 | Unclassified wearable device. |
| WEARABLE_WRIST_WATCH | 0x0704 | Smart watch. |
| WEARABLE_PAGER | 0x0708 | Wearable pager. |
| WEARABLE_JACKET | 0x070C | Smart jacket. |
| WEARABLE_HELMET | 0x0710 | Wearable helmet. |
| WEARABLE_GLASSES | 0x0714 | Wearable glasses. |
| TOY_UNCATEGORIZED | 0x0800 | Unclassified toy. |
| TOY_ROBOT | 0x0804 | Toy robot. |
| TOY_VEHICLE | 0x0808 | Toy vehicle. |
| TOY_DOLL_ACTION_FIGURE | 0x080C | Humanoid toy doll. |
| TOY_CONTROLLER | 0x0810 | Toy controller. |
| TOY_GAME | 0x0814 | Toy gaming device. |
| HEALTH_UNCATEGORIZED | 0x0900 | Unclassified health devices. |
| HEALTH_BLOOD_PRESSURE | 0x0904 | Blood pressure device. |
| HEALTH_THERMOMETER | 0x0908 | Thermometer |
| HEALTH_WEIGHING | 0x090C | Body scale. |
| HEALTH_GLUCOSE | 0x0910 | Blood glucose monitor. |
| HEALTH_PULSE_OXIMETER | 0x0914 | Pulse oximeter. |
| HEALTH_PULSE_RATE | 0x0918 | Heart rate monitor. |
| HEALTH_DATA_DISPLAY | 0x091C | Health data display. |
| HEALTH_STEP_COUNTER | 0x0920 | Step counter. |
| HEALTH_BODY_COMPOSITION_ANALYZER | 0x0924 | Body composition analyzer. |
| HEALTH_PEAK_FLOW_MONITOR | 0x0928 | Hygrometer. |
| HEALTH_MEDICATION_MONITOR | 0x092C | Medication monitor. |
| HEALTH_KNEE_PROSTHESIS | 0x0930 | Prosthetic knee. |
| HEALTH_ANKLE_PROSTHESIS | 0x0934 | Prosthetic ankle. |
| HEALTH_GENERIC_HEALTH_MANAGER | 0x0938 | Generic health management device. |
| HEALTH_PERSONAL_MOBILITY_DEVICE | 0x093C | Personal mobility device. |
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册