1e41f4b71Sopenharmony_ci# @ohos.bluetooth.pbap (蓝牙pbap模块)(系统接口)
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_cipbap模块提供了访问电话簿相关功能的方法。
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ci> **说明:**
6e41f4b71Sopenharmony_ci>
7e41f4b71Sopenharmony_ci> 本模块首批接口从API version 11开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
8e41f4b71Sopenharmony_ci> 当前页面仅包含本模块的系统接口,其他公开接口参见[@ohos.bluetooth.pbap (蓝牙pbap模块)](js-apis-bluetooth-pbap.md)
9e41f4b71Sopenharmony_ci
10e41f4b71Sopenharmony_ci
11e41f4b71Sopenharmony_ci## 导入模块
12e41f4b71Sopenharmony_ci
13e41f4b71Sopenharmony_ci```js
14e41f4b71Sopenharmony_ciimport { pbap } from '@kit.ConnectivityKit';
15e41f4b71Sopenharmony_ci```
16e41f4b71Sopenharmony_ci
17e41f4b71Sopenharmony_ci## PbapServerProfile
18e41f4b71Sopenharmony_ci
19e41f4b71Sopenharmony_ci使用PbapServerProfile方法之前需要创建该类的实例进行操作,通过createPbapServerProfile()方法构造此实例。
20e41f4b71Sopenharmony_ci
21e41f4b71Sopenharmony_ci### disconnect
22e41f4b71Sopenharmony_ci
23e41f4b71Sopenharmony_cidisconnect(deviceId: string): void
24e41f4b71Sopenharmony_ci
25e41f4b71Sopenharmony_ci断开连接设备的Pbap服务。
26e41f4b71Sopenharmony_ci
27e41f4b71Sopenharmony_ci**系统接口**:此接口为系统接口。
28e41f4b71Sopenharmony_ci
29e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.ACCESS_BLUETOOTH
30e41f4b71Sopenharmony_ci
31e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Communication.Bluetooth.Core32e41f4b71Sopenharmony_ci
33e41f4b71Sopenharmony_ci**参数:**
34e41f4b71Sopenharmony_ci
35e41f4b71Sopenharmony_ci| 参数名    | 类型     | 必填   | 说明      |
36e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ------- |
37e41f4b71Sopenharmony_ci| deviceId | string | 是    | 远端设备地址。 |
38e41f4b71Sopenharmony_ci
39e41f4b71Sopenharmony_ci**错误码**:
40e41f4b71Sopenharmony_ci
41e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
42e41f4b71Sopenharmony_ci
43e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 |
44e41f4b71Sopenharmony_ci| -------- | ---------------------------- |
45e41f4b71Sopenharmony_ci|201 | Permission denied.                 |
46e41f4b71Sopenharmony_ci|202 | Non-system applications are not allowed to use system APIs. |
47e41f4b71Sopenharmony_ci|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.                 |
48e41f4b71Sopenharmony_ci|801 | Capability not supported.          |
49e41f4b71Sopenharmony_ci|2900001 | Service stopped.                         |
50e41f4b71Sopenharmony_ci|2900003 | Bluetooth disabled.                 |
51e41f4b71Sopenharmony_ci|2900004 | Profile not supported.                |
52e41f4b71Sopenharmony_ci|2900099 | Operation failed.                        |
53e41f4b71Sopenharmony_ci
54e41f4b71Sopenharmony_ci**示例:**
55e41f4b71Sopenharmony_ci
56e41f4b71Sopenharmony_ci```js
57e41f4b71Sopenharmony_ciimport { AsyncCallback, BusinessError } from '@kit.BasicServicesKit';
58e41f4b71Sopenharmony_citry {
59e41f4b71Sopenharmony_ci    let pbapServerProfile = pbap.createPbapServerProfile();
60e41f4b71Sopenharmony_ci    pbapServerProfile.disconnect('XX:XX:XX:XX:XX:XX');
61e41f4b71Sopenharmony_ci} catch (err) {
62e41f4b71Sopenharmony_ci    console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
63e41f4b71Sopenharmony_ci}
64e41f4b71Sopenharmony_ci```
65e41f4b71Sopenharmony_ci
66e41f4b71Sopenharmony_ci### setShareType
67e41f4b71Sopenharmony_ci
68e41f4b71Sopenharmony_cisetShareType(deviceId: string, type: ShareType, callback: AsyncCallback<void>): void
69e41f4b71Sopenharmony_ci
70e41f4b71Sopenharmony_ci设置电话簿信息的共享类型。使用Callback异步回调。
71e41f4b71Sopenharmony_ci
72e41f4b71Sopenharmony_ci**系统接口**:此接口为系统接口。
73e41f4b71Sopenharmony_ci
74e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.ACCESS_BLUETOOTHohos.permission.MANAGE_BLUETOOTH
75e41f4b71Sopenharmony_ci
76e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Communication.Bluetooth.Core77e41f4b71Sopenharmony_ci
78e41f4b71Sopenharmony_ci**参数:**
79e41f4b71Sopenharmony_ci
80e41f4b71Sopenharmony_ci| 参数名      | 类型     | 必填   | 说明                                  |
81e41f4b71Sopenharmony_ci| -------- | ------ | ---- | ----------------------------------- |
82e41f4b71Sopenharmony_ci| deviceId | string | 是    | 表示远端设备地址,例如:"XX:XX:XX:XX:XX:XX"。 |
83e41f4b71Sopenharmony_ci| type | [ShareType](#sharetype) | 是    | 表示共享类型的枚举值。 |
84e41f4b71Sopenharmony_ci| callback | AsyncCallback<void> | 是    | 回调函数。当设置成功,err为undefined,否则为错误对象。   |
85e41f4b71Sopenharmony_ci
86e41f4b71Sopenharmony_ci**错误码**:
87e41f4b71Sopenharmony_ci
88e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
89e41f4b71Sopenharmony_ci
90e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 |
91e41f4b71Sopenharmony_ci| -------- | ---------------------------- |
92e41f4b71Sopenharmony_ci|201 | Permission denied.                 |
93e41f4b71Sopenharmony_ci|202 | Non-system applications are not allowed to use system APIs. |
94e41f4b71Sopenharmony_ci|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.                 |
95e41f4b71Sopenharmony_ci|801 | Capability not supported.          |
96e41f4b71Sopenharmony_ci|2900001 | Service stopped.                         |
97e41f4b71Sopenharmony_ci|2900003 | Bluetooth disabled.                 |
98e41f4b71Sopenharmony_ci|2900004 | Profile not supported.                |
99e41f4b71Sopenharmony_ci|2900099 | Operation failed.                        |
100e41f4b71Sopenharmony_ci
101e41f4b71Sopenharmony_ci**示例:**
102e41f4b71Sopenharmony_ci
103e41f4b71Sopenharmony_ci```js
104e41f4b71Sopenharmony_ciimport { AsyncCallback, BusinessError } from '@kit.BasicServicesKit';
105e41f4b71Sopenharmony_citry {
106e41f4b71Sopenharmony_ci    let pbapServerProfile = pbap.createPbapServerProfile();
107e41f4b71Sopenharmony_ci    pbapServerProfile.setShareType('XX:XX:XX:XX:XX:XX', 0, (err: BusinessError) => {
108e41f4b71Sopenharmony_ci       console.info('setShareType'); 
109e41f4b71Sopenharmony_ci    });
110e41f4b71Sopenharmony_ci} catch (err) {
111e41f4b71Sopenharmony_ci    console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
112e41f4b71Sopenharmony_ci}
113e41f4b71Sopenharmony_ci```
114e41f4b71Sopenharmony_ci
115e41f4b71Sopenharmony_ci
116e41f4b71Sopenharmony_ci### setShareType
117e41f4b71Sopenharmony_ci
118e41f4b71Sopenharmony_cisetShareType(deviceId: string, type: ShareType): Promise<void>
119e41f4b71Sopenharmony_ci
120e41f4b71Sopenharmony_ci设置电话簿信息的共享类型。使用Promise异步回调。
121e41f4b71Sopenharmony_ci
122e41f4b71Sopenharmony_ci**系统接口**:此接口为系统接口。
123e41f4b71Sopenharmony_ci
124e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.ACCESS_BLUETOOTHohos.permission.MANAGE_BLUETOOTH
125e41f4b71Sopenharmony_ci
126e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Communication.Bluetooth.Core127e41f4b71Sopenharmony_ci
128e41f4b71Sopenharmony_ci**参数:**
129e41f4b71Sopenharmony_ci
130e41f4b71Sopenharmony_ci| 参数名      | 类型     | 必填   | 说明                                  |
131e41f4b71Sopenharmony_ci| -------- | ------ | ---- | ----------------------------------- |
132e41f4b71Sopenharmony_ci| deviceId | string | 是    | 表示远端设备地址,例如:"XX:XX:XX:XX:XX:XX"。 |
133e41f4b71Sopenharmony_ci| type | [ShareType](#sharetype) | 是    | 表示共享类型的枚举值。 |
134e41f4b71Sopenharmony_ci
135e41f4b71Sopenharmony_ci**返回值:**
136e41f4b71Sopenharmony_ci
137e41f4b71Sopenharmony_ci| 类型                                              | 说明                |
138e41f4b71Sopenharmony_ci| ------------------------------------------------- | ------------------- |
139e41f4b71Sopenharmony_ci| Promise<void> | 以Promise的形式返回结果。如果成功,err为undefined的,否则为错误对象。 |
140e41f4b71Sopenharmony_ci
141e41f4b71Sopenharmony_ci**错误码**:
142e41f4b71Sopenharmony_ci
143e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
144e41f4b71Sopenharmony_ci
145e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 |
146e41f4b71Sopenharmony_ci| -------- | ---------------------------- |
147e41f4b71Sopenharmony_ci|201 | Permission denied.                 |
148e41f4b71Sopenharmony_ci|202 | Non-system applications are not allowed to use system APIs. |
149e41f4b71Sopenharmony_ci|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.                 |
150e41f4b71Sopenharmony_ci|801 | Capability not supported.          |
151e41f4b71Sopenharmony_ci|2900001 | Service stopped.                         |
152e41f4b71Sopenharmony_ci|2900003 | Bluetooth disabled.                 |
153e41f4b71Sopenharmony_ci|2900004 | Profile not supported.                |
154e41f4b71Sopenharmony_ci|2900099 | Operation failed.                        |
155e41f4b71Sopenharmony_ci
156e41f4b71Sopenharmony_ci**示例:**
157e41f4b71Sopenharmony_ci
158e41f4b71Sopenharmony_ci```js
159e41f4b71Sopenharmony_ciimport { AsyncCallback, BusinessError } from '@kit.BasicServicesKit';
160e41f4b71Sopenharmony_citry {
161e41f4b71Sopenharmony_ci    let pbapServerProfile = pbap.createPbapServerProfile();
162e41f4b71Sopenharmony_ci    pbapServerProfile.setShareType('XX:XX:XX:XX:XX:XX', 0).then(() => {
163e41f4b71Sopenharmony_ci        console.info('setShareType');
164e41f4b71Sopenharmony_ci    });
165e41f4b71Sopenharmony_ci} catch (err) {
166e41f4b71Sopenharmony_ci    console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
167e41f4b71Sopenharmony_ci}
168e41f4b71Sopenharmony_ci```
169e41f4b71Sopenharmony_ci
170e41f4b71Sopenharmony_ci### getShareType
171e41f4b71Sopenharmony_ci
172e41f4b71Sopenharmony_cigetShareType(deviceId: string, callback: AsyncCallback<ShareType>): void
173e41f4b71Sopenharmony_ci
174e41f4b71Sopenharmony_ci获取电话簿信息的共享类型。使用Callback异步回调。
175e41f4b71Sopenharmony_ci
176e41f4b71Sopenharmony_ci**系统接口**:此接口为系统接口。
177e41f4b71Sopenharmony_ci
178e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.ACCESS_BLUETOOTHohos.permission.MANAGE_BLUETOOTH
179e41f4b71Sopenharmony_ci
180e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Communication.Bluetooth.Core181e41f4b71Sopenharmony_ci
182e41f4b71Sopenharmony_ci**参数:**
183e41f4b71Sopenharmony_ci
184e41f4b71Sopenharmony_ci| 参数名      | 类型     | 必填   | 说明                                  |
185e41f4b71Sopenharmony_ci| -------- | ------ | ---- | ----------------------------------- |
186e41f4b71Sopenharmony_ci| deviceId | string | 是    | 表示远端设备地址,例如:"XX:XX:XX:XX:XX:XX"。 |
187e41f4b71Sopenharmony_ci| callback | AsyncCallback<[ShareType](#sharetype)> | 是    | 回调函数。当获取成功,err为undefined,否则为错误对象。   |
188e41f4b71Sopenharmony_ci
189e41f4b71Sopenharmony_ci**错误码**:
190e41f4b71Sopenharmony_ci
191e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
192e41f4b71Sopenharmony_ci
193e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 |
194e41f4b71Sopenharmony_ci| -------- | ---------------------------- |
195e41f4b71Sopenharmony_ci|201 | Permission denied.                 |
196e41f4b71Sopenharmony_ci|202 | Non-system applications are not allowed to use system APIs. |
197e41f4b71Sopenharmony_ci|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.                 |
198e41f4b71Sopenharmony_ci|801 | Capability not supported.          |
199e41f4b71Sopenharmony_ci|2900001 | Service stopped.                         |
200e41f4b71Sopenharmony_ci|2900003 | Bluetooth disabled.                 |
201e41f4b71Sopenharmony_ci|2900004 | Profile not supported.                |
202e41f4b71Sopenharmony_ci|2900099 | Operation failed.                        |
203e41f4b71Sopenharmony_ci
204e41f4b71Sopenharmony_ci**示例:**
205e41f4b71Sopenharmony_ci
206e41f4b71Sopenharmony_ci```js
207e41f4b71Sopenharmony_ciimport { AsyncCallback, BusinessError } from '@kit.BasicServicesKit';
208e41f4b71Sopenharmony_citry {
209e41f4b71Sopenharmony_ci    let pbapServerProfile = pbap.createPbapServerProfile();
210e41f4b71Sopenharmony_ci    pbapServerProfile.getShareType('XX:XX:XX:XX:XX:XX', (err, type) => {
211e41f4b71Sopenharmony_ci        console.info('getShareType ' + type);
212e41f4b71Sopenharmony_ci    });
213e41f4b71Sopenharmony_ci} catch (err) {
214e41f4b71Sopenharmony_ci    console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
215e41f4b71Sopenharmony_ci}
216e41f4b71Sopenharmony_ci```
217e41f4b71Sopenharmony_ci
218e41f4b71Sopenharmony_ci### getShareType
219e41f4b71Sopenharmony_ci
220e41f4b71Sopenharmony_cigetShareType(deviceId: string): Promise<ShareType>
221e41f4b71Sopenharmony_ci
222e41f4b71Sopenharmony_ci获取电话簿信息的共享类型。使用Promise异步回调。
223e41f4b71Sopenharmony_ci
224e41f4b71Sopenharmony_ci**系统接口**:此接口为系统接口。
225e41f4b71Sopenharmony_ci
226e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.ACCESS_BLUETOOTHohos.permission.MANAGE_BLUETOOTH
227e41f4b71Sopenharmony_ci
228e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Communication.Bluetooth.Core229e41f4b71Sopenharmony_ci
230e41f4b71Sopenharmony_ci**参数:**
231e41f4b71Sopenharmony_ci
232e41f4b71Sopenharmony_ci| 参数名      | 类型     | 必填   | 说明                                  |
233e41f4b71Sopenharmony_ci| -------- | ------ | ---- | ----------------------------------- |
234e41f4b71Sopenharmony_ci| deviceId | string | 是    | 表示远端设备地址,例如:"XX:XX:XX:XX:XX:XX"。 |
235e41f4b71Sopenharmony_ci
236e41f4b71Sopenharmony_ci**返回值:**
237e41f4b71Sopenharmony_ci
238e41f4b71Sopenharmony_ci| 类型                                              | 说明                |
239e41f4b71Sopenharmony_ci| ------------------------------------------------- | ------------------- |
240e41f4b71Sopenharmony_ci| Promise<[ShareType](#sharetype)> | 以Promise的形式返回结果。如果成功,err为undefined的,否则为错误对象。 |
241e41f4b71Sopenharmony_ci
242e41f4b71Sopenharmony_ci**错误码**:
243e41f4b71Sopenharmony_ci
244e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
245e41f4b71Sopenharmony_ci
246e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 |
247e41f4b71Sopenharmony_ci| -------- | ---------------------------- |
248e41f4b71Sopenharmony_ci|201 | Permission denied.                 |
249e41f4b71Sopenharmony_ci|202 | Non-system applications are not allowed to use system APIs. |
250e41f4b71Sopenharmony_ci|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.                 |
251e41f4b71Sopenharmony_ci|801 | Capability not supported.          |
252e41f4b71Sopenharmony_ci|2900001 | Service stopped.                         |
253e41f4b71Sopenharmony_ci|2900003 | Bluetooth disabled.                 |
254e41f4b71Sopenharmony_ci|2900004 | Profile not supported.                |
255e41f4b71Sopenharmony_ci|2900099 | Operation failed.                        |
256e41f4b71Sopenharmony_ci
257e41f4b71Sopenharmony_ci**示例:**
258e41f4b71Sopenharmony_ci
259e41f4b71Sopenharmony_ci```js
260e41f4b71Sopenharmony_ciimport { AsyncCallback, BusinessError } from '@kit.BasicServicesKit';
261e41f4b71Sopenharmony_citry {
262e41f4b71Sopenharmony_ci    let pbapServerProfile = pbap.createPbapServerProfile();
263e41f4b71Sopenharmony_ci    pbapServerProfile.getShareType('XX:XX:XX:XX:XX:XX').then((type) => {
264e41f4b71Sopenharmony_ci        console.info('getShareType ' + type);
265e41f4b71Sopenharmony_ci    });
266e41f4b71Sopenharmony_ci} catch (err) {
267e41f4b71Sopenharmony_ci    console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
268e41f4b71Sopenharmony_ci}
269e41f4b71Sopenharmony_ci```
270e41f4b71Sopenharmony_ci
271e41f4b71Sopenharmony_ci### setPhoneBookAccessAuthorization
272e41f4b71Sopenharmony_ci
273e41f4b71Sopenharmony_cisetPhoneBookAccessAuthorization(deviceId: string, authorization: AccessAuthorization, callback: AsyncCallback<void>): void
274e41f4b71Sopenharmony_ci
275e41f4b71Sopenharmony_ci设置电话簿信息的访问权限。使用Callback异步回调。
276e41f4b71Sopenharmony_ci
277e41f4b71Sopenharmony_ci**系统接口**:此接口为系统接口。
278e41f4b71Sopenharmony_ci
279e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.ACCESS_BLUETOOTHohos.permission.MANAGE_BLUETOOTH
280e41f4b71Sopenharmony_ci
281e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Communication.Bluetooth.Core282e41f4b71Sopenharmony_ci
283e41f4b71Sopenharmony_ci**参数:**
284e41f4b71Sopenharmony_ci
285e41f4b71Sopenharmony_ci| 参数名      | 类型     | 必填   | 说明                                  |
286e41f4b71Sopenharmony_ci| -------- | ------ | ---- | ----------------------------------- |
287e41f4b71Sopenharmony_ci| deviceId | string | 是    | 表示远端设备地址,例如:"XX:XX:XX:XX:XX:XX"。 |
288e41f4b71Sopenharmony_ci| authorization | [AccessAuthorization](js-apis-bluetooth-constant-sys.md#AccessAuthorization) | 是    | 表示访问权限枚举值。 |
289e41f4b71Sopenharmony_ci| callback | AsyncCallback<void> | 是    | 回调函数。当设置成功,err为undefined,否则为错误对象。   |
290e41f4b71Sopenharmony_ci
291e41f4b71Sopenharmony_ci**错误码**:
292e41f4b71Sopenharmony_ci
293e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
294e41f4b71Sopenharmony_ci
295e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 |
296e41f4b71Sopenharmony_ci| -------- | ---------------------------- |
297e41f4b71Sopenharmony_ci|201 | Permission denied.                 |
298e41f4b71Sopenharmony_ci|202 | Non-system applications are not allowed to use system APIs. |
299e41f4b71Sopenharmony_ci|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.                 |
300e41f4b71Sopenharmony_ci|801 | Capability not supported.          |
301e41f4b71Sopenharmony_ci|2900001 | Service stopped.                         |
302e41f4b71Sopenharmony_ci|2900003 | Bluetooth disabled.                 |
303e41f4b71Sopenharmony_ci|2900004 | Profile not supported.                |
304e41f4b71Sopenharmony_ci|2900099 | Operation failed.                        |
305e41f4b71Sopenharmony_ci
306e41f4b71Sopenharmony_ci**示例:**
307e41f4b71Sopenharmony_ci
308e41f4b71Sopenharmony_ci```js
309e41f4b71Sopenharmony_ciimport { AsyncCallback, BusinessError } from '@kit.BasicServicesKit';
310e41f4b71Sopenharmony_citry {
311e41f4b71Sopenharmony_ci    let pbapServerProfile = pbap.createPbapServerProfile();
312e41f4b71Sopenharmony_ci    pbapServerProfile.setPhoneBookAccessAuthorization('XX:XX:XX:XX:XX:XX', 0, (err: BusinessError) => {
313e41f4b71Sopenharmony_ci       console.info('setPhoneBookAccessAuthorization'); 
314e41f4b71Sopenharmony_ci    });
315e41f4b71Sopenharmony_ci} catch (err) {
316e41f4b71Sopenharmony_ci    console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
317e41f4b71Sopenharmony_ci}
318e41f4b71Sopenharmony_ci```
319e41f4b71Sopenharmony_ci
320e41f4b71Sopenharmony_ci
321e41f4b71Sopenharmony_ci### setPhoneBookAccessAuthorization
322e41f4b71Sopenharmony_ci
323e41f4b71Sopenharmony_cisetPhoneBookAccessAuthorization(deviceId: string, authorization: AccessAuthorization): Promise<void>
324e41f4b71Sopenharmony_ci
325e41f4b71Sopenharmony_ci设置电话簿信息的访问权限。使用Promise异步回调。
326e41f4b71Sopenharmony_ci
327e41f4b71Sopenharmony_ci**系统接口**:此接口为系统接口。
328e41f4b71Sopenharmony_ci
329e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.ACCESS_BLUETOOTHohos.permission.MANAGE_BLUETOOTH
330e41f4b71Sopenharmony_ci
331e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Communication.Bluetooth.Core332e41f4b71Sopenharmony_ci
333e41f4b71Sopenharmony_ci**参数:**
334e41f4b71Sopenharmony_ci
335e41f4b71Sopenharmony_ci| 参数名      | 类型     | 必填   | 说明                                  |
336e41f4b71Sopenharmony_ci| -------- | ------ | ---- | ----------------------------------- |
337e41f4b71Sopenharmony_ci| deviceId | string | 是    | 表示远端设备地址,例如:"XX:XX:XX:XX:XX:XX"。 |
338e41f4b71Sopenharmony_ci| authorization | [AccessAuthorization](js-apis-bluetooth-constant-sys.md#AccessAuthorization) | 是    | 表示访问权限枚举值。 |
339e41f4b71Sopenharmony_ci
340e41f4b71Sopenharmony_ci**返回值:**
341e41f4b71Sopenharmony_ci
342e41f4b71Sopenharmony_ci| 类型                                              | 说明                |
343e41f4b71Sopenharmony_ci| ------------------------------------------------- | ------------------- |
344e41f4b71Sopenharmony_ci| Promise<void> | 以Promise的形式返回结果。如果成功,err为undefined的,否则为错误对象。 |
345e41f4b71Sopenharmony_ci
346e41f4b71Sopenharmony_ci**错误码**:
347e41f4b71Sopenharmony_ci
348e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
349e41f4b71Sopenharmony_ci
350e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 |
351e41f4b71Sopenharmony_ci| -------- | ---------------------------- |
352e41f4b71Sopenharmony_ci|201 | Permission denied.                 |
353e41f4b71Sopenharmony_ci|202 | Non-system applications are not allowed to use system APIs. |
354e41f4b71Sopenharmony_ci|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.                 |
355e41f4b71Sopenharmony_ci|801 | Capability not supported.          |
356e41f4b71Sopenharmony_ci|2900001 | Service stopped.                         |
357e41f4b71Sopenharmony_ci|2900003 | Bluetooth disabled.                 |
358e41f4b71Sopenharmony_ci|2900004 | Profile not supported.                |
359e41f4b71Sopenharmony_ci|2900099 | Operation failed.                        |
360e41f4b71Sopenharmony_ci
361e41f4b71Sopenharmony_ci**示例:**
362e41f4b71Sopenharmony_ci
363e41f4b71Sopenharmony_ci```js
364e41f4b71Sopenharmony_ciimport { AsyncCallback, BusinessError } from '@kit.BasicServicesKit';
365e41f4b71Sopenharmony_citry {
366e41f4b71Sopenharmony_ci    let pbapServerProfile = pbap.createPbapServerProfile();
367e41f4b71Sopenharmony_ci    pbapServerProfile.setPhoneBookAccessAuthorization('XX:XX:XX:XX:XX:XX', 0).then(() => {
368e41f4b71Sopenharmony_ci        console.info('setPhoneBookAccessAuthorization');
369e41f4b71Sopenharmony_ci    });
370e41f4b71Sopenharmony_ci} catch (err) {
371e41f4b71Sopenharmony_ci    console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
372e41f4b71Sopenharmony_ci}
373e41f4b71Sopenharmony_ci```
374e41f4b71Sopenharmony_ci
375e41f4b71Sopenharmony_ci### getPhoneBookAccessAuthorization
376e41f4b71Sopenharmony_ci
377e41f4b71Sopenharmony_cigetPhoneBookAccessAuthorization(deviceId: string, callback: AsyncCallback<AccessAuthorization>): void
378e41f4b71Sopenharmony_ci
379e41f4b71Sopenharmony_ci获取电话簿信息的访问权限。使用Callback异步回调。
380e41f4b71Sopenharmony_ci
381e41f4b71Sopenharmony_ci**系统接口**:此接口为系统接口。
382e41f4b71Sopenharmony_ci
383e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.ACCESS_BLUETOOTHohos.permission.MANAGE_BLUETOOTH
384e41f4b71Sopenharmony_ci
385e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Communication.Bluetooth.Core386e41f4b71Sopenharmony_ci
387e41f4b71Sopenharmony_ci**参数:**
388e41f4b71Sopenharmony_ci
389e41f4b71Sopenharmony_ci| 参数名      | 类型     | 必填   | 说明                                  |
390e41f4b71Sopenharmony_ci| -------- | ------ | ---- | ----------------------------------- |
391e41f4b71Sopenharmony_ci| deviceId | string | 是    | 表示远端设备地址,例如:"XX:XX:XX:XX:XX:XX"。 |
392e41f4b71Sopenharmony_ci| callback | AsyncCallback<[AccessAuthorization](js-apis-bluetooth-constant-sys.md#AccessAuthorization)> | 是    | 回调函数。当获取成功,err为undefined,否则为错误对象。   |
393e41f4b71Sopenharmony_ci
394e41f4b71Sopenharmony_ci**错误码**:
395e41f4b71Sopenharmony_ci
396e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
397e41f4b71Sopenharmony_ci
398e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 |
399e41f4b71Sopenharmony_ci| -------- | ---------------------------- |
400e41f4b71Sopenharmony_ci|201 | Permission denied.                 |
401e41f4b71Sopenharmony_ci|202 | Non-system applications are not allowed to use system APIs. |
402e41f4b71Sopenharmony_ci|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.                 |
403e41f4b71Sopenharmony_ci|801 | Capability not supported.          |
404e41f4b71Sopenharmony_ci|2900001 | Service stopped.                         |
405e41f4b71Sopenharmony_ci|2900003 | Bluetooth disabled.                 |
406e41f4b71Sopenharmony_ci|2900004 | Profile not supported.                |
407e41f4b71Sopenharmony_ci|2900099 | Operation failed.                        |
408e41f4b71Sopenharmony_ci
409e41f4b71Sopenharmony_ci**示例:**
410e41f4b71Sopenharmony_ci
411e41f4b71Sopenharmony_ci```js
412e41f4b71Sopenharmony_ciimport { AsyncCallback, BusinessError } from '@kit.BasicServicesKit';
413e41f4b71Sopenharmony_citry {
414e41f4b71Sopenharmony_ci    let pbapServerProfile = pbap.createPbapServerProfile();
415e41f4b71Sopenharmony_ci    pbapServerProfile.getPhoneBookAccessAuthorization('XX:XX:XX:XX:XX:XX', (err, authorization) => {
416e41f4b71Sopenharmony_ci        console.info('authorization ' + authorization);
417e41f4b71Sopenharmony_ci    });
418e41f4b71Sopenharmony_ci} catch (err) {
419e41f4b71Sopenharmony_ci    console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
420e41f4b71Sopenharmony_ci}
421e41f4b71Sopenharmony_ci```
422e41f4b71Sopenharmony_ci
423e41f4b71Sopenharmony_ci### getPhoneBookAccessAuthorization
424e41f4b71Sopenharmony_ci
425e41f4b71Sopenharmony_cigetPhoneBookAccessAuthorization(deviceId: string): Promise<AccessAuthorization>
426e41f4b71Sopenharmony_ci
427e41f4b71Sopenharmony_ci获取电话簿信息的访问权限。使用Promise异步回调。
428e41f4b71Sopenharmony_ci
429e41f4b71Sopenharmony_ci**系统接口**:此接口为系统接口。
430e41f4b71Sopenharmony_ci
431e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.ACCESS_BLUETOOTHohos.permission.MANAGE_BLUETOOTH
432e41f4b71Sopenharmony_ci
433e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Communication.Bluetooth.Core434e41f4b71Sopenharmony_ci
435e41f4b71Sopenharmony_ci**参数:**
436e41f4b71Sopenharmony_ci
437e41f4b71Sopenharmony_ci| 参数名      | 类型     | 必填   | 说明                                  |
438e41f4b71Sopenharmony_ci| -------- | ------ | ---- | ----------------------------------- |
439e41f4b71Sopenharmony_ci| deviceId | string | 是    | 表示远端设备地址,例如:"XX:XX:XX:XX:XX:XX"。 |
440e41f4b71Sopenharmony_ci
441e41f4b71Sopenharmony_ci**返回值:**
442e41f4b71Sopenharmony_ci
443e41f4b71Sopenharmony_ci| 类型                                              | 说明                |
444e41f4b71Sopenharmony_ci| ------------------------------------------------- | ------------------- |
445e41f4b71Sopenharmony_ci| Promise<[AccessAuthorization](js-apis-bluetooth-constant-sys.md#AccessAuthorization)> | 以Promise的形式返回结果。如果成功,err为undefined的,否则为错误对象。 |
446e41f4b71Sopenharmony_ci
447e41f4b71Sopenharmony_ci**错误码**:
448e41f4b71Sopenharmony_ci
449e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
450e41f4b71Sopenharmony_ci
451e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 |
452e41f4b71Sopenharmony_ci| -------- | ---------------------------- |
453e41f4b71Sopenharmony_ci|201 | Permission denied.                 |
454e41f4b71Sopenharmony_ci|202 | Non-system applications are not allowed to use system APIs. |
455e41f4b71Sopenharmony_ci|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.                 |
456e41f4b71Sopenharmony_ci|801 | Capability not supported.          |
457e41f4b71Sopenharmony_ci|2900001 | Service stopped.                         |
458e41f4b71Sopenharmony_ci|2900003 | Bluetooth disabled.                 |
459e41f4b71Sopenharmony_ci|2900004 | Profile not supported.                |
460e41f4b71Sopenharmony_ci|2900099 | Operation failed.                        |
461e41f4b71Sopenharmony_ci
462e41f4b71Sopenharmony_ci**示例:**
463e41f4b71Sopenharmony_ci
464e41f4b71Sopenharmony_ci```js
465e41f4b71Sopenharmony_ciimport { AsyncCallback, BusinessError } from '@kit.BasicServicesKit';
466e41f4b71Sopenharmony_citry {
467e41f4b71Sopenharmony_ci    let pbapServerProfile = pbap.createPbapServerProfile();
468e41f4b71Sopenharmony_ci    pbapServerProfile.getPhoneBookAccessAuthorization('XX:XX:XX:XX:XX:XX').then((authorization) => {
469e41f4b71Sopenharmony_ci        console.info('authorization ' + authorization);
470e41f4b71Sopenharmony_ci    });
471e41f4b71Sopenharmony_ci} catch (err) {
472e41f4b71Sopenharmony_ci    console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
473e41f4b71Sopenharmony_ci}
474e41f4b71Sopenharmony_ci```
475e41f4b71Sopenharmony_ci
476e41f4b71Sopenharmony_ci## ShareType
477e41f4b71Sopenharmony_ci
478e41f4b71Sopenharmony_ci枚举,共享类型。
479e41f4b71Sopenharmony_ci
480e41f4b71Sopenharmony_ci**系统接口**:此接口为系统接口。
481e41f4b71Sopenharmony_ci
482e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Communication.Bluetooth.Core483e41f4b71Sopenharmony_ci
484e41f4b71Sopenharmony_ci| 名称                 | 值  | 说明     |
485e41f4b71Sopenharmony_ci| ------------------ | ---- | ------ |
486e41f4b71Sopenharmony_ci| SHARE_NAME_AND_PHONE_NUMBER | 0    | 共享名字和号码信息。<br/>此接口为系统接口。 |
487e41f4b71Sopenharmony_ci| SHARE_ALL | 1    | 共享所有信息。<br/>此接口为系统接口。  |
488e41f4b71Sopenharmony_ci| SHARE_NOTHING  | 2    | 不共享。<br/>此接口为系统接口。   |