• 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 11开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
14>
15> 本模块接口仅可在Stage模型下使用。
16>
17> 本模块接口仅对[设备管理应用](../../mdm/mdm-kit-term.md#mdm应用设备管理应用)开放,需将[设备管理应用激活](js-apis-enterprise-adminManager-sys.md#adminmanagerenableadmin-2)后调用。
18>
19> 当前页面仅包含本模块的系统接口,其他公开接口参见。其他公开接口参见[@ohos.enterprise.bluetoothManager](js-apis-enterprise-bluetoothManager.md)。
20
21## 导入模块
22
23```ts
24import { bluetoothManager } from '@kit.MDMKit';
25```
26
27## bluetoothManager.isBluetoothDisabled
28
29isBluetoothDisabled(admin: Want): boolean
30
31查询蓝牙是否被禁用。
32
33**需要权限:** ohos.permission.ENTERPRISE_MANAGE_BLUETOOTH
34
35**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
36
37**模型约束:** 此接口仅可在Stage模型下使用。
38
39**系统接口:** 此接口为系统接口。
40
41**参数:**
42
43| 参数名 | 类型                                                    | 必填 | 说明                   |
44| ------ | ------------------------------------------------------- | ---- | ---------------------- |
45| admin  | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是   | 企业设备管理扩展组件。 |
46
47**返回值:**
48
49| 类型                   | 说明                      |
50| :-------------------- | ------------------------- |
51| boolean | 返回蓝牙禁用状态,true表示蓝牙被禁用,false表示蓝牙未被禁用。 |
52
53**错误码:**
54
55以下的错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。
56
57| 错误码ID | 错误信息                                                                     |
58| ------- | ---------------------------------------------------------------------------- |
59| 9200001 | The application is not an administrator application of the device. |
60| 9200002 | The administrator application does not have permission to manage the device. |
61| 201 | Permission verification failed. The application does not have the permission required to call the API. |
62| 202 | Permission verification failed. A non-system application calls a system API. |
63| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
64
65**示例:**
66
67```ts
68import { bluetoothManager } from '@kit.MDMKit';
69import { Want } from '@kit.AbilityKit';
70
71let wantTemp: Want = {
72  // 需根据实际情况进行替换
73  bundleName: 'com.example.myapplication',
74  abilityName: 'EntryAbility'
75};
76
77try {
78  let isDisabled: boolean = bluetoothManager.isBluetoothDisabled(wantTemp);
79  console.info(`Succeeded in query the bluetooth is disabled or not, isDisabled : ${isDisabled}`);
80} catch(err) {
81  console.error(`Failed to query the bluetooth is disabled or not. Code: ${err.code}, message: ${err.message}`);
82};
83```
84
85## bluetoothManager.setBluetoothDisabled
86
87setBluetoothDisabled(admin: Want, disabled: boolean): void
88
89设置禁用蓝牙策略。
90
91**需要权限:** ohos.permission.ENTERPRISE_MANAGE_BLUETOOTH
92
93**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
94
95**模型约束:** 此接口仅可在Stage模型下使用。
96
97**系统接口:** 此接口为系统接口。
98
99**参数:**
100
101| 参数名   | 类型                                                    | 必填 | 说明                                      |
102| -------- | ------------------------------------------------------- | ---- | ----------------------------------------- |
103| admin    | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是   | 企业设备管理扩展组件。                    |
104| disabled | boolean                                                 | 是   | true表示禁用蓝牙,false表示解除蓝牙禁用。 |
105
106**错误码:**
107
108以下的错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。
109
110| 错误码ID | 错误信息                                                     |
111| -------- | ------------------------------------------------------------ |
112| 9200001  | The application is not an administrator application of the device. |
113| 9200002  | The administrator application does not have permission to manage the device. |
114| 201      | Permission verification failed. The application does not have the permission required to call the API. |
115| 202      | Permission verification failed. A non-system application calls a system API. |
116| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
117
118**示例:**
119
120```ts
121import { bluetoothManager } from '@kit.MDMKit';
122import { Want } from '@kit.AbilityKit';
123
124let wantTemp: Want = {
125  // 需根据实际情况进行替换
126  bundleName: 'com.example.myapplication',
127  abilityName: 'EntryAbility'
128};
129
130try {
131  bluetoothManager.setBluetoothDisabled(wantTemp, true);
132  console.info('Succeeded in set the bluetooth disabled.');
133} catch(err) {
134  console.error(`Failed to set the bluetooth disabled. Code: ${err.code}, message: ${err.message}`);
135};
136```
137