35edd163创建于 2025年10月21日历史提交

@ohos.bluetooth.hfp (Bluetooth HFP Module)

The hfp module provides the Bluetooth call audio capability based on the Hands-Free Profile (HFP)), such as obtaining the call audio connection 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

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

BaseProfile

type BaseProfile = baseProfile.BaseProfile

BaseProfile class, which provides public capabilities such as obtaining the connection status and listening for connection status changes.

System capability: SystemCapability.Communication.Bluetooth.Core

Type Description
baseProfile.BaseProfile BaseProfile API definition.

hfp.createHfpAgProfile

createHfpAgProfile(): HandsFreeAudioGatewayProfile

Creates an HFP AG instance. Through this instance, you can use the local device as the HFP AG and implement functions such as obtaining the Bluetooth call audio connection status.

System capability: SystemCapability.Communication.Bluetooth.Core

Return value

Type Description
HandsFreeAudioGatewayProfile HFP AG instance.

Error codes

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

ID Error Message
401 Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.
801 Capability not supported.

Example

import { BusinessError } from '@kit.BasicServicesKit';

try {
    let hfpAgProfile = hfp.createHfpAgProfile();
    console.info('hfpAg success');
} catch (err) {
    console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
}

HandsFreeAudioGatewayProfile

Represents the HFP AG role in Bluetooth call audio.

  • The HandsFreeAudioGatewayProfile class is inherited from BaseProfile. Therefore, you can use the APIs in its parent class.
  • Before using the APIs of this class, you need to construct an HFP AG instance by calling createHfpAgProfile.
  • The counterpart of the HFP AG role is the HF role.