openharmony 鸿蒙 js-apis-bluetooth-connection-sys

2025-06-12 浏览 (1)

@ohos.bluetooth.connection (Bluetooth Connection Module) (System API)

The connection module provides APIs for operating and managing 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. This topic describes only the system APIs provided by the module. For details about its public APIs, see @ohos.bluetooth.connection (Bluetooth Connection Module).

Modules to Import

import { connection } from '@kit.ConnectivityKit';

connection.pairCredibleDevice

pairCredibleDevice(deviceId: string, transport: BluetoothTransport, callback: AsyncCallback<void>): void

Pairs a trusted device whose address is obtained in a non-Bluetooth scan mode (such as using NFC). 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

NameTypeMandatoryDescription
deviceIdstringYesAddress of the device to pair, for example, XX:XX:XX:XX:XX:XX.
transportBluetoothTransportYesDevice type, for example, a classic Bluetooth device or a Bluetooth low energy (BLE) device.
callbackAsyncCallback<void>YesCallback used 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.

IDError Message
201Permission denied.
202Non-system applications are not allowed to use system APIs.
401Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.
801Capability not supported.
2900001Service stopped.
2900003Bluetooth disabled.
2900099Operation failed.

Example

import { AsyncCallback, BusinessError } from '@kit.BasicServicesKit';
try {
    connection.pairCredibleDevice('68:13:24:79:4C:8C', connection.BluetoothTransport
        .TRANSPORT_BR_EDR, (err: BusinessError) => {
        if (err) {
            console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
            return;
        }
        console.info('pairCredibleDevice, err: ' + JSON.stringify(err));
    });
} catch (err) {
    console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
}

connection.pairCredibleDevice

pairCredibleDevice(deviceId: string, transport: BluetoothTransport): Promise<void>

Pairs a trusted device whose address is obtained in a non-Bluetooth scan mode (such as using NFC). 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

NameTypeMandatoryDescription
deviceIdstringYesAddress of the device to pair, for example, XX:XX:XX:XX:XX:XX.
transportBluetoothTransportYesDevice type, for example, a classic Bluetooth device or a BLE device.

Return value

TypeDescription
Promise<void>Promise used to return the result.

Error codes

For details about the error codes, see Bluetooth Error Codes.

IDError Message
201Permission denied.
202Non-system applications are not allowed to use system APIs.
401Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.
801Capability not supported.
2900001Service stopped.
2900003Bluetooth disabled.
2900099Operation failed.

Example

import { AsyncCallback, BusinessError } from '@kit.BasicServicesKit';
try {
    connection.pairCredibleDevice('68:13:24:79:4C:8C', 0).then(() => {
        console.info('PairCredibleDevice');
    }, (err: BusinessError) => {
        console.error('PairCredibleDevice:errCode' + err.code + ', errMessage: ' + err.message);
    });
} catch (err) {
    console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
}

connection.cancelPairedDevice

cancelPairedDevice(deviceId: string, callback: AsyncCallback<void>): void

Cancels a paired device. This API uses an asynchronous callback to return the result.

System API: This is a system API.

Required permissions: ohos.permission.ACCESS_BLUETOOTH

System capability: SystemCapability.Communication.Bluetooth.Core

Parameters

NameTypeMandatoryDescription
deviceIdstringYesAddress of the device to cancel, for example, XX:XX:XX:XX:XX:XX.
callbackAsyncCallback<void>YesCallback used 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.

IDError Message
201Permission denied.
202Non-system applications are not allowed to use system APIs.
401Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.
801Capability not supported.
2900001Service stopped.
2900003Bluetooth disabled.
2900099Operation failed.

Example

import { AsyncCallback, BusinessError } from '@kit.BasicServicesKit';
// callback
try {
    connection.cancelPairedDevice('11:22:33:44:55:66', (err: BusinessError) => {
        console.info('cancelPairedDevice, device name err:' + JSON.stringify(err));
    });
} catch (err) {
    console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
}

connection.cancelPairedDevice

