目录

@ohos.bluetooth.pbap (蓝牙pbap模块)

本模块提供基于电话簿访问协议(Phone Book Access Profile,PBAP)的蓝牙电话簿访问能力,支持创建PSE服务端实例、获取设备间蓝牙电话簿服务连接状态等,适用于本端设备作为PSE对外提供电话簿访问服务的场景,可帮助开发者快速实现蓝牙电话簿的共享与连接管理功能。

本模块首批接口从API version 11开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。

导入模块

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

BaseProfile

type BaseProfile = baseProfile.BaseProfile

基础Profile接口定义,提供订阅和获取连接状态等公共能力。

系统能力:SystemCapability.Communication.Bluetooth.Core。

类型 说明
baseProfile.BaseProfile 基础Profile接口定义。

pbap.createPbapServerProfile

createPbapServerProfile(): PbapServerProfile

创建蓝牙电话簿访问协议中的PSE实例。通过该实例可使用本端作为PSE设备的接口,如:获取本端和其他设备间的蓝牙电话簿服务连接状态。典型使用场景包括:车载蓝牙系统访问手机电话簿、跨设备联系人同步等需要本端作为电话簿服务端的场景。

系统能力:SystemCapability.Communication.Bluetooth.Core。

返回值:

类型 说明
PbapServerProfile

返回PSE实例。

- 该类继承于BaseProfile,因此可以使用其父类中的方法。

- 和该实例角色相对应的是PCE角色。

错误码:

以下错误码的详细介绍请参见通用错误码说明文档。

错误码ID 错误信息
401 Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.
801 Capability not supported.

示例:

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

try {
    let pbapServerProfile = pbap.createPbapServerProfile();
    console.info('pbapServer success');
} catch (err) {
    console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
}

pbap.createPbapClientProfile

createPbapClientProfile(): PbapClientProfile

创建蓝牙电话簿访问协议中的PCE实例。通过该实例可使用本端作为PCE设备时提供的接口,如:获取电话簿同步状态、订阅电话簿同步状态变化事件等。典型使用场景包括:车载蓝牙系统作为PCE访问手机电话簿、跨设备联系人同步等。

起始版本: 26.0.1

系统能力:SystemCapability.Communication.Bluetooth.Core

模型约束:此接口仅可在Stage模型下使用。

返回值:

类型 说明
PbapClientProfile

返回PCE实例。

- 该类继承于BaseProfile,因此可以使用其父类中的方法。

- 和该实例角色相对应的是PSE角色。

错误码:

以下错误码的详细介绍请参见通用错误码说明文档。

错误码ID 错误信息
801 Capability not supported. Possible causes: 1. The hardware does not support the capability; 2. The chip does not support the capability; 3. A dependent service feature is not supported.

示例:

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

try {
    let pbapClientProfile = pbap.createPbapClientProfile();
    console.info('pbapClient success');
} catch (err) {
    console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
}