• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.enterprise.bluetoothManager(蓝牙管理)
2<!--Kit: MDM Kit-->
3<!--Subsystem: Customization-->
4<!--Owner: @huanleima-->
5<!--Designer: @liuzuming-->
6<!--Tester: @lpw_work-->
7<!--Adviser: @Brilliantry_Rui-->
8
9本模块提供设备蓝牙管理的能力,包括设置和查询蓝牙信息等。
10
11> **说明:**
12>
13> 本模块首批接口从API version 12开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
14>
15> 本模块接口仅可在Stage模型下使用。
16>
17> 本模块接口仅对设备管理应用开放,且调用接口前需激活设备管理应用,具体请参考[MDM Kit开发指南](../../mdm/mdm-kit-guide.md)。
18>
19> 全局通用限制类策略由restrictions统一提供,若要全局禁用蓝牙,请参考[@ohos.enterprise.restrictions(限制类策略)](js-apis-enterprise-restrictions.md)。
20
21## 导入模块
22
23```ts
24import { bluetoothManager } from '@kit.MDMKit';
25```
26
27## bluetoothManager.getBluetoothInfo
28
29getBluetoothInfo(admin: Want): BluetoothInfo
30
31查询设备蓝牙信息。
32
33**需要权限:** ohos.permission.ENTERPRISE_MANAGE_BLUETOOTH
34
35**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
36
37**模型约束:** 此接口仅可在Stage模型下使用。
38
39
40**参数:**
41
42| 参数名 | 类型                                                    | 必填 | 说明           |
43| ------ | ------------------------------------------------------- | ---- | -------------- |
44| admin  | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是   | 企业设备管理扩展组件。 |
45
46**返回值:**
47
48| 类型                            | 说明                                             |
49| ------------------------------- | ------------------------------------------------ |
50| [BluetoothInfo](#bluetoothinfo) | 蓝牙信息,包含蓝牙名称、蓝牙状态和蓝牙连接状态。 |
51
52**错误码**:
53
54以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。
55
56| 错误码ID | 错误信息                                                     |
57| -------- | ------------------------------------------------------------ |
58| 9200001  | The application is not an administrator application of the device. |
59| 9200002  | The administrator application does not have permission to manage the device. |
60| 201      | Permission verification failed. The application does not have the permission required to call the API. |
61| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
62
63**示例:**
64
65```ts
66import { bluetoothManager } from '@kit.MDMKit';
67import { Want } from '@kit.AbilityKit';
68
69let wantTemp: Want = {
70  // 需根据实际情况进行替换
71  bundleName: 'com.example.myapplication',
72  abilityName: 'EntryAbility'
73};
74
75try {
76    let result: bluetoothManager.BluetoothInfo = bluetoothManager.getBluetoothInfo(wantTemp);
77    console.info(`Succeeded in getting bluetooth info: ${JSON.stringify(result)}`);
78} catch(err) {
79    console.error(`Failed to get bluetooth info. Code: ${err.code}, message: ${err.message}`);
80}
81```
82
83## bluetoothManager.addAllowedBluetoothDevices
84
85addAllowedBluetoothDevices(admin: Want, deviceIds: Array\<string>): void
86
87添加蓝牙设备可用名单。添加蓝牙设备可用名单后当前设备仅允许连接该名单下的蓝牙设备。
88
89以下情况下,通过本接口添加蓝牙设备可用名单,会报策略冲突:
90
911. 已经通过[setDisallowedPolicy](js-apis-enterprise-restrictions.md#restrictionssetdisallowedpolicy)接口禁用了蓝牙。通过[setDisallowedPolicy](js-apis-enterprise-restrictions.md#restrictionssetdisallowedpolicy)接口启用蓝牙后,可解除冲突。
922. 已经通过[addDisallowedBluetoothDevices](#bluetoothmanageradddisallowedbluetoothdevices20)接口添加了蓝牙设备禁用名单。通过[removeDisallowedBluetoothDevices](#bluetoothmanagerremovedisallowedbluetoothdevices20)移除蓝牙设备禁用名单后,可解除冲突。
93
94**需要权限:** ohos.permission.ENTERPRISE_MANAGE_BLUETOOTH
95
96**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
97
98**模型约束:** 此接口仅可在Stage模型下使用。
99
100
101**参数:**
102
103| 参数名    | 类型                                                    | 必填 | 说明                                                |
104| --------- | ------------------------------------------------------- | ---- | --------------------------------------------------- |
105| admin     | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是   | 企业设备管理扩展组件。                                      |
106| deviceIds | Array\<string>                                          | 是   | 蓝牙设备MAC地址的数组。蓝牙设备允许名单数组长度上限为1000,若当前允许名单中已有300个蓝牙设备MAC地址,则只允许再添加700个。 |
107
108**错误码**:
109
110以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。
111
112| 错误码ID | 错误信息                                                     |
113| -------- | ------------------------------------------------------------ |
114| 9200001  | The application is not an administrator application of the device. |
115| 9200002  | The administrator application does not have permission to manage the device. |
116| 9200010  | A conflict policy has been configured.                       |
117| 201      | Permission verification failed. The application does not have the permission required to call the API. |
118| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
119
120**示例:**
121
122```ts
123import { bluetoothManager } from '@kit.MDMKit';
124import { Want } from '@kit.AbilityKit';
125
126let wantTemp: Want = {
127  // 需根据实际情况进行替换
128  bundleName: 'com.example.myapplication',
129  abilityName: 'EntryAbility'
130};
131// 需根据实际情况进行替换
132let deviceIds: Array<string> = ["00:1A:2B:3C:4D:5E","AA:BB:CC:DD:EE:FF"];
133try {
134    bluetoothManager.addAllowedBluetoothDevices(wantTemp,deviceIds);
135    console.info(`Succeeded in adding allowed bluetooth devices.`);
136} catch(err) {
137    console.error(`Failed to add allowed bluetooth devices. Code: ${err.code}, message: ${err.message}`);
138}
139```
140
141## bluetoothManager.removeAllowedBluetoothDevices
142
143removeAllowedBluetoothDevices(admin: Want, deviceIds: Array\<string>): void
144
145移除蓝牙设备可用名单。
146
147**需要权限:** ohos.permission.ENTERPRISE_MANAGE_BLUETOOTH
148
149**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
150
151**模型约束:** 此接口仅可在Stage模型下使用。
152
153
154**参数:**
155
156| 参数名    | 类型                                                    | 必填 | 说明                    |
157| --------- | ------------------------------------------------------- | ---- | ----------------------- |
158| admin     | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是   | 企业设备管理扩展组件。          |
159| deviceIds | Array\<string>                                          | 是   | 蓝牙设备MAC地址的数组。 |
160
161**错误码**:
162
163以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。
164
165| 错误码ID | 错误信息                                                     |
166| -------- | ------------------------------------------------------------ |
167| 9200001  | The application is not an administrator application of the device. |
168| 9200002  | The administrator application does not have permission to manage the device. |
169| 201      | Permission verification failed. The application does not have the permission required to call the API. |
170| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
171
172**示例:**
173
174```ts
175import { bluetoothManager } from '@kit.MDMKit';
176import { Want } from '@kit.AbilityKit';
177
178let wantTemp: Want = {
179  // 需根据实际情况进行替换
180  bundleName: 'com.example.myapplication',
181  abilityName: 'EntryAbility'
182};
183// 需根据实际情况进行替换
184let deviceIds: Array<string> = ["00:1A:2B:3C:4D:5E","AA:BB:CC:DD:EE:FF"];
185try {
186    bluetoothManager.removeAllowedBluetoothDevices(wantTemp,deviceIds);
187    console.info(`Succeeded in removing allowed bluetooth devices.`);
188} catch(err) {
189    console.error(`Failed to remove allowed bluetooth devices. Code: ${err.code}, message: ${err.message}`);
190}
191```
192
193## bluetoothManager.getAllowedBluetoothDevices
194
195getAllowedBluetoothDevices(admin: Want): Array\<string>
196
197获取蓝牙设备可用名单。
198
199**需要权限:** ohos.permission.ENTERPRISE_MANAGE_BLUETOOTH
200
201**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
202
203**模型约束:** 此接口仅可在Stage模型下使用。
204
205
206**参数:**
207
208| 参数名 | 类型                                                    | 必填 | 说明           |
209| ------ | ------------------------------------------------------- | ---- | -------------- |
210| admin  | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是   | 企业设备管理扩展组件。 |
211
212**返回值:**
213
214| 类型           | 说明                                |
215| -------------- | ----------------------------------- |
216| Array\<string> | 可用名单中蓝牙设备MAC地址的数组。 |
217
218**错误码**:
219
220以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。
221
222| 错误码ID | 错误信息                                                     |
223| -------- | ------------------------------------------------------------ |
224| 9200001  | The application is not an administrator application of the device. |
225| 9200002  | The administrator application does not have permission to manage the device. |
226| 201      | Permission verification failed. The application does not have the permission required to call the API. |
227| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
228
229**示例:**
230
231```ts
232import { bluetoothManager } from '@kit.MDMKit';
233import { Want } from '@kit.AbilityKit';
234
235let wantTemp: Want = {
236  // 需根据实际情况进行替换
237  bundleName: 'com.example.myapplication',
238  abilityName: 'EntryAbility'
239};
240try {
241    let result: Array<string> = bluetoothManager.getAllowedBluetoothDevices(wantTemp);
242    console.info(`Succeeded in getting allowed bluetooth devices. Result: ${JSON.stringify(result)}`);
243} catch(err) {
244    console.error(`Failed to get allowed bluetooth devices. Code: ${err.code}, message: ${err.message}`);
245}
246```
247
248## bluetoothManager.addDisallowedBluetoothDevices<sup>20+</sup>
249
250addDisallowedBluetoothDevices(admin: Want, deviceIds: Array&lt;string&gt;): void
251
252添加蓝牙设备禁用名单。添加禁用名单后当前设备不允许连接该名单下的蓝牙设备。
253
254以下情况下,通过本接口添加蓝牙设备禁用名单,会报策略冲突:
255
2561. 已经通过[setDisallowedPolicy](js-apis-enterprise-restrictions.md#restrictionssetdisallowedpolicy)接口禁用了蓝牙。通过[setDisallowedPolicy](js-apis-enterprise-restrictions.md#restrictionssetdisallowedpolicy)接口启用蓝牙后,可解除冲突。
2572. 已经通过[addAllowedBluetoothDevices](#bluetoothmanageraddallowedbluetoothdevices)接口添加了蓝牙设备可用名单。通过[removeAllowedBluetoothDevices](#bluetoothmanagerremoveallowedbluetoothdevices)移除蓝牙设备可用名单后,可解除冲突。
258
259**需要权限:** ohos.permission.ENTERPRISE_MANAGE_BLUETOOTH
260
261**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
262
263**模型约束:** 此接口仅可在Stage模型下使用。
264
265**参数:**
266
267| 参数名    | 类型                                                    | 必填 | 说明                                                |
268| --------- | ------------------------------------------------------- | ---- | --------------------------------------------------- |
269| admin     | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是   | 企业设备管理扩展组件。                                      |
270| deviceIds | Array&lt;string&gt;                                          | 是   | 蓝牙设备MAC地址的数组。蓝牙设备禁用名单数组长度上限为1000,若当前禁用名单中已有300个蓝牙设备MAC地址,则只允许再添加700个。 |
271
272**错误码**:
273
274以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。
275
276| 错误码ID | 错误信息                                                     |
277| -------- | ------------------------------------------------------------ |
278| 9200001  | The application is not an administrator application of the device. |
279| 9200002  | The administrator application does not have permission to manage the device. |
280| 9200010  | A conflict policy has been configured.                       |
281| 201      | Permission verification failed. The application does not have the permission required to call the API. |
282
283**示例:**
284
285```ts
286import { bluetoothManager } from '@kit.MDMKit';
287import { Want } from '@kit.AbilityKit';
288
289let wantTemp: Want = {
290  //需根据实际情况进行替换
291  bundleName: 'com.example.myapplication',
292  abilityName: 'EntryAbility'
293};
294//需根据实际情况进行替换
295let deviceIds: Array<string> = ["00:1A:2B:3C:4D:5E","AA:BB:CC:DD:EE:FF"];
296try {
297    bluetoothManager.addDisallowedBluetoothDevices(wantTemp,deviceIds);
298    console.info(`Succeeded in adding disallowed bluetooth devices.`);
299} catch(err) {
300    console.error(`Failed to add disallowed bluetooth devices. Code: ${err.code}, message: ${err.message}`);
301}
302```
303
304## bluetoothManager.removeDisallowedBluetoothDevices<sup>20+</sup>
305
306removeDisallowedBluetoothDevices(admin: Want, deviceIds: Array&lt;string&gt;): void
307
308移除蓝牙设备禁用名单。若移除禁用名单中的部分蓝牙设备,则当前设备不允许连接禁用名单内剩余的蓝牙设备。若移除禁用名单中的所有蓝牙设备,则当前设备可以连接任意的蓝牙设备。
309
310**需要权限:** ohos.permission.ENTERPRISE_MANAGE_BLUETOOTH
311
312**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
313
314**模型约束:** 此接口仅可在Stage模型下使用。
315
316**参数:**
317
318| 参数名    | 类型                                                    | 必填 | 说明                    |
319| --------- | ------------------------------------------------------- | ---- | ----------------------- |
320| admin     | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是   | 企业设备管理扩展组件。          |
321| deviceIds | Array&lt;string&gt;                                          | 是   | 蓝牙设备MAC地址的数组。 |
322
323**错误码**:
324
325以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。
326
327| 错误码ID | 错误信息                                                     |
328| -------- | ------------------------------------------------------------ |
329| 9200001  | The application is not an administrator application of the device. |
330| 9200002  | The administrator application does not have permission to manage the device. |
331| 201      | Permission verification failed. The application does not have the permission required to call the API. |
332
333**示例:**
334
335```ts
336import { bluetoothManager } from '@kit.MDMKit';
337import { Want } from '@kit.AbilityKit';
338
339let wantTemp: Want = {
340  //需根据实际情况进行替换
341  bundleName: 'com.example.myapplication',
342  abilityName: 'EntryAbility'
343};
344//需根据实际情况进行替换
345let deviceIds: Array<string> = ["00:1A:2B:3C:4D:5E","AA:BB:CC:DD:EE:FF"];
346try {
347    bluetoothManager.removeDisallowedBluetoothDevices(wantTemp,deviceIds);
348    console.info(`Succeeded in removing disallowed bluetooth devices.`);
349} catch(err) {
350    console.error(`Failed to remove disallowed bluetooth devices. Code: ${err.code}, message: ${err.message}`);
351}
352```
353
354## bluetoothManager.getDisallowedBluetoothDevices<sup>20+</sup>
355
356getDisallowedBluetoothDevices(admin: Want): Array&lt;string&gt;
357
358获取蓝牙设备禁用名单。
359
360**需要权限:** ohos.permission.ENTERPRISE_MANAGE_BLUETOOTH
361
362**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
363
364**模型约束:** 此接口仅可在Stage模型下使用。
365
366**参数:**
367
368| 参数名 | 类型                                                    | 必填 | 说明           |
369| ------ | ------------------------------------------------------- | ---- | -------------- |
370| admin  | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是   | 企业设备管理扩展组件。 |
371
372**返回值:**
373
374| 类型           | 说明                                |
375| -------------- | ----------------------------------- |
376| Array&lt;string&gt; | 禁用名单中蓝牙设备MAC地址的数组。 |
377
378**错误码**:
379
380以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。
381
382| 错误码ID | 错误信息                                                     |
383| -------- | ------------------------------------------------------------ |
384| 9200001  | The application is not an administrator application of the device. |
385| 9200002  | The administrator application does not have permission to manage the device. |
386| 201      | Permission verification failed. The application does not have the permission required to call the API. |
387
388**示例:**
389
390```ts
391import { bluetoothManager } from '@kit.MDMKit';
392import { Want } from '@kit.AbilityKit';
393
394let wantTemp: Want = {
395  //需根据实际情况进行替换
396  bundleName: 'com.example.myapplication',
397  abilityName: 'EntryAbility'
398};
399try {
400    let result: Array<string> = bluetoothManager.getDisallowedBluetoothDevices(wantTemp);
401    console.info(`Succeeded in getting disallowed bluetooth devices. Result: ${JSON.stringify(result)}`);
402} catch(err) {
403    console.error(`Failed to get disallowed bluetooth devices. Code: ${err.code}, message: ${err.message}`);
404}
405```
406
407## BluetoothInfo
408
409设备的蓝牙信息。
410
411**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
412
413**模型约束:** 此接口仅可在Stage模型下使用。
414
415| 名称            | 类型                                                         | 只读 | 可选 | 说明                     |
416| --------------- | ------------------------------------------------------------ | ---- | ---- | ------------------------ |
417| name            | string                                                       | 否   | 否 | 表示设备的蓝牙名称。     |
418| state           | [access.BluetoothState](../apis-connectivity-kit/js-apis-bluetooth-access.md#bluetoothstate) | 否   | 否 | 表示设备的蓝牙状态。     |
419| connectionState | [constant.ProfileConnectionState](../apis-connectivity-kit/js-apis-bluetooth-constant.md#profileconnectionstate) | 否   | 否 | 表示设备的蓝牙连接状态。 |
420
421## bluetoothManager.turnOnBluetooth<sup>20+</sup>
422
423turnOnBluetooth(admin: Want): void
424
425开启蓝牙。蓝牙开启后用户可以手动关闭。
426
427**需要权限:** ohos.permission.ENTERPRISE_MANAGE_BLUETOOTH
428
429**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
430
431**模型约束:** 此接口仅可在Stage模型下使用。
432
433
434**参数:**
435
436| 参数名 | 类型                                                    | 必填 | 说明                   |
437| ------ | ------------------------------------------------------- | ---- | ---------------------- |
438| admin  | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是   | 企业设备管理扩展组件。 |
439
440**错误码**:
441
442以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。
443
444| 错误码ID | 错误信息                                                     |
445| -------- | ------------------------------------------------------------ |
446| 9200001  | The application is not an administrator application of the device. |
447| 9200002  | The administrator application does not have permission to manage the device. |
448| 201      | Permission verification failed. The application does not have the permission required to call the API. |
449| 203      | This function is prohibited by enterprise management policies. |
450
451**示例:**
452
453```ts
454import { Want } from '@kit.AbilityKit';
455import { bluetoothManager } from '@kit.MDMKit';
456
457let wantTemp: Want = {
458  // 需根据实际情况进行替换
459  bundleName: 'com.example.myapplication',
460  abilityName: 'EntryAbility'
461};
462try {
463    bluetoothManager.turnOnBluetooth(wantTemp);
464    console.info(`Succeeded in turning on bluetooth.`);
465} catch(err) {
466    console.error(`Failed to turn on bluetooth. Code: ${err.code}, message: ${err.message}`);
467}
468```
469
470## bluetoothManager.turnOffBluetooth<sup>20+</sup>
471
472turnOffBluetooth(admin: Want): void
473
474关闭蓝牙。蓝牙关闭后用户可以手动打开。
475
476**需要权限:** ohos.permission.ENTERPRISE_MANAGE_BLUETOOTH
477
478**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
479
480**模型约束:** 此接口仅可在Stage模型下使用。
481
482
483**参数:**
484
485| 参数名 | 类型                                                    | 必填 | 说明                   |
486| ------ | ------------------------------------------------------- | ---- | ---------------------- |
487| admin  | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是   | 企业设备管理扩展组件。 |
488
489**错误码**:
490
491以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。
492
493| 错误码ID | 错误信息                                                     |
494| -------- | ------------------------------------------------------------ |
495| 9200001  | The application is not an administrator application of the device. |
496| 9200002  | The administrator application does not have permission to manage the device. |
497| 201      | Permission verification failed. The application does not have the permission required to call the API. |
498| 203      | This function is prohibited by enterprise management policies. |
499
500**示例:**
501
502```ts
503import { Want } from '@kit.AbilityKit';
504import { bluetoothManager } from '@kit.MDMKit';
505
506let wantTemp: Want = {
507  // 需根据实际情况进行替换
508  bundleName: 'com.example.myapplication',
509  abilityName: 'EntryAbility'
510};
511try {
512    bluetoothManager.turnOffBluetooth(wantTemp);
513    console.info('Succeeded in turning off bluetooth.');
514} catch(err) {
515    console.error(`Failed to turn off bluetooth. Code: ${err.code}, message: ${err.message}`);
516}
517```
518
519## bluetoothManager.addDisallowedBluetoothProtocols<sup>20+</sup>
520
521addDisallowedBluetoothProtocols(admin: Want, accountId: number, protocols: Array&lt;Protocol&gt;): void
522
523添加蓝牙协议禁用名单。添加后,指定用户将无法使用该禁用名单中的蓝牙协议向其他设备外发文件。通过该接口禁用GATT或SPP协议,对系统服务和系统应用不生效。
524
525**需要权限:** ohos.permission.ENTERPRISE_MANAGE_BLUETOOTH
526
527**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
528
529**模型约束:** 此接口仅可在Stage模型下使用。
530
531**参数:**
532
533| 参数名 | 类型                                                    | 必填 | 说明                   |
534| ------ | ------------------------------------------------------- | ---- | ---------------------- |
535| admin  | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是   | 企业设备管理扩展组件。 |
536| accountId | number | 是   | 用户ID,取值范围:大于等于0。<br> accountId可以通过@ohos.account.osAccount中的[getOsAccountLocalId](../apis-basic-services-kit/js-apis-osAccount.md#getosaccountlocalid9-1)等接口来获取。 |
537| protocols  | Array&lt;[Protocol](#protocol20)&gt; | 是   | 蓝牙协议的数组。数组长度上限为10000。 |
538
539**错误码**:
540
541以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。
542
543| 错误码ID | 错误信息                                                     |
544| -------- | ------------------------------------------------------------ |
545| 9200001  | The application is not an administrator application of the device. |
546| 9200002  | The administrator application does not have permission to manage the device. |
547| 201      | Permission verification failed. The application does not have the permission required to call the API. |
548
549**示例:**
550
551```ts
552import { Want } from '@kit.AbilityKit';
553import { bluetoothManager } from '@kit.MDMKit';
554
555let wantTemp: Want = {
556  // 需根据实际情况进行替换
557  bundleName: 'com.example.myapplication',
558  abilityName: 'EntryAbility'
559};
560// 需根据实际情况进行替换
561let accountId: number = 100;
562let protocols: Array<bluetoothManager.Protocol> = [bluetoothManager.Protocol.GATT, bluetoothManager.Protocol.SPP];
563try{
564    bluetoothManager.addDisallowedBluetoothProtocols(wantTemp, accountId, protocols);
565    console.info('Succeeded in adding disallowed bluetooth protocols policy.');
566} catch (err) {
567    console.error(`Failed to add disallowed bluetooth protocols. Code: ${err.code}, message: ${err.message}`);
568}
569```
570
571## bluetoothManager.removeDisallowedBluetoothProtocols<sup>20+</sup>
572
573removeDisallowedBluetoothProtocols(admin: Want, accountId: number, protocols: Array&lt;Protocol&gt;): void
574
575移除蓝牙协议禁用名单。若移除禁用名单中某个用户的部分蓝牙协议,则该用户不能使用禁用名单内剩余的蓝牙协议向其他设备外发文件。若移除禁用名单中某个用户的所有蓝牙协议,则该用户可以使用任意蓝牙协议向其他设备外发文件。若移除禁用名单中不存在的蓝牙协议,接口可调用成功,但不会移除禁用名单中不存在的蓝牙协议。
576
577**需要权限:** ohos.permission.ENTERPRISE_MANAGE_BLUETOOTH
578
579**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
580
581**模型约束:** 此接口仅可在Stage模型下使用。
582
583**参数:**
584
585| 参数名 | 类型                                                    | 必填 | 说明                   |
586| ------ | ------------------------------------------------------- | ---- | ---------------------- |
587| admin  | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是   | 企业设备管理扩展组件。 |
588| accountId | number | 是   | 用户ID,取值范围:大于等于0。<br> accountId可以通过@ohos.account.osAccount中的[getOsAccountLocalId](../apis-basic-services-kit/js-apis-osAccount.md#getosaccountlocalid9-1)等接口来获取。 |
589| protocols  | Array&lt;[Protocol](#protocol20)&gt; | 是   | 蓝牙协议的数组。 |
590
591**错误码**:
592
593以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。
594
595| 错误码ID | 错误信息                                                     |
596| -------- | ------------------------------------------------------------ |
597| 9200001  | The application is not an administrator application of the device. |
598| 9200002  | The administrator application does not have permission to manage the device. |
599| 201      | Permission verification failed. The application does not have the permission required to call the API. |
600
601**示例:**
602
603```ts
604import { Want } from '@kit.AbilityKit';
605import { bluetoothManager } from '@kit.MDMKit';
606
607let wantTemp: Want = {
608  // 需根据实际情况进行替换
609  bundleName: 'com.example.myapplication',
610  abilityName: 'EntryAbility'
611};
612// 需根据实际情况进行替换
613let accountId: number = 100;
614let protocols: Array<bluetoothManager.Protocol> = [bluetoothManager.Protocol.GATT, bluetoothManager.Protocol.SPP];
615try{
616    bluetoothManager.removeDisallowedBluetoothProtocols(wantTemp, accountId, protocols);
617    console.info('Succeeded in removing disallowed bluetooth protocols policy.');
618} catch (err) {
619    console.error(`Failed to remove disallowed bluetooth protocols. Code: ${err.code}, message: ${err.message}`);
620}
621```
622
623## bluetoothManager.getDisallowedBluetoothProtocols<sup>20+</sup>
624
625getDisallowedBluetoothProtocols(admin: Want, accountId: number): Array&lt;Protocol&gt;
626
627获取指定用户的蓝牙协议禁用名单。
628
629**需要权限:** ohos.permission.ENTERPRISE_MANAGE_BLUETOOTH
630
631**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
632
633**模型约束:** 此接口仅可在Stage模型下使用。
634
635**参数:**
636
637| 参数名 | 类型                                                    | 必填 | 说明                   |
638| ------ | ------------------------------------------------------- | ---- | ---------------------- |
639| admin  | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是   | 企业设备管理扩展组件。 |
640| accountId | number | 是   | 用户ID,取值范围:大于等于0。<br> accountId可以通过@ohos.account.osAccount中的[getOsAccountLocalId](../apis-basic-services-kit/js-apis-osAccount.md#getosaccountlocalid9-1)等接口来获取。 |
641
642**返回值:**
643
644| 类型           | 说明                                |
645| -------------- | ----------------------------------- |
646| Array&lt;[Protocol](#protocol20)&gt; | 禁用名单中蓝牙协议的数组。 |
647
648**错误码**:
649
650以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。
651
652| 错误码ID | 错误信息                                                     |
653| -------- | ------------------------------------------------------------ |
654| 9200001  | The application is not an administrator application of the device. |
655| 9200002  | The administrator application does not have permission to manage the device. |
656| 201      | Permission verification failed. The application does not have the permission required to call the API. |
657
658**示例:**
659
660```ts
661import { Want } from '@kit.AbilityKit';
662import { bluetoothManager } from '@kit.MDMKit';
663
664let wantTemp: Want = {
665  // 需根据实际情况进行替换
666  bundleName: 'com.example.myapplication',
667  abilityName: 'EntryAbility'
668};
669// 需根据实际情况进行替换
670let accountId: number = 100;
671try{
672    let result: Array<bluetoothManager.Protocol> = bluetoothManager.getDisallowedBluetoothProtocols(wantTemp, accountId);
673    console.info(`Succeeded in getting disallowed bluetooth protocols. Result: ${JSON.stringify(result)}`);
674} catch (err) {
675    console.error(`Failed to get disallowed bluetooth protocols. Code: ${err.code}, message: ${err.message}`);
676}
677```
678
679## Protocol<sup>20+</sup>
680
681蓝牙协议类型。
682
683**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
684
685**模型约束:** 此接口仅可在Stage模型下使用。
686
687| 名称                | 值  | 说明    |
688| ----------------- | ---- | ----- |
689| GATT | 0 | [GATT协议](../../connectivity/terminology.md#gatt)。 |
690| SPP | 1 | [SPP协议](../../connectivity/terminology.md#spp)。 |
691| OPP | 2 | [OPP协议](../../connectivity/terminology.md#opp)。 |