cancelPairedDevice(deviceId: string): Promise<void>

Cancels a paired device. This API uses a promise to return the result.

System API: This is a system API.

Required permissions: ohos.permission.ACCESS_BLUETOOTH

System capability: SystemCapability.Communication.Bluetooth.Core

Parameters

NameTypeMandatoryDescription
deviceIdstringYesAddress of the device to cancel, for example, XX:XX:XX:XX:XX:XX.

Return value

TypeDescription
Promise<void>Promise used to return the result.

Error codes

For details about the error codes, see Bluetooth Error Codes.

IDError Message
201Permission denied.
202Non-system applications are not allowed to use system APIs.
401Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.
801Capability not supported.
2900001Service stopped.
2900003Bluetooth disabled.
2900099Operation failed.

Example

import { AsyncCallback, BusinessError } from '@kit.BasicServicesKit';
// promise
try {
    connection.cancelPairedDevice('11:22:33:44:55:66').then(() => {
        console.info('cancelPairedDevice');
    }, (error: BusinessError) => {
        console.info('cancelPairedDevice: errCode:' + error.code + ',errMessage' + error.message);
    })

} catch (err) {
    console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
}

connection.cancelPairingDevice

cancelPairingDevice(deviceId: string, callback: AsyncCallback<void>): void

Cancels the pairing of a device. This API uses an asynchronous callback to return the result.

System API: This is a system API.

Required permissions: ohos.permission.ACCESS_BLUETOOTH

System capability: SystemCapability.Communication.Bluetooth.Core

Parameters

NameTypeMandatoryDescription
deviceIdstringYesAddress of the device to cancel, for example, XX:XX:XX:XX:XX:XX.
callbackAsyncCallback<void>YesCallback used 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.

IDError Message
201Permission denied.
202Non-system applications are not allowed to use system APIs.
401Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.
801Capability not supported.
2900001Service stopped.
2900003Bluetooth disabled.
2900099Operation failed.

Example

import { AsyncCallback, BusinessError } from '@kit.BasicServicesKit';
try {
    connection.cancelPairingDevice('XX:XX:XX:XX:XX:XX');
} catch (err) {
    console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
}

connection.cancelPairingDevice

cancelPairingDevice(deviceId: string): Promise<void>

Cancels the pairing of a device. This API uses a promise to return the result.

System API: This is a system API.

Required permissions: ohos.permission.ACCESS_BLUETOOTH

System capability: SystemCapability.Communication.Bluetooth.Core

Parameters

NameTypeMandatoryDescription
deviceIdstringYesAddress of the device to cancel, for example, XX:XX:XX:XX:XX:XX.

Return value

TypeDescription
Promise<void>Promise used to return the result.

Error codes

For details about the error codes, see Bluetooth Error Codes.

IDError Message
201Permission denied.
202Non-system applications are not allowed to use system APIs.
401Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.
801Capability not supported.
2900001Service stopped.
2900003Bluetooth disabled.
2900099Operation failed.

Example

import { AsyncCallback, BusinessError } from '@kit.BasicServicesKit';
try {
    connection.cancelPairingDevice('XX:XX:XX:XX:XX:XX');
} catch (err) {
    console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
}

connection.getLocalProfileUuids

getLocalProfileUuids(callback: AsyncCallback<Array<ProfileUuids>>): void

Obtains the profile UUIDs of the local device. This API uses an asynchronous callback to return the result.

System API: This is a system API.

Required permissions: ohos.permission.ACCESS_BLUETOOTH

System capability: SystemCapability.Communication.Bluetooth.Core

Parameters

NameTypeMandatoryDescription
callbackAsyncCallback<Array<ProfileUuids>>YesCallback used to return the profile UUIDs obtained. 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.

IDError Message
201Permission denied.
202Non-system applications are not allowed to use system APIs.
401Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.
801Capability not supported.
2900001Service stopped.
2900003Bluetooth disabled.
2900099Operation failed.

Example

