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