1# @ohos.enterprise.bluetoothManager (Bluetooth Management) 2 3The **bluetoothManager** module provides Bluetooth management capabilities, including setting and obtaining Bluetooth information. 4 5> **NOTE** 6> 7> - The initial APIs of this module are supported since API version 12. Newly added APIs will be marked with a superscript to indicate their earliest API version. 8> 9> - The APIs of this module can be used only in the stage model. 10> 11> - The APIs of this module can be called only by a device administrator application that is enabled. For details, see [MDM Kit Development](../../mdm/mdm-kit-guide.md). 12> 13> - The global restriction policies are provided by **restrictions**. To disable Bluetooth globally, see [@ohos.enterprise.restrictions](js-apis-enterprise-restrictions.md). 14 15## Modules to Import 16 17```ts 18import { bluetoothManager } from '@kit.MDMKit'; 19``` 20 21## bluetoothManager.getBluetoothInfo 22 23getBluetoothInfo(admin: Want): BluetoothInfo 24 25Obtains device Bluetooth information. 26 27**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_BLUETOOTH 28 29**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 30 31 32 33**Parameters** 34 35| Name| Type | Mandatory| Description | 36| ------ | ------------------------------------------------------- | ---- | -------------- | 37| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | EnterpriseAdminExtensionAbility.| 38 39**Return value** 40 41| Type | Description | 42| ------------------------------- | ------------------------------------------------ | 43| [BluetoothInfo](#bluetoothinfo) | Bluetooth information, including the Bluetooth name, state, and profile connection state.| 44 45**Error codes** 46 47For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 48 49| ID| Error Message | 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| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 55 56**Example** 57 58```ts 59import { Want } from '@kit.AbilityKit'; 60 61let wantTemp: Want = { 62 bundleName: 'com.example.myapplication', 63 abilityName: 'EntryAbility', 64}; 65 66try { 67 let result: bluetoothManager.BluetoothInfo = bluetoothManager.getBluetoothInfo(wantTemp); 68 console.info(`Succeeded in getting bluetooth info: ${JSON.stringify(result)}`); 69} catch(err) { 70 console.error(`Failed to get bluetooth info. Code: ${err.code}, message: ${err.message}`); 71} 72``` 73 74## bluetoothManager.addAllowedBluetoothDevices 75 76addAllowedBluetoothDevices(admin: Want, deviceIds: Array\<string>): void 77 78Adds allowed Bluetooth devices. The current device can only connect to the allowed Bluetooth devices. 79 80A policy conflict is reported when this API is called in the following scenarios: 81 821. Bluetooth has been disabled by calling [setDisallowedPolicy](js-apis-enterprise-restrictions.md#restrictionssetdisallowedpolicy). You can resolve the conflict by enabling the Bluetooth through [setDisallowedPolicy](js-apis-enterprise-restrictions.md#restrictionssetdisallowedpolicy). 832. Disallowed Bluetooth devices have been added by calling [addDisallowedBluetoothDevices](#bluetoothmanageradddisallowedbluetoothdevices20). You can resolve the conflict by removing disallowed Bluetooth devices through [removeDisallowedBluetoothDevices](#bluetoothmanagerremovedisallowedbluetoothdevices20). 84 85**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_BLUETOOTH 86 87**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 88 89 90 91**Parameters** 92 93| Name | Type | Mandatory| Description | 94| --------- | ------------------------------------------------------- | ---- | --------------------------------------------------- | 95| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | EnterpriseAdminExtensionAbility. | 96| deviceIds | Array\<string> | Yes | MAC addresses of the Bluetooth devices to add. This array can hold a maximum of 1000 MAC addresses.| 97 98**Error codes** 99 100For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 101 102| ID| Error Message | 103| -------- | ------------------------------------------------------------ | 104| 9200001 | The application is not an administrator application of the device. | 105| 9200002 | The administrator application does not have permission to manage the device. | 106| 9200010 | A conflict policy has been configured. | 107| 201 | Permission verification failed. The application does not have the permission required to call the API. | 108| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 109 110**Example** 111 112```ts 113import { Want } from '@kit.AbilityKit'; 114 115let wantTemp: Want = { 116 bundleName: 'com.example.myapplication', 117 abilityName: 'EntryAbility', 118}; 119let deviceIds: Array<string> = ["00:1A:2B:3C:4D:5E","AA:BB:CC:DD:EE:FF"]; 120try { 121 bluetoothManager.addAllowedBluetoothDevices(wantTemp,deviceIds); 122 console.info(`Succeeded in adding allowed bluetooth devices.`); 123} catch(err) { 124 console.error(`Failed to add allowed bluetooth devices. Code: ${err.code}, message: ${err.message}`); 125} 126``` 127 128## bluetoothManager.removeAllowedBluetoothDevices 129 130removeAllowedBluetoothDevices(admin: Want, deviceIds: Array\<string>): void 131 132Removes allowed Bluetooth devices. 133 134**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_BLUETOOTH 135 136**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 137 138 139 140**Parameters** 141 142| Name | Type | Mandatory| Description | 143| --------- | ------------------------------------------------------- | ---- | ----------------------- | 144| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | EnterpriseAdminExtensionAbility. | 145| deviceIds | Array\<string> | Yes | MAC addresses of the Bluetooth devices to remove.| 146 147**Error codes** 148 149For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 150 151| ID| Error Message | 152| -------- | ------------------------------------------------------------ | 153| 9200001 | The application is not an administrator application of the device. | 154| 9200002 | The administrator application does not have permission to manage the device. | 155| 201 | Permission verification failed. The application does not have the permission required to call the API. | 156| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 157 158**Example** 159 160```ts 161import { Want } from '@kit.AbilityKit'; 162 163let wantTemp: Want = { 164 bundleName: 'com.example.myapplication', 165 abilityName: 'EntryAbility', 166}; 167let deviceIds: Array<string> = ["00:1A:2B:3C:4D:5E","AA:BB:CC:DD:EE:FF"]; 168try { 169 bluetoothManager.removeAllowedBluetoothDevices(wantTemp,deviceIds); 170 console.info(`Succeeded in removing allowed bluetooth devices.`); 171} catch(err) { 172 console.error(`Failed to remove allowed bluetooth devices. Code: ${err.code}, message: ${err.message}`); 173} 174``` 175 176## bluetoothManager.getAllowedBluetoothDevices 177 178getAllowedBluetoothDevices(admin: Want): Array\<string> 179 180Obtains allowed Bluetooth devices. 181 182**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_BLUETOOTH 183 184**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 185 186 187 188**Parameters** 189 190| Name| Type | Mandatory| Description | 191| ------ | ------------------------------------------------------- | ---- | -------------- | 192| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | EnterpriseAdminExtensionAbility.| 193 194**Return value** 195 196| Type | Description | 197| -------------- | ----------------------------------- | 198| Array\<string> | MAC addresses of allowed Bluetooth devices obtained.| 199 200**Error codes** 201 202For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 203 204| ID| Error Message | 205| -------- | ------------------------------------------------------------ | 206| 9200001 | The application is not an administrator application of the device. | 207| 9200002 | The administrator application does not have permission to manage the device. | 208| 201 | Permission verification failed. The application does not have the permission required to call the API. | 209| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 210 211**Example** 212 213```ts 214import { Want } from '@kit.AbilityKit'; 215 216let wantTemp: Want = { 217 bundleName: 'com.example.myapplication', 218 abilityName: 'EntryAbility', 219}; 220try { 221 let result: Array<string> = bluetoothManager.getAllowedBluetoothDevices(wantTemp); 222 console.info(`Succeeded in getting allowed bluetooth devices. Result: ${JSON.stringify(result)}`); 223} catch(err) { 224 console.error(`Failed to get allowed bluetooth devices. Code: ${err.code}, message: ${err.message}`); 225} 226``` 227 228## bluetoothManager.addDisallowedBluetoothDevices<sup>20+</sup> 229 230addDisallowedBluetoothDevices(admin: Want, deviceIds: Array<string>): void 231 232Adds disallowed Bluetooth devices. The current device cannot connect to the disallowed Bluetooth devices. 233 234A policy conflict is reported when this API is called in the following scenarios: 235 2361. Bluetooth has been disabled by calling [setDisallowedPolicy](js-apis-enterprise-restrictions.md#restrictionssetdisallowedpolicy). You can resolve the conflict by enabling the Bluetooth through [setDisallowedPolicy](js-apis-enterprise-restrictions.md#restrictionssetdisallowedpolicy). 2372. Allowed Bluetooth devices have been added by calling [addAllowedBluetoothDevices](#bluetoothmanageraddallowedbluetoothdevices). You can resolve the conflict by removing allowed Bluetooth devices through [removeAllowedBluetoothDevices](#bluetoothmanagerremoveallowedbluetoothdevices). 238 239**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_BLUETOOTH 240 241**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 242 243**Parameters** 244 245| Name | Type | Mandatory| Description | 246| --------- | ------------------------------------------------------- | ---- | --------------------------------------------------- | 247| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | EnterpriseAdminExtensionAbility. | 248| deviceIds | Array<string> | Yes | MAC addresses of the Bluetooth devices to add. <br>The maximum number of disallowed Bluetooth devices is 1,000. If there are already 300 MAC addresses of the devices, only 700 more can be added.| 249 250**Error codes** 251 252For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 253 254| ID| Error Message | 255| -------- | ------------------------------------------------------------ | 256| 9200001 | The application is not an administrator application of the device. | 257| 9200002 | The administrator application does not have permission to manage the device. | 258| 9200010 | A conflict policy has been configured. | 259| 201 | Permission verification failed. The application does not have the permission required to call the API. | 260 261**Example** 262 263```ts 264import { Want } from '@kit.AbilityKit'; 265 266let wantTemp: Want = { 267 // Replace it as required. 268 bundleName: 'com.example.myapplication', 269 abilityName: 'EntryAbility', 270}; 271// Replace it as required. 272let deviceIds: Array<string> = ["00:1A:2B:3C:4D:5E","AA:BB:CC:DD:EE:FF"]; 273try { 274 bluetoothManager.addDisallowedBluetoothDevices(wantTemp,deviceIds); 275 console.info(`Succeeded in adding allowed bluetooth devices.`); 276} catch(err) { 277 console.error(`Failed to add allowed bluetooth devices. Code: ${err.code}, message: ${err.message}`); 278} 279``` 280 281## bluetoothManager.removeDisallowedBluetoothDevices<sup>20+</sup> 282 283removeDisallowedBluetoothDevices(admin: Want, deviceIds: Array<string>): void 284 285Removes disallowed Bluetooth devices. If some disallowed Bluetooth devices are removed, the current device cannot connect to the remaining disallowed Bluetooth devices. If all disallowed Bluetooth devices are removed, the current device can connect to any Bluetooth device. 286 287**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_BLUETOOTH 288 289**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 290 291**Parameters** 292 293| Name | Type | Mandatory| Description | 294| --------- | ------------------------------------------------------- | ---- | ----------------------- | 295| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | EnterpriseAdminExtensionAbility. | 296| deviceIds | Array<string> | Yes | MAC addresses of the Bluetooth devices to remove.| 297 298**Error codes** 299 300For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 301 302| ID| Error Message | 303| -------- | ------------------------------------------------------------ | 304| 9200001 | The application is not an administrator application of the device. | 305| 9200002 | The administrator application does not have permission to manage the device. | 306| 201 | Permission verification failed. The application does not have the permission required to call the API. | 307 308**Example** 309 310```ts 311import { Want } from '@kit.AbilityKit'; 312 313let wantTemp: Want = { 314 // Replace it as required. 315 bundleName: 'com.example.myapplication', 316 abilityName: 'EntryAbility', 317}; 318// Replace it as required. 319let deviceIds: Array<string> = ["00:1A:2B:3C:4D:5E","AA:BB:CC:DD:EE:FF"]; 320try { 321 bluetoothManager.removeDisallowedBluetoothDevices(wantTemp,deviceIds); 322 console.info(`Succeeded in removing allowed bluetooth devices.`); 323} catch(err) { 324 console.error(`Failed to remove allowed bluetooth devices. Code: ${err.code}, message: ${err.message}`); 325} 326``` 327 328## bluetoothManager.getDisallowedBluetoothDevices<sup>20+</sup> 329 330getDisallowedBluetoothDevices(admin: Want): Array<string> 331 332Obtains disallowed Bluetooth devices. 333 334**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_BLUETOOTH 335 336**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 337 338**Parameters** 339 340| Name| Type | Mandatory| Description | 341| ------ | ------------------------------------------------------- | ---- | -------------- | 342| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | EnterpriseAdminExtensionAbility.| 343 344**Return value** 345 346| Type | Description | 347| -------------- | ----------------------------------- | 348| Array<string> | MAC addresses of disallowed Bluetooth devices obtained.| 349 350**Error codes** 351 352For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 353 354| ID| Error Message | 355| -------- | ------------------------------------------------------------ | 356| 9200001 | The application is not an administrator application of the device. | 357| 9200002 | The administrator application does not have permission to manage the device. | 358| 201 | Permission verification failed. The application does not have the permission required to call the API. | 359 360**Example** 361 362```ts 363import { Want } from '@kit.AbilityKit'; 364 365let wantTemp: Want = { 366 // Replace it as required. 367 bundleName: 'com.example.myapplication', 368 abilityName: 'EntryAbility', 369}; 370try { 371 let result: Array<string> = bluetoothManager.getDisallowedBluetoothDevices(wantTemp); 372 console.info(`Succeeded in getting allowed bluetooth devices. Result: ${JSON.stringify(result)}`); 373} catch(err) { 374 console.error(`Failed to get allowed bluetooth devices. Code: ${err.code}, message: ${err.message}`); 375} 376``` 377 378## BluetoothInfo 379 380Represents the device Bluetooth information. 381 382**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 383 384 385 386**Model restriction**: This API can be used only in the stage model. 387 388| Name | Type | Read-Only| Optional| Description | 389| --------------- | ------------------------------------------------------------ | ---- | ---- | ------------------------ | 390| name | string | No | No| Bluetooth name of the device. | 391| state | [access.BluetoothState](../apis-connectivity-kit/js-apis-bluetooth-access.md#bluetoothstate) | No | No| Bluetooth state of the device. | 392| connectionState | [constant.ProfileConnectionState](../apis-connectivity-kit/js-apis-bluetooth-constant.md#profileconnectionstate) | No | No| Bluetooth profile connection state of the device.| 393 394## bluetoothManager.turnOnBluetooth<sup>20+</sup> 395 396turnOnBluetooth(admin: Want): void 397 398Enables Bluetooth. 399 400**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_BLUETOOTH 401 402**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 403 404 405 406**Parameters** 407 408| Name| Type | Mandatory| Description | 409| ------ | ------------------------------------------------------- | ---- | ---------------------- | 410| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | EnterpriseAdminExtensionAbility.| 411 412**Error codes** 413 414For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 415 416| ID| Error Message | 417| -------- | ------------------------------------------------------------ | 418| 9200001 | The application is not an administrator application of the device. | 419| 9200002 | The administrator application does not have permission to manage the device. | 420| 201 | Permission verification failed. The application does not have the permission required to call the API. | 421| 203 | This function is prohibited by enterprise management policies. | 422 423**Example** 424 425```ts 426import { Want } from '@kit.AbilityKit'; 427import { bluetoothManager } from '@kit.MDMKit'; 428 429let wantTemp: Want = { 430 bundleName: 'com.example.myapplication', 431 abilityName: 'EntryAbility', 432}; 433try { 434 bluetoothManager.turnOnBluetooth(wantTemp); 435 console.info(`Succeeded in turning on bluetooth.`); 436} catch(err) { 437 console.error(`Failed to turn on bluetooth. Code: ${err.code}, message: ${err.message}`); 438} 439``` 440 441## bluetoothManager.turnOffBluetooth<sup>20+</sup> 442 443turnOffBluetooth(admin: Want): void 444 445Disables Bluetooth. 446 447**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_BLUETOOTH 448 449**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 450 451 452 453**Parameters** 454 455| Name| Type | Mandatory| Description | 456| ------ | ------------------------------------------------------- | ---- | ---------------------- | 457| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | EnterpriseAdminExtensionAbility.| 458 459**Error codes** 460 461For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 462 463| ID| Error Message | 464| -------- | ------------------------------------------------------------ | 465| 9200001 | The application is not an administrator application of the device. | 466| 9200002 | The administrator application does not have permission to manage the device. | 467| 201 | Permission verification failed. The application does not have the permission required to call the API. | 468| 203 | This function is prohibited by enterprise management policies. | 469 470**Example** 471 472```ts 473import { Want } from '@kit.AbilityKit'; 474import { bluetoothManager } from '@kit.MDMKit'; 475 476let wantTemp: Want = { 477 bundleName: 'com.example.myapplication', 478 abilityName: 'EntryAbility', 479}; 480try { 481 bluetoothManager.turnOffBluetooth(wantTemp); 482 console.info(`Succeeded in turning off bluetooth.`); 483} catch(err) { 484 console.error(`Failed to turn off bluetooth. Code: ${err.code}, message: ${err.message}`); 485} 486``` 487 488## bluetoothManager.addDisallowedBluetoothProtocols<sup>20+</sup> 489 490addDisallowedBluetoothProtocols(admin: Want, accountId: number, protocols: Array<Protocol>): void 491 492Adds disallowed Bluetooth protocols. Specified users cannot use the disallowed Bluetooth protocols to send files to other devices. 493 494**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_BLUETOOTH 495 496**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 497 498**Parameters** 499 500| Name| Type | Mandatory| Description | 501| ------ | ------------------------------------------------------- | ---- | ---------------------- | 502| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | EnterpriseAdminExtensionAbility.| 503| accountId | number | Yes | User ID, which must be greater than or equal to 0.<br> You can call [getOsAccountLocalId](../apis-basic-services-kit/js-apis-osAccount.md#getosaccountlocalid9-1) of @ohos.account.osAccount to obtain the ID.| 504| protocols | Array<[Protocol](#protocol20)> | Yes | Bluetooth protocol array, which has a maximum length of 10,000.| 505 506**Error codes** 507 508For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 509 510| ID| Error Message | 511| -------- | ------------------------------------------------------------ | 512| 9200001 | The application is not an administrator application of the device. | 513| 9200002 | The administrator application does not have permission to manage the device. | 514| 201 | Permission verification failed. The application does not have the permission required to call the API. | 515 516**Example** 517 518```ts 519import { Want } from '@kit.AbilityKit'; 520import { bluetoothManager } from '@kit.MDMKit'; 521 522let wantTemp: Want = { 523 // Replace it as required. 524 bundleName: 'com.example.myapplication', 525 abilityName: 'EntryAbility' 526}; 527// Replace it as required. 528let accountId: number = 100; 529let protocols: Array<bluetoothManager.Protocol> = [bluetoothManager.Protocol.GATT, bluetoothManager.Protocol.SPP]; 530try{ 531 bluetoothManager.addDisallowedBluetoothProtocols(wantTemp, accountId, protocols); 532 console.info('Succeeded in adding disallowed bluetooth protocols policy.'); 533} catch (err) { 534 console.error(`Failed to add disallowed bluetooth protocols. Code: ${err.code}, message: ${err.message}`); 535} 536``` 537 538## bluetoothManager.removeDisallowedBluetoothProtocols<sup>20+</sup> 539 540removeDisallowedBluetoothProtocols(admin: Want, accountId: number, protocols: Array<Protocol>): void 541 542Removes disallowed Bluetooth protocols. After removing some protocols, the user is still restricted by the remaining disallowed protocols; after removing all protocols, the user can use any protocol; removing non-existent protocols results in a successful API call but no actual change. 543 544**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_BLUETOOTH 545 546**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 547 548**Parameters** 549 550| Name| Type | Mandatory| Description | 551| ------ | ------------------------------------------------------- | ---- | ---------------------- | 552| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | EnterpriseAdminExtensionAbility.| 553| accountId | number | Yes | User ID, which must be greater than or equal to 0.<br> You can call [getOsAccountLocalId](../apis-basic-services-kit/js-apis-osAccount.md#getosaccountlocalid9-1) of @ohos.account.osAccount to obtain the ID.| 554| protocols | Array<[Protocol](#protocol20)> | Yes | Bluetooth protocol array.| 555 556**Error codes** 557 558For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 559 560| ID| Error Message | 561| -------- | ------------------------------------------------------------ | 562| 9200001 | The application is not an administrator application of the device. | 563| 9200002 | The administrator application does not have permission to manage the device. | 564| 201 | Permission verification failed. The application does not have the permission required to call the API. | 565 566**Example** 567 568```ts 569import { Want } from '@kit.AbilityKit'; 570import { bluetoothManager } from '@kit.MDMKit'; 571 572let wantTemp: Want = { 573 // Replace it as required. 574 bundleName: 'com.example.myapplication', 575 abilityName: 'EntryAbility' 576}; 577// Replace it as required. 578let accountId: number = 100; 579let protocols: Array<bluetoothManager.Protocol> = [bluetoothManager.Protocol.GATT, bluetoothManager.Protocol.SPP]; 580try{ 581 bluetoothManager.removeDisallowedBluetoothProtocols(wantTemp, accountId, protocols); 582 console.info('Succeeded in removing disallowed bluetooth protocols policy.'); 583} catch (err) { 584 console.error(`Failed to remove disallowed bluetooth protocols. Code: ${err.code}, message: ${err.message}`); 585} 586``` 587 588## bluetoothManager.getDisallowedBluetoothProtocols<sup>20+</sup> 589 590getDisallowedBluetoothProtocols(admin: Want, accountId: number): Array<Protocol> 591 592Obtains the disallowed Bluetooth protocols of a specified user. 593 594**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_BLUETOOTH 595 596**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 597 598**Parameters** 599 600| Name| Type | Mandatory| Description | 601| ------ | ------------------------------------------------------- | ---- | ---------------------- | 602| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | EnterpriseAdminExtensionAbility.| 603| accountId | number | Yes | User ID, which must be greater than or equal to 0.<br> You can call [getOsAccountLocalId](../apis-basic-services-kit/js-apis-osAccount.md#getosaccountlocalid9-1) of @ohos.account.osAccount to obtain the ID.| 604 605**Return value** 606 607| Type | Description | 608| -------------- | ----------------------------------- | 609| Array<[Protocol](#protocol20)> | Array of disallowed Bluetooth protocols.| 610 611**Error codes** 612 613For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 614 615| ID| Error Message | 616| -------- | ------------------------------------------------------------ | 617| 9200001 | The application is not an administrator application of the device. | 618| 9200002 | The administrator application does not have permission to manage the device. | 619| 201 | Permission verification failed. The application does not have the permission required to call the API. | 620 621**Example** 622 623```ts 624import { Want } from '@kit.AbilityKit'; 625import { bluetoothManager } from '@kit.MDMKit'; 626 627let wantTemp: Want = { 628 // Replace it as required. 629 bundleName: 'com.example.myapplication', 630 abilityName: 'EntryAbility' 631}; 632// Replace it as required. 633let accountId: number = 100; 634try{ 635 let result: Array<bluetoothManager.Protocol> = bluetoothManager.getDisallowedBluetoothProtocols(wantTemp, accountId); 636 console.info(`Succeeded in getting disallowed bluetooth protocols. Result: ${JSON.stringify(result)}`); 637} catch (err) { 638 console.error(`Failed to get disallowed bluetooth protocols. Code: ${err.code}, message: ${err.message}`); 639} 640``` 641 642## Protocol<sup>20+</sup> 643 644Represents the Bluetooth protocol type. 645 646**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 647 648| Name | Value | Description | 649| ----------------- | ---- | ----- | 650| GATT | 0 | [Generic Attribute Profile (GATT)](../../connectivity/terminology.md#gatt)| 651| SPP | 1 | [Serial Port Profile (SPP)](../../connectivity/terminology.md#spp)| 652<!--no_check-->