import { AsyncCallback, BusinessError } from '@kit.BasicServicesKit';
try {
    connection.getLocalProfileUuids((err: BusinessError, data: Array<connection.ProfileUuids>) => {
        console.info('getLocalProfileUuids, err: ' + JSON.stringify(err) + ', data: ' + JSON.stringify(data));
    });
} catch (err) {
    console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
}

connection.getLocalProfileUuids

getLocalProfileUuids(): Promise<Array<ProfileUuids>>

Obtains the profile UUIDs of the local device. This API uses a promise to return the result.

System API: This is a system API.

Required permissions: ohos.permission.ACCESS_BLUETOOTH

System capability: SystemCapability.Communication.Bluetooth.Core

Return value

TypeDescription
Promise<Array<ProfileUuids>>Promise used to return the result.

Error codes

For details about the error codes, see Bluetooth Error Codes.

IDError Message
201Permission denied.
202Non-system applications are not allowed to use system APIs.
401Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.
801Capability not supported.
2900001Service stopped.
2900003Bluetooth disabled.
2900099Operation failed.

Example

import { AsyncCallback, BusinessError } from '@kit.BasicServicesKit';
try {
    connection.getLocalProfileUuids().then(() => {
        console.info('getLocalProfileUuids');
    }, (err: BusinessError) => {
        console.error('getLocalProfileUuids: errCode' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
    });
} catch (err) {
    console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
}

connection.disconnectAllowedProfiles11+

disconnectAllowedProfiles(deviceId: string, callback: AsyncCallback<void>): void

Disconnects all connected profiles for a remote 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

NameTypeMandatoryDescription
deviceIdstringYesAddress of the target remote device, for example, XX:XX:XX:XX:XX.
callbackAsyncCallback<void>YesCallback used 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.

IDError Message
201Permission denied.
202Non-system applications are not allowed to use system APIs.
401Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.
801Capability not supported.
2900001Service stopped.
2900003Bluetooth disabled.
2900099Operation failed.

Example

import { AsyncCallback, BusinessError } from '@kit.BasicServicesKit';
try {
    connection.disconnectAllowedProfiles('68:13:24:79:4C:8C', (err: BusinessError) => {
        if (err) {
            console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
            return;
        }
        console.info('disconnectAllowedProfiles, err: ' + JSON.stringify(err));
    });
} catch (err) {
    console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
}

connection.disconnectAllowedProfiles11+

disconnectAllowedProfiles(deviceId: string): Promise<void>

Disconnects all connected profiles for a remote 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

NameTypeMandatoryDescription
deviceIdstringYesAddress of the target remote device, for example, XX:XX:XX:XX:XX.

Return value

TypeDescription
Promise<void>Promise used to return the result. If the operation is successful, true is returned; otherwise, false is returned.

Error codes

For details about the error codes, see Bluetooth Error Codes.

IDError Message
201Permission denied.
202Non-system applications are not allowed to use system APIs.
401Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.
801Capability not supported.
2900001Service stopped.
2900003Bluetooth disabled.
2900099Operation failed.

Example

import { AsyncCallback, BusinessError } from '@kit.BasicServicesKit';
try {
    connection.disconnectAllowedProfiles('68:13:24:79:4C:8C').then(() => {
        console.info('disconnectAllowedProfiles');
    }, (err: BusinessError) => {
        console.error('disconnectAllowedProfiles:errCode' + err.code + ', errMessage: ' + err.message);
    });
} catch (err) {
    console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
}

connection.getRemoteProductId11+

getRemoteProductId(deviceId: string): string

Obtains the product ID of a remote Bluetooth device. Since API version 16, the ohos.permission.ACCESS_BLUETOOTH and ohos.permission.MANAGE_BLUETOOTH permissions are no longer verified.

System API: This is a system API.

System capability: SystemCapability.Communication.Bluetooth.Core

Parameters

NameTypeMandatoryDescription
deviceIdstringYesAddress of the remote device, for example, XX:XX:XX:XX:XX:XX.

Return value

TypeDescription
stringProduct ID obtained.

Error codes

For details about the error codes, see Bluetooth Error Codes.

IDError Message
202Non-system applications are not allowed to use system APIs.
401Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.
801Capability not supported.
2900001Service stopped.
2900003Bluetooth disabled.
2900099Operation failed.

Example

try {
  let remoteDeviceProductId = connection.getRemoteProductId('XX:XX:XX:XX:XX:XX');
} catch (err) {
  console.error('errCode: ' + err.code + ', errMessage: ' + err.message);
}

connection.setRemoteDeviceType12+

setRemoteDeviceType(deviceId: string, type: DeviceType): Promise<void>

Sets the type of a remote Bluetooth device. This API uses a promise to return the result.

System API: This is a system API.

Required permissions: ohos.permission.ACCESS_BLUETOOTH

System capability: SystemCapability.Communication.Bluetooth.Core

Parameters

NameTypeMandatoryDescription
deviceIdstringYesMAC address of the remote device, for example, XX:XX:XX:XX:XX:XX.
typeDeviceTypeYesDevice type to set.

Return value

TypeDescription
Promise<void>Promise used to return the device type set. If the operation fails, an error code is returned.

Error codes

For details about the error codes, see Bluetooth Error Codes.

IDError Message
201Permission denied.
401Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.
2900001Service stopped.
2900003Bluetooth disabled.

Example

import { AsyncCallback, BusinessError } from '@kit.BasicServicesKit';
// promise
try {
    connection.setRemoteDeviceType('11:22:33:44:55:66', connection.DeviceType.DEVICE_TYPE_HEADSET).then(() => {
        console.info('setRemoteDeviceType success');
    });
} catch (err) {
    console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
}

connection.getRemoteDeviceType12+

getRemoteDeviceType(deviceId: string): Promise<DeviceType>

Obtains the type of a remote Bluetooth device. This API uses a promise to return the result. Since API version 18, the ohos.permission.ACCESS_BLUETOOTH permission is no longer verified.

System API: This is a system API.

System capability: SystemCapability.Communication.Bluetooth.Core

Parameters

NameTypeMandatoryDescription
deviceIdstringYesMAC address of the remote device, for example, XX:XX:XX:XX:XX:XX.

Return value

TypeDescription
Promise<DeviceType>Promise used to return the device type obtained.

Error codes

For details about the error codes, see Bluetooth Error Codes.

IDError Message
202Non-system applications are not allowed to use system APIs.
401Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.
2900001Service stopped.
2900003Bluetooth disabled.

Example

import { AsyncCallback, BusinessError } from '@kit.BasicServicesKit';
// promise
try {
    connection.getRemoteDeviceType('11:22:33:44:55:66').then((data: connection.DeviceType) => {
        console.info('getRemoteDeviceType success, DeviceType:' + JSON.stringify(data));
    });
} catch (err) {
    console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
}

connection.controlDeviceAction15+

controlDeviceAction(controlDeviceActionParams: ControlDeviceActionParams): Promise<void>

Sends a control command to Bluetooth headsets during scanning. This API uses a promise to return the result.

Required permissions: ohos.permission.ACCESS_BLUETOOTH and ohos.permission.MANAGE_BLUETOOTH (available only for system applications)

System capability: SystemCapability.Communication.Bluetooth.Core

Parameters

NameTypeMandatoryDescription
controlDeviceActionParams15+ControlDeviceActionParamsYesBluetooth peripheral control information.

Return value

TypeDescription
Promise<void>Promise used to return the result.

Error codes

For details about the error codes, see Universal Error Codes and Bluetooth Error Codes.

IDError Message
201Permission denied.
202Non-system applications are not allowed to use system APIs.
401Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.
801Capability not supported.
2900001Service stopped.
2900003Bluetooth disabled.
2900099Operation failed.

Example

import { AsyncCallback, BusinessError } from '@kit.BasicServicesKit';
try {
    let controlDeviceActionParams: connection.ControlDeviceActionParams = {
        deviceId: '40:DC:A5:E5:75:C3',
        type: connection.ControlType.PLAY,
        typeValue: connection.ControlTypeValue.ENABLE,
        controlObject: connection.ControlObject.LEFT_EAR
    };
    connection.controlDeviceAction(controlDeviceActionParams).then(() => {
        console.info('controlDeviceAction success');
    }, (err: BusinessError) => {
        console.error('controlDeviceAction: errCode' + err.code + ', errMessage: ' + err.message);
    });
} catch (err) {
    console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
}

connection.updateCloudBluetoothDevice15+

updateCloudBluetoothDevice(trustedPairedDevices: TrustedPairedDevices): Promise<void>

Updates cloud devices in Bluetooth settings. 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

NameTypeMandatoryDescription
trustedPairedDevicesTrustedPairedDevicesYesCloud device list.

Return value

TypeDescription
Promise<void>Promise used to return the result. If the setting fails, an error code is returned.

Error codes

For details about the error codes, see Universal Error Codes and Bluetooth Error Codes.

IDError Message
201Permission denied.
202Non-system applications are not allowed to use system APIs.
401Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.
801Capability not supported.
2900001Service stopped.
2900003Bluetooth disabled.
2900099Operation failed.

Example

import { connection } from '@kit.ConnectivityKit';
// promise
/**
 * Update cloud devices in Bluetooth settings.
 */
public updateCloudBluetoothDevice() {
    const trustPairDeviceArr: connection.TrustedPairedDevice[] = [];
    let descBuffer = new ArrayBuffer(1);
    trustPairDeviceArr.push({
        sn: '',
        deviceType: '',
        modelId: '',
        manufactory: '',
        productId: '',
        hiLinkVersion: '',
        macAddress: '11:22:33:44:55:66',
        serviceType: '',
        serviceId: '',
        deviceName: '',
        uuids: '',
        bluetoothClass: 0,
        token: descBuffer,
        deviceNameTime: 0,
        secureAdvertisingInfo: descBuffer,
        pairState: 0
        });
    const trustPairDevices: connection.TrustedPairedDevices = { trustedPairedDevices: trustPairDeviceArr };
    try {
        connection.updateCloudBluetoothDevice(trustPairDevices)
            .then(() => {
                console.info('updateCloudBluetoothDevice success!');
            })
            .catch((err: BusinessError) => {
                console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
            });
    } catch (err) {
        console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
    }
}

PinRequiredParam

Represents the pairing request parameters.

System capability: SystemCapability.Communication.Bluetooth.Core

NameTypeReadableWritableDescription
pinTypePinTypeYesNoType of the device to pair.
This is a system API.

ControlDeviceActionParams15+

Defines the configuration parameters of the control command.

System capability: SystemCapability.Communication.Bluetooth.Core

NameTypeReadableWritableDescription
deviceIdstringYesNoDevice ID.
typeControlTypeYesNoControl type.
typeValueControlTypeValueYesNoControl action.
controlObjectControlObjectYesNoControl object.

PinType

Enumerates the Bluetooth pairing types.

System API: This is a system API.

System capability: SystemCapability.Communication.Bluetooth.Core

NameValueDescription
PIN_TYPE_ENTER_PIN_CODE0The user needs to enter the PIN displayed on the peer device.
This is a system API.
PIN_TYPE_ENTER_PASSKEY1The user needs to enter the PASSKEY displayed on the peer device.
This is a system API.
PIN_TYPE_CONFIRM_PASSKEY2The user needs to confirm the PASSKEY displayed on the local device.
This is a system API.
PIN_TYPE_NO_PASSKEY_CONSENT3There is no PASSKEY, and the user needs to accept or reject the pairing request.
This is a system API.
PIN_TYPE_NOTIFY_PASSKEY4The user needs to enter the PASSKEY displayed on the local device on the peer device.
This is a system API.
PIN_TYPE_DISPLAY_PIN_CODE5The user needs to enter the PIN displayed on the peer device for Bluetooth 2.0 devices.
This is a system API.
PIN_TYPE_OOB_CONSENT6The user needs to accept or reject the out of band (OOB) pairing request.
This is a system API.
PIN_TYPE_PIN_16_DIGITS7The user needs to enter the 16-digit PIN displayed on the peer device.
This is a system API.

DeviceType12+

Enumerates the custom types of a remote Bluetooth device.

System API: This is a system API.

System capability: SystemCapability.Communication.Bluetooth.Core

NameValueDescription
DEVICE_TYPE_DEFAULT12+0Default device type, which is the same as the original type.
This is a system API.
DEVICE_TYPE_CAR12+1Car.
This is a system API.
DEVICE_TYPE_HEADSET12+2Headset.
This is a system API.
DEVICE_TYPE_HEARING12+3Hearing aid.
This is a system API.
DEVICE_TYPE_GLASSES12+4Glasses.
This is a system API.
DEVICE_TYPE_WATCH12+5Watch.
This is a system API.
DEVICE_TYPE_SPEAKER12+6Speaker.
This is a system API.
DEVICE_TYPE_OTHERS12+7Other device.
This is a system API.

BatteryInfo12+

Represents the battery information.

System capability: SystemCapability.Communication.Bluetooth.Core

NameTypeReadableWritableDescription
deviceIdstringYesNoMAC address of the remote device.
This is a system API.

ControlType15+

Enumerates control types.

System capability: SystemCapability.Communication.Bluetooth.Core

NameValueDescription
PLAY0Play
VIBRATE1Vibration
FLASH2Flash
LOCK3Lock

ControlTypeValue15+

Enumerates control actions.

System capability: SystemCapability.Communication.Bluetooth.Core

NameValueDescription
DISABLE0Disable
ENABLE1Enable
QUERY2Query

ControlObject15+

Enumerates control objects.

System capability: SystemCapability.Communication.Bluetooth.Core

NameValueDescription
LEFT_EAR0Left earbud.
RIGHT_EAR1Right earbud.
LEFT_RIGHT_EAR2Left and right earbuds.

TrustedPairedDevices15+

Defines the cloud device list.

System capability: SystemCapability.Communication.Bluetooth.Core

NameTypeReadableOptionalDescription
trustedPairedDevicesArray<TrustedPairedDevice>YesNoCloud device list.

TrustedPairedDevice15+

Defines the cloud device information.

System capability: SystemCapability.Communication.Bluetooth.Core

NameTypeReadableOptionalDescription
snstringYesNoDevice SN.
deviceTypestringYesNoDevice type to set.
modelIdstringYesNoCharging state of the left earbud.
manufactorystringYesNoManufacturer information.
productIdstringYesNoProduct information.
hiLinkVersionstringYesNoHiLink version.
macAddressstringYesNoMAC address.
serviceTypestringYesNoService type.
serviceIdstringYesNoDevice ID.
deviceNamestringYesNoDevice name.
uuidsstringYesNoDevice UUID.
bluetoothClassnumberYesNoPeer device type.
tokenArrayBufferYesNoDevice token information.
deviceNameTimenumberYesNoDevice name modification time.
secureAdvertisingInfoArrayBufferYesNoDevice advertising information.
pairStatenumberYesNoDevice pairing status.

你可能感兴趣的鸿蒙文章

harmony 鸿蒙Connectivity Kit (Short-Range Communication Service)

harmony 鸿蒙Bluetooth

harmony 鸿蒙Wifi

harmony 鸿蒙Bluetooth Error Codes

harmony 鸿蒙NFC Error Codes

harmony 鸿蒙SecureElement Error Codes

harmony 鸿蒙Wi-Fi Error Codes

harmony 鸿蒙@ohos.bluetooth.a2dp (Bluetooth A2DP Module) (System API)

harmony 鸿蒙@ohos.bluetooth.a2dp (Bluetooth A2DP Module)

harmony 鸿蒙@ohos.bluetooth.access (Bluetooth Access Module) (System API)

  • 所属分类: 后端技术
  • 本文标签: 鸿蒙 软件
  • 版权声明: 本文链接 https://seaxiang.com/blog/iJKi4S