1# @ohos.enterprise.bundleManager(包管理)(系统接口) 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 10开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 14> 15> 本模块接口仅可在Stage模型下使用。 16> 17> 本模块接口仅对[设备管理应用](../../mdm/mdm-kit-term.md#mdm应用设备管理应用)开放,需将[设备管理应用激活](js-apis-enterprise-adminManager-sys.md#adminmanagerenableadmin-2)后调用。 18> 19> 当前页面仅包含本模块的系统接口,其他公开接口参见。其他公开接口参见[@ohos.enterprise.bundleManager](js-apis-enterprise-bundleManager.md)。 20 21## 导入模块 22 23```ts 24import { bundleManager } from '@kit.MDMKit'; 25``` 26 27## bundleManager.addAllowedInstallBundles 28 29addAllowedInstallBundles(admin: Want, appIds: Array\<string>, callback: AsyncCallback<void>): void 30 31添加应用至当前用户的应用程序包安装允许名单,添加至允许名单的应用允许在当前用户下安装,否则不允许安装,使用callback异步回调。 32 33**需要权限:** ohos.permission.ENTERPRISE_SET_BUNDLE_INSTALL_POLICY 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| appIds | Array<string> | 是 | 应用ID数组。 | 47| callback | AsyncCallback<void> | 是 | 回调函数。当接口调用成功,err为null,否则为错误对象。 | 48 49**错误码**: 50 51以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。 52 53| 错误码ID | 错误信息 | 54| ------- | ---------------------------------------------------------------------------- | 55| 9200001 | The application is not an administrator application of the device. | 56| 9200002 | The administrator application does not have permission to manage the device. | 57| 201 | Permission verification failed. The application does not have the permission required to call the API. | 58| 202 | Permission verification failed. A non-system application calls a system API. | 59| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 60 61**示例:** 62 63```ts 64import { bundleManager } from '@kit.MDMKit'; 65import { Want } from '@kit.AbilityKit'; 66 67let wantTemp: Want = { 68 // 需根据实际情况进行替换 69 bundleName: 'com.example.myapplication', 70 abilityName: 'EntryAbility' 71}; 72// 需根据实际情况进行替换 73let appIds: Array<string> = ['com.example.******_******/******5t5CoBM=']; 74 75bundleManager.addAllowedInstallBundles(wantTemp, appIds, (err) => { 76 if (err) { 77 console.error(`Failed to add allowed install bundles. Code is ${err.code}, message is ${err.message}`); 78 return; 79 } 80 console.info('Succeeded in adding allowed install bundles'); 81}); 82``` 83 84## bundleManager.addAllowedInstallBundles 85 86addAllowedInstallBundles(admin: Want, appIds: Array\<string>, userId: number, callback: AsyncCallback<void>): void 87 88添加应用至应用程序包安装允许名单,添加至允许名单的应用允许在指定用户(通过userId指定)下安装,否则不允许安装,使用callback异步回调。 89 90**需要权限:** ohos.permission.ENTERPRISE_SET_BUNDLE_INSTALL_POLICY 91 92**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager 93 94**模型约束:** 此接口仅可在Stage模型下使用。 95 96**系统接口:** 此接口为系统接口。 97 98**参数:** 99 100| 参数名 | 类型 | 必填 | 说明 | 101| ----- | ----------------------------------- | ---- | ------- | 102| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是 | 企业设备管理扩展组件。 | 103| appIds | Array<string> | 是 | 应用ID数组。 | 104| userId | number | 是 | 用户ID,指定具体用户。取值范围:大于等于0。 | 105| callback | AsyncCallback<void> | 是 | 回调函数,当接口调用成功,err为null,否则为错误对象。 | 106 107**错误码**: 108 109以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。 110 111| 错误码ID | 错误信息 | 112| ------- | ---------------------------------------------------------------------------- | 113| 9200001 | The application is not an administrator application of the device. | 114| 9200002 | The administrator application does not have permission to manage the device. | 115| 201 | Permission verification failed. The application does not have the permission required to call the API. | 116| 202 | Permission verification failed. A non-system application calls a system API. | 117| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 118 119**示例:** 120 121```ts 122import { bundleManager } from '@kit.MDMKit'; 123import { Want } from '@kit.AbilityKit'; 124 125let wantTemp: Want = { 126 // 需根据实际情况进行替换 127 bundleName: 'com.example.myapplication', 128 abilityName: 'EntryAbility' 129}; 130// 需根据实际情况进行替换 131let appIds: Array<string> = ['com.example.******_******/******5t5CoBM=']; 132 133bundleManager.addAllowedInstallBundles(wantTemp, appIds, 100, (err) => { 134 if (err) { 135 console.error(`Failed to add allowed install bundles. Code is ${err.code}, message is ${err.message}`); 136 return; 137 } 138 console.info('Succeeded in adding allowed install bundles'); 139}); 140``` 141 142## bundleManager.addAllowedInstallBundles 143 144addAllowedInstallBundles(admin: Want, appIds: Array\<string>, userId?: number): Promise<void> 145 146添加应用至应用程序包安装允许名单,添加至允许名单的应用允许在当前/指定用户下安装,否则不允许安装。使用promise异步回调。 147 148**需要权限:** ohos.permission.ENTERPRISE_SET_BUNDLE_INSTALL_POLICY 149 150**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager 151 152**模型约束:** 此接口仅可在Stage模型下使用。 153 154**系统接口:** 此接口为系统接口。 155 156**参数:** 157 158| 参数名 | 类型 | 必填 | 说明 | 159| ----- | ----------------------------------- | ---- | ------- | 160| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是 | 企业设备管理扩展组件。 | 161| appIds | Array<string> | 是 | 应用ID数组。 | 162| userId | number | 否 |用户ID,取值范围:大于等于0。<br> - 调用接口时,若传入userId,表示指定用户。<br> - 调用接口时,若未传入userId,表示当前用户。 | 163 164**返回值:** 165 166| 类型 | 说明 | 167| --------------------- | ------------------------- | 168| Promise<void> | 无返回结果的Promise对象。当添加应用程序包安装允许名单失败时,会抛出错误对象。 | 169 170**错误码**: 171 172以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。 173 174| 错误码ID | 错误信息 | 175| ------- | ---------------------------------------------------------------------------- | 176| 9200001 | The application is not an administrator application of the device. | 177| 9200002 | The administrator application does not have permission to manage the device. | 178| 201 | Permission verification failed. The application does not have the permission required to call the API. | 179| 202 | Permission verification failed. A non-system application calls a system API. | 180| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 181 182**示例:** 183 184```ts 185import { bundleManager } from '@kit.MDMKit'; 186import { Want } from '@kit.AbilityKit'; 187import { BusinessError } from '@kit.BasicServicesKit'; 188 189let wantTemp: Want = { 190 // 需根据实际情况进行替换 191 bundleName: 'com.example.myapplication', 192 abilityName: 'EntryAbility' 193}; 194// 需根据实际情况进行替换 195let appIds: Array<string> = ['com.example.******_******/******5t5CoBM=']; 196 197bundleManager.addAllowedInstallBundles(wantTemp, appIds, 100).then(() => { 198 console.info('Succeeded in adding allowed install bundles'); 199}).catch((err: BusinessError) => { 200 console.error(`Failed to add allowed install bundles. Code is ${err.code}, message is ${err.message}`); 201}); 202``` 203 204## bundleManager.removeAllowedInstallBundles 205 206removeAllowedInstallBundles(admin: Want, appIds: Array\<string>, callback: AsyncCallback<void>): void 207 208移除当前用户的应用程序包安装允许名单中的指定应用。安装允许名单存在时,不在允许名单中的应用不允许在当前用户下安装,使用callback异步回调。 209 210**需要权限:** ohos.permission.ENTERPRISE_SET_BUNDLE_INSTALL_POLICY 211 212**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager 213 214**模型约束:** 此接口仅可在Stage模型下使用。 215 216**系统接口:** 此接口为系统接口。 217 218**参数:** 219 220| 参数名 | 类型 | 必填 | 说明 | 221| -------- | ---------------------------------------- | ---- | ------------------------------- | 222| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是 | 企业设备管理扩展组件。 | 223| appIds | Array<string> | 是 | 应用ID数组。 | 224| callback | AsyncCallback<void> | 是 | 回调函数。当接口调用成功,err为null,否则为错误对象。 | 225 226**错误码**: 227 228以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。 229 230| 错误码ID | 错误信息 | 231| ------- | ---------------------------------------------------------------------------- | 232| 9200001 | The application is not an administrator application of the device. | 233| 9200002 | The administrator application does not have permission to manage the device. | 234| 201 | Permission verification failed. The application does not have the permission required to call the API. | 235| 202 | Permission verification failed. A non-system application calls a system API. | 236| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 237 238**示例:** 239 240```ts 241import { bundleManager } from '@kit.MDMKit'; 242import { Want } from '@kit.AbilityKit'; 243 244let wantTemp: Want = { 245 // 需根据实际情况进行替换 246 bundleName: 'com.example.myapplication', 247 abilityName: 'EntryAbility' 248}; 249// 需根据实际情况进行替换 250let appIds: Array<string> = ['com.example.******_******/******5t5CoBM=']; 251 252bundleManager.removeAllowedInstallBundles(wantTemp, appIds, (err) => { 253 if (err) { 254 console.error(`Failed to remove allowed install bundles. Code is ${err.code}, message is ${err.message}`); 255 return; 256 } 257 console.info('Succeeded in removing allowed install bundles'); 258}); 259``` 260 261## bundleManager.removeAllowedInstallBundles 262 263removeAllowedInstallBundles(admin: Want, appIds: Array\<string>, userId: number, callback: AsyncCallback<void>): void 264 265移除在应用程序包安装允许名单中的应用,在允许名单存在的情况下,不在允许名单中的应用不允许在指定用户(通过userId指定)下安装,使用callback异步回调。 266 267**需要权限:** ohos.permission.ENTERPRISE_SET_BUNDLE_INSTALL_POLICY 268 269**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager 270 271**模型约束:** 此接口仅可在Stage模型下使用。 272 273**系统接口:** 此接口为系统接口。 274 275**参数:** 276 277| 参数名 | 类型 | 必填 | 说明 | 278| ----- | ----------------------------------- | ---- | ------- | 279| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是 | 企业设备管理扩展组件。 | 280| appIds | Array<string> | 是 | 应用ID数组。 | 281| userId | number | 是 | 用户ID,指定具体用户。取值范围:大于等于0。 | 282| callback | AsyncCallback<void> | 是 | 回调函数。当接口调用成功,err为null,否则为错误对象。 | 283 284**错误码**: 285 286以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。 287 288| 错误码ID | 错误信息 | 289| ------- | ---------------------------------------------------------------------------- | 290| 9200001 | The application is not an administrator application of the device. | 291| 9200002 | The administrator application does not have permission to manage the device. | 292| 201 | Permission verification failed. The application does not have the permission required to call the API. | 293| 202 | Permission verification failed. A non-system application calls a system API. | 294| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 295 296**示例:** 297 298```ts 299import { bundleManager } from '@kit.MDMKit'; 300import { Want } from '@kit.AbilityKit'; 301 302let wantTemp: Want = { 303 // 需根据实际情况进行替换 304 bundleName: 'com.example.myapplication', 305 abilityName: 'EntryAbility' 306}; 307// 需根据实际情况进行替换 308let appIds: Array<string> = ['com.example.******_******/******5t5CoBM=']; 309 310bundleManager.removeAllowedInstallBundles(wantTemp, appIds, 100, (err) => { 311 if (err) { 312 console.error(`Failed to remove allowed install bundles. Code is ${err.code}, message is ${err.message}`); 313 return; 314 } 315 console.info('Succeeded in removing allowed install bundles'); 316}); 317``` 318 319## bundleManager.removeAllowedInstallBundles 320 321removeAllowedInstallBundles(admin: Want, appIds: Array\<string>, userId?: number): Promise<void> 322 323移除在应用程序包安装允许名单中的应用,在允许名单存在的情况下,不在允许名单中的应用不允许在当前/指定用户下安装。使用promise异步回调。 324 325**需要权限:** ohos.permission.ENTERPRISE_SET_BUNDLE_INSTALL_POLICY 326 327**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager 328 329**模型约束:** 此接口仅可在Stage模型下使用。 330 331**系统接口:** 此接口为系统接口。 332 333**参数:** 334 335| 参数名 | 类型 | 必填 | 说明 | 336| ----- | ----------------------------------- | ---- | ------- | 337| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是 | 企业设备管理扩展组件。 | 338| appIds | Array<string> | 是 | 应用ID数组。 | 339| userId | number | 否 | 用户ID,取值范围:大于等于0。<br> - 调用接口时,若传入userId,表示指定用户。<br> - 调用接口时,若未传入userId,表示当前用户。 | 340 341**返回值:** 342 343| 类型 | 说明 | 344| --------------------- | ------------------------- | 345| Promise<void> | 无返回结果的Promise对象。当移除应用程序包安装允许名单失败时,会抛出错误对象。 | 346 347**错误码**: 348 349以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。 350 351| 错误码ID | 错误信息 | 352| ------- | ---------------------------------------------------------------------------- | 353| 9200001 | The application is not an administrator application of the device. | 354| 9200002 | The administrator application does not have permission to manage the device. | 355| 201 | Permission verification failed. The application does not have the permission required to call the API. | 356| 202 | Permission verification failed. A non-system application calls a system API. | 357| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 358 359**示例:** 360 361```ts 362import { bundleManager } from '@kit.MDMKit'; 363import { Want } from '@kit.AbilityKit'; 364import { BusinessError } from '@kit.BasicServicesKit'; 365 366let wantTemp: Want = { 367 // 需根据实际情况进行替换 368 bundleName: 'com.example.myapplication', 369 abilityName: 'EntryAbility' 370}; 371// 需根据实际情况进行替换 372let appIds: Array<string> = ['com.example.******_******/******5t5CoBM=']; 373 374bundleManager.removeAllowedInstallBundles(wantTemp, appIds, 100).then(() => { 375 console.info('Succeeded in removing allowed install bundles'); 376}).catch((err: BusinessError) => { 377 console.error(`Failed to remove allowed install bundles. Code is ${err.code}, message is ${err.message}`); 378}); 379``` 380 381## bundleManager.getAllowedInstallBundles 382 383getAllowedInstallBundles(admin: Want, callback: AsyncCallback<Array<string>>): void 384 385获取当前用户下的应用程序包安装允许名单,使用callback异步回调。 386 387**需要权限:** ohos.permission.ENTERPRISE_SET_BUNDLE_INSTALL_POLICY 388 389**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager 390 391**模型约束:** 此接口仅可在Stage模型下使用。 392 393**系统接口:** 此接口为系统接口。 394 395**参数:** 396 397| 参数名 | 类型 | 必填 | 说明 | 398| -------- | ---------------------------------------- | ---- | ------------------------------- | 399| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是 | 企业设备管理扩展组件。 | 400| callback | AsyncCallback<Array<string>> | 是 | 回调函数,当接口调用成功,err为null,否则为错误对象。 | 401 402**错误码**: 403 404以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。 405 406| 错误码ID | 错误信息 | 407| ------- | ---------------------------------------------------------------------------- | 408| 9200001 | The application is not an administrator application of the device. | 409| 9200002 | The administrator application does not have permission to manage the device. | 410| 201 | Permission verification failed. The application does not have the permission required to call the API. | 411| 202 | Permission verification failed. A non-system application calls a system API. | 412| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 413 414**示例:** 415 416```ts 417import { bundleManager } from '@kit.MDMKit'; 418import { Want } from '@kit.AbilityKit'; 419 420let wantTemp: Want = { 421 // 需根据实际情况进行替换 422 bundleName: 'com.example.myapplication', 423 abilityName: 'EntryAbility' 424}; 425 426bundleManager.getAllowedInstallBundles(wantTemp, (err, result) => { 427 if (err) { 428 console.error(`Failed to get allowed install bundles. Code is ${err.code}, message is ${err.message}`); 429 return; 430 } 431 console.info(`Succeeded in getting allowed install bundles, result : ${JSON.stringify(result)}`); 432}); 433``` 434 435## bundleManager.getAllowedInstallBundles 436 437getAllowedInstallBundles(admin: Want, userId: number, callback: AsyncCallback<Array<string>>): void 438 439获取指定用户(通过userId指定)下的应用程序包安装允许名单,使用callback异步回调。 440 441**需要权限:** ohos.permission.ENTERPRISE_SET_BUNDLE_INSTALL_POLICY 442 443**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager 444 445**模型约束:** 此接口仅可在Stage模型下使用。 446 447**系统接口:** 此接口为系统接口。 448 449**参数:** 450 451| 参数名 | 类型 | 必填 | 说明 | 452| -------- | ---------------------------------------- | ---- | ------------------------------- | 453| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是 | 企业设备管理扩展组件。 | 454| userId | number | 是 | 用户ID,指定具体用户。取值范围:大于等于0。 | 455| callback | AsyncCallback<Array<string>> | 是 | 回调函数,当接口调用成功,err为null,否则为错误对象。 | 456 457**错误码**: 458 459以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。 460 461| 错误码ID | 错误信息 | 462| ------- | ---------------------------------------------------------------------------- | 463| 9200001 | The application is not an administrator application of the device. | 464| 9200002 | The administrator application does not have permission to manage the device. | 465| 201 | Permission verification failed. The application does not have the permission required to call the API. | 466| 202 | Permission verification failed. A non-system application calls a system API. | 467| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 468 469**示例:** 470 471```ts 472import { bundleManager } from '@kit.MDMKit'; 473import { Want } from '@kit.AbilityKit'; 474 475let wantTemp: Want = { 476 // 需根据实际情况进行替换 477 bundleName: 'com.example.myapplication', 478 abilityName: 'EntryAbility' 479}; 480 481bundleManager.getAllowedInstallBundles(wantTemp, 100, (err, result) => { 482 if (err) { 483 console.error(`Failed to get allowed install bundles. Code is ${err.code}, message is ${err.message}`); 484 return; 485 } 486 console.info(`Succeeded in getting allowed install bundles, result : ${JSON.stringify(result)}`); 487}); 488``` 489 490## bundleManager.getAllowedInstallBundles 491 492getAllowedInstallBundles(admin: Want, userId?: number): Promise<Array<string>> 493 494获取当前/指定用户下的应用程序包安装允许名单,使用promise异步回调。 495 496**需要权限:** ohos.permission.ENTERPRISE_SET_BUNDLE_INSTALL_POLICY 497 498**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager 499 500**模型约束:** 此接口仅可在Stage模型下使用。 501 502**系统接口:** 此接口为系统接口。 503 504**参数:** 505 506| 参数名 | 类型 | 必填 | 说明 | 507| ----- | ----------------------------------- | ---- | ------- | 508| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是 | 企业设备管理扩展组件。 | 509| userId | number | 否 | 用户ID,取值范围:大于等于0。<br> - 调用接口时,若传入userId,表示指定用户。<br> - 调用接口时,若未传入userId,表示当前用户。 | 510 511**返回值:** 512 513| 类型 | 说明 | 514| --------------------- | ------------------------- | 515| Promise<Array<string>> | Promise对象,返回当前/指定用户下的应用程序包安装允许名单。 | 516 517**错误码**: 518 519以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。 520 521| 错误码ID | 错误信息 | 522| ------- | ---------------------------------------------------------------------------- | 523| 9200001 | The application is not an administrator application of the device. | 524| 9200002 | The administrator application does not have permission to manage the device. | 525| 201 | Permission verification failed. The application does not have the permission required to call the API. | 526| 202 | Permission verification failed. A non-system application calls a system API. | 527| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 528 529**示例:** 530 531```ts 532import { bundleManager } from '@kit.MDMKit'; 533import { Want } from '@kit.AbilityKit'; 534import { BusinessError } from '@kit.BasicServicesKit'; 535 536let wantTemp: Want = { 537 // 需根据实际情况进行替换 538 bundleName: 'com.example.myapplication', 539 abilityName: 'EntryAbility' 540}; 541 542bundleManager.getAllowedInstallBundles(wantTemp, 100).then((result) => { 543 console.info(`Succeeded in getting allowed install bundles, result : ${JSON.stringify(result)}`); 544}).catch((err: BusinessError) => { 545 console.error(`Failed to get allowed install bundles. Code is ${err.code}, message is ${err.message}`); 546}); 547``` 548 549## bundleManager.addDisallowedInstallBundles 550 551addDisallowedInstallBundles(admin: Want, appIds: Array\<string>, callback: AsyncCallback<void>): void 552 553添加应用至应用程序包安装禁止名单,添加至禁止名单的应用不允许在当前用户下安装,使用callback异步回调。 554 555**需要权限:** ohos.permission.ENTERPRISE_SET_BUNDLE_INSTALL_POLICY 556 557**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager 558 559**模型约束:** 此接口仅可在Stage模型下使用。 560 561**系统接口:** 此接口为系统接口。 562 563**参数:** 564 565| 参数名 | 类型 | 必填 | 说明 | 566| -------- | ---------------------------------------- | ---- | ------------------------------- | 567| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是 | 企业设备管理扩展组件。 | 568| appIds | Array<string> | 是 | 应用ID数组。 | 569| callback | AsyncCallback<void> | 是 | 回调函数。当接口调用成功,err为null,否则为错误对象。 | 570 571**错误码**: 572 573以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。 574 575| 错误码ID | 错误信息 | 576| ------- | ---------------------------------------------------------------------------- | 577| 9200001 | The application is not an administrator application of the device. | 578| 9200002 | The administrator application does not have permission to manage the device. | 579| 201 | Permission verification failed. The application does not have the permission required to call the API. | 580| 202 | Permission verification failed. A non-system application calls a system API. | 581| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 582 583**示例:** 584 585```ts 586import { bundleManager } from '@kit.MDMKit'; 587import { Want } from '@kit.AbilityKit'; 588 589let wantTemp: Want = { 590 // 需根据实际情况进行替换 591 bundleName: 'com.example.myapplication', 592 abilityName: 'EntryAbility' 593}; 594// 需根据实际情况进行替换 595let appIds: Array<string> = ['com.example.******_******/******5t5CoBM=']; 596 597bundleManager.addDisallowedInstallBundles(wantTemp, appIds, (err) => { 598 if (err) { 599 console.error(`Failed to add disallowed install bundles. Code is ${err.code}, message is ${err.message}`); 600 return; 601 } 602 console.info('Succeeded in adding disallowed install bundles'); 603}); 604``` 605 606## bundleManager.addDisallowedInstallBundles 607 608addDisallowedInstallBundles(admin: Want, appIds: Array\<string>, userId: number, callback: AsyncCallback<void>): void 609 610添加应用至应用程序包安装禁止名单,添加至禁止名单的应用不允许在指定用户(通过userId指定)下安装。使用callback异步回调。 611 612**需要权限:** ohos.permission.ENTERPRISE_SET_BUNDLE_INSTALL_POLICY 613 614**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager 615 616**模型约束:** 此接口仅可在Stage模型下使用。 617 618**系统接口:** 此接口为系统接口。 619 620**参数:** 621 622| 参数名 | 类型 | 必填 | 说明 | 623| ----- | ----------------------------------- | ---- | ------- | 624| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是 | 企业设备管理扩展组件。 | 625| appIds | Array<string> | 是 | 应用ID数组。 | 626| userId | number | 是 | 用户ID,指定具体用户。取值范围:大于等于0。 | 627| callback | AsyncCallback<void> | 是 | 回调函数,当接口调用成功,err为null,否则为错误对象。 | 628 629**错误码**: 630 631以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。 632 633| 错误码ID | 错误信息 | 634| ------- | ---------------------------------------------------------------------------- | 635| 9200001 | The application is not an administrator application of the device. | 636| 9200002 | The administrator application does not have permission to manage the device. | 637| 201 | Permission verification failed. The application does not have the permission required to call the API. | 638| 202 | Permission verification failed. A non-system application calls a system API. | 639| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 640 641**示例:** 642 643```ts 644import { bundleManager } from '@kit.MDMKit'; 645import { Want } from '@kit.AbilityKit'; 646 647let wantTemp: Want = { 648 // 需根据实际情况进行替换 649 bundleName: 'com.example.myapplication', 650 abilityName: 'EntryAbility' 651}; 652// 需根据实际情况进行替换 653let appIds: Array<string> = ['com.example.******_******/******5t5CoBM=']; 654 655bundleManager.addDisallowedInstallBundles(wantTemp, appIds, 100, (err) => { 656 if (err) { 657 console.error(`Failed to add disallowed install bundles. Code is ${err.code}, message is ${err.message}`); 658 return; 659 } 660 console.info('Succeeded in adding disallowed install bundles'); 661}); 662``` 663 664## bundleManager.addDisallowedInstallBundles 665 666addDisallowedInstallBundles(admin: Want, appIds: Array\<string>, userId?: number): Promise<void> 667 668添加应用至应用程序包安装禁止名单,添加至禁止名单的应用不允许在当前/指定用户下安装。使用promise异步回调。 669 670**需要权限:** ohos.permission.ENTERPRISE_SET_BUNDLE_INSTALL_POLICY 671 672**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager 673 674**模型约束:** 此接口仅可在Stage模型下使用。 675 676**系统接口:** 此接口为系统接口。 677 678**参数:** 679 680| 参数名 | 类型 | 必填 | 说明 | 681| ----- | ----------------------------------- | ---- | ------- | 682| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是 | 企业设备管理扩展组件。 | 683| appIds | Array<string> | 是 | 应用ID数组。 | 684| userId | number | 否 | 用户ID,取值范围:大于等于0。<br> - 调用接口时,若传入userId,表示指定用户。<br> - 调用接口时,若未传入userId,表示当前用户。 | 685 686**返回值:** 687 688| 类型 | 说明 | 689| --------------------- | ------------------------- | 690| Promise<void> | 无返回结果的Promise对象。当添加应用程序包安装禁止名单失败时,会抛出错误对象。 | 691 692**错误码**: 693 694以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。 695 696| 错误码ID | 错误信息 | 697| ------- | ---------------------------------------------------------------------------- | 698| 9200001 | The application is not an administrator application of the device. | 699| 9200002 | The administrator application does not have permission to manage the device. | 700| 201 | Permission verification failed. The application does not have the permission required to call the API. | 701| 202 | Permission verification failed. A non-system application calls a system API. | 702| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 703 704**示例:** 705 706```ts 707import { bundleManager } from '@kit.MDMKit'; 708import { Want } from '@kit.AbilityKit'; 709import { BusinessError } from '@kit.BasicServicesKit'; 710 711let wantTemp: Want = { 712 // 需根据实际情况进行替换 713 bundleName: 'com.example.myapplication', 714 abilityName: 'EntryAbility' 715}; 716// 需根据实际情况进行替换 717let appIds: Array<string> = ['com.example.******_******/******5t5CoBM=']; 718 719bundleManager.addDisallowedInstallBundles(wantTemp, appIds, 100).then(() => { 720 console.info('Succeeded in adding disallowed install bundles'); 721}).catch((err: BusinessError) => { 722 console.error(`Failed to add disallowed install bundles. Code is ${err.code}, message is ${err.message}`); 723}); 724``` 725 726## bundleManager.removeDisallowedInstallBundles 727 728removeDisallowedInstallBundles(admin: Want, appIds: Array\<string>, callback: AsyncCallback<void>): void 729 730移除在应用程序包安装禁止名单中的应用,在禁止名单存在的情况下,在禁止名单中的应用不允许在当前用户下安装。使用callback异步回调。 731 732**需要权限:** ohos.permission.ENTERPRISE_SET_BUNDLE_INSTALL_POLICY 733 734**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager 735 736**模型约束:** 此接口仅可在Stage模型下使用。 737 738**系统接口:** 此接口为系统接口。 739 740**参数:** 741 742| 参数名 | 类型 | 必填 | 说明 | 743| -------- | ---------------------------------------- | ---- | ------------------------------- | 744| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是 | 企业设备管理扩展组件。 | 745| appIds | Array<string> | 是 | 应用ID数组。 | 746| callback | AsyncCallback<void> | 是 | 回调函数。当接口调用成功,err为null,否则为错误对象。 | 747 748**错误码**: 749 750以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。 751 752| 错误码ID | 错误信息 | 753| ------- | ---------------------------------------------------------------------------- | 754| 9200001 | The application is not an administrator application of the device. | 755| 9200002 | The administrator application does not have permission to manage the device. | 756| 201 | Permission verification failed. The application does not have the permission required to call the API. | 757| 202 | Permission verification failed. A non-system application calls a system API. | 758| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 759 760**示例:** 761 762```ts 763import { bundleManager } from '@kit.MDMKit'; 764import { Want } from '@kit.AbilityKit'; 765 766let wantTemp: Want = { 767 // 需根据实际情况进行替换 768 bundleName: 'com.example.myapplication', 769 abilityName: 'EntryAbility' 770}; 771// 需根据实际情况进行替换 772let appIds: Array<string> = ['com.example.******_******/******5t5CoBM=']; 773 774bundleManager.removeDisallowedInstallBundles(wantTemp, appIds, (err) => { 775 if (err) { 776 console.error(`Failed to remove disallowed install bundles. Code is ${err.code}, message is ${err.message}`); 777 return; 778 } 779 console.info('Succeeded in removing disallowed install bundles'); 780}); 781``` 782 783## bundleManager.removeDisallowedInstallBundles 784 785removeDisallowedInstallBundles(admin: Want, appIds: Array\<string>, userId: number, callback: AsyncCallback<void>): void 786 787移除在应用程序包安装禁止名单中的应用,在禁止名单存在的情况下,在禁止名单中的应用不允许在指定用户(通过userId指定)下安装,使用callback异步回调。 788 789**需要权限:** ohos.permission.ENTERPRISE_SET_BUNDLE_INSTALL_POLICY 790 791**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager 792 793**模型约束:** 此接口仅可在Stage模型下使用。 794 795**系统接口:** 此接口为系统接口。 796 797**参数:** 798 799| 参数名 | 类型 | 必填 | 说明 | 800| ----- | ----------------------------------- | ---- | ------- | 801| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是 | 企业设备管理扩展组件。 | 802| appIds | Array<string> | 是 | 应用ID数组。 | 803| userId | number | 是 | 用户ID,指定具体用户。取值范围:大于等于0。 | 804| callback | AsyncCallback<void> | 是 | 回调函数。当接口调用成功,err为null,否则为错误对象。 | 805 806**错误码**: 807 808以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。 809 810| 错误码ID | 错误信息 | 811| ------- | ---------------------------------------------------------------------------- | 812| 9200001 | The application is not an administrator application of the device. | 813| 9200002 | The administrator application does not have permission to manage the device. | 814| 201 | Permission verification failed. The application does not have the permission required to call the API. | 815| 202 | Permission verification failed. A non-system application calls a system API. | 816| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 817 818**示例:** 819 820```ts 821import { bundleManager } from '@kit.MDMKit'; 822import { Want } from '@kit.AbilityKit'; 823 824let wantTemp: Want = { 825 // 需根据实际情况进行替换 826 bundleName: 'com.example.myapplication', 827 abilityName: 'EntryAbility' 828}; 829// 需根据实际情况进行替换 830let appIds: Array<string> = ['com.example.******_******/******5t5CoBM=']; 831 832bundleManager.removeDisallowedInstallBundles(wantTemp, appIds, 100, (err) => { 833 if (err) { 834 console.error(`Failed to remove disallowed install bundles. Code is ${err.code}, message is ${err.message}`); 835 return; 836 } 837 console.info('Succeeded in removing disallowed install bundles'); 838}); 839``` 840 841## bundleManager.removeDisallowedInstallBundles 842 843removeDisallowedInstallBundles(admin: Want, appIds: Array\<string>, userId?: number): Promise<void> 844 845移除在应用程序包安装禁止名单中的应用,在禁止名单存在的情况下,在禁止名单中的应用不允许在当前/指定用户下安装。使用promise异步回调。 846 847**需要权限:** ohos.permission.ENTERPRISE_SET_BUNDLE_INSTALL_POLICY 848 849**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager 850 851**模型约束:** 此接口仅可在Stage模型下使用。 852 853**系统接口:** 此接口为系统接口。 854 855**参数:** 856 857| 参数名 | 类型 | 必填 | 说明 | 858| ----- | ----------------------------------- | ---- | ------- | 859| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是 | 企业设备管理扩展组件。 | 860| appIds | Array<string> | 是 | 应用ID数组。 | 861| userId | number | 否 | 用户ID,取值范围:大于等于0。<br> - 调用接口时,若传入userId,表示指定用户。<br> - 调用接口时,若未传入userId,表示当前用户。 | 862 863**返回值:** 864 865| 类型 | 说明 | 866| --------------------- | ------------------------- | 867| Promise<void> | 无返回结果的Promise对象。当移除应用程序包安装禁止名单失败时,会抛出错误对象。 | 868 869**错误码**: 870 871以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。 872 873| 错误码ID | 错误信息 | 874| ------- | ---------------------------------------------------------------------------- | 875| 9200001 | The application is not an administrator application of the device. | 876| 9200002 | The administrator application does not have permission to manage the device. | 877| 201 | Permission verification failed. The application does not have the permission required to call the API. | 878| 202 | Permission verification failed. A non-system application calls a system API. | 879| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 880 881**示例:** 882 883```ts 884import { bundleManager } from '@kit.MDMKit'; 885import { Want } from '@kit.AbilityKit'; 886import { BusinessError } from '@kit.BasicServicesKit'; 887 888let wantTemp: Want = { 889 // 需根据实际情况进行替换 890 bundleName: 'com.example.myapplication', 891 abilityName: 'EntryAbility' 892}; 893// 需根据实际情况进行替换 894let appIds: Array<string> = ['com.example.******_******/******5t5CoBM=']; 895 896bundleManager.removeDisallowedInstallBundles(wantTemp, appIds, 100).then(() => { 897 console.info('Succeeded in removing disallowed install bundles'); 898}).catch((err: BusinessError) => { 899 console.error(`Failed to remove disallowed install bundles. Code is ${err.code}, message is ${err.message}`); 900}); 901``` 902 903## bundleManager.getDisallowedInstallBundles 904 905getDisallowedInstallBundles(admin: Want, callback: AsyncCallback<Array<string>>): void 906 907获取当前用户下的应用程序包安装禁止名单,使用callback异步回调。 908 909**需要权限:** ohos.permission.ENTERPRISE_SET_BUNDLE_INSTALL_POLICY 910 911**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager 912 913**模型约束:** 此接口仅可在Stage模型下使用。 914 915**系统接口:** 此接口为系统接口。 916 917**参数:** 918 919| 参数名 | 类型 | 必填 | 说明 | 920| -------- | ---------------------------------------- | ---- | ------------------------------- | 921| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是 | 企业设备管理扩展组件。 | 922| callback | AsyncCallback<Array<string>> | 是 | 回调函数,当接口调用成功,err为null,否则为错误对象。 | 923 924**错误码**: 925 926以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。 927 928| 错误码ID | 错误信息 | 929| ------- | ---------------------------------------------------------------------------- | 930| 9200001 | The application is not an administrator application of the device. | 931| 9200002 | The administrator application does not have permission to manage the device. | 932| 201 | Permission verification failed. The application does not have the permission required to call the API. | 933| 202 | Permission verification failed. A non-system application calls a system API. | 934| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 935 936**示例:** 937 938```ts 939import { bundleManager } from '@kit.MDMKit'; 940import { Want } from '@kit.AbilityKit'; 941 942let wantTemp: Want = { 943 // 需根据实际情况进行替换 944 bundleName: 'com.example.myapplication', 945 abilityName: 'EntryAbility' 946}; 947 948bundleManager.getDisallowedInstallBundles(wantTemp, (err, result) => { 949 if (err) { 950 console.error(`Failed to get disallowed install bundles. Code is ${err.code}, message is ${err.message}`); 951 return; 952 } 953 console.info(`Succeeded in getting disallowed install bundles, result : ${JSON.stringify(result)}`); 954}); 955``` 956 957## bundleManager.getDisallowedInstallBundles 958 959getDisallowedInstallBundles(admin: Want, userId: number, callback: AsyncCallback<Array<string>>): void 960 961获取指定用户(通过userId指定)下的应用程序包安装禁止名单,使用callback异步回调。 962 963**需要权限:** ohos.permission.ENTERPRISE_SET_BUNDLE_INSTALL_POLICY 964 965**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager 966 967**模型约束:** 此接口仅可在Stage模型下使用。 968 969**系统接口:** 此接口为系统接口。 970 971**参数:** 972 973| 参数名 | 类型 | 必填 | 说明 | 974| -------- | ---------------------------------------- | ---- | ------------------------------- | 975| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是 | 企业设备管理扩展组件。 | 976| userId | number | 是 | 用户ID,指定具体用户。取值范围:大于等于0。 | 977| callback | AsyncCallback<Array<string>> | 是 | 回调函数,当接口调用成功,err为null,否则为错误对象。 | 978 979**错误码**: 980 981以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。 982 983| 错误码ID | 错误信息 | 984| ------- | ---------------------------------------------------------------------------- | 985| 9200001 | The application is not an administrator application of the device. | 986| 9200002 | The administrator application does not have permission to manage the device. | 987| 201 | Permission verification failed. The application does not have the permission required to call the API. | 988| 202 | Permission verification failed. A non-system application calls a system API. | 989| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 990 991**示例:** 992 993```ts 994import { bundleManager } from '@kit.MDMKit'; 995import { Want } from '@kit.AbilityKit'; 996 997let wantTemp: Want = { 998 // 需根据实际情况进行替换 999 bundleName: 'com.example.myapplication', 1000 abilityName: 'EntryAbility' 1001}; 1002 1003bundleManager.getDisallowedInstallBundles(wantTemp, 100, (err, result) => { 1004 if (err) { 1005 console.error(`Failed to get disallowed install bundles. Code is ${err.code}, message is ${err.message}`); 1006 return; 1007 } 1008 console.info(`Succeeded in getting disallowed install bundles, result : ${JSON.stringify(result)}`); 1009}); 1010``` 1011 1012## bundleManager.getDisallowedInstallBundles 1013 1014getDisallowedInstallBundles(admin: Want, userId?: number): Promise<Array<string>> 1015 1016获取当前/指定用户下的应用程序包安装禁止名单,使用promise异步回调。 1017 1018**需要权限:** ohos.permission.ENTERPRISE_SET_BUNDLE_INSTALL_POLICY 1019 1020**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager 1021 1022**模型约束:** 此接口仅可在Stage模型下使用。 1023 1024**系统接口:** 此接口为系统接口。 1025 1026**参数:** 1027 1028| 参数名 | 类型 | 必填 | 说明 | 1029| ----- | ----------------------------------- | ---- | ------- | 1030| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是 | 企业设备管理扩展组件。 | 1031| userId | number | 否 | 用户ID,取值范围:大于等于0。<br> - 调用接口时,若传入userId,表示指定用户。<br> - 调用接口时,若未传入userId,表示当前用户。 | 1032 1033**返回值:** 1034 1035| 类型 | 说明 | 1036| --------------------- | ------------------------- | 1037| Promise<Array<string>> | Promise对象,返回当前/指定用户下的应用程序包安装禁止名单。 | 1038 1039**错误码**: 1040 1041以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。 1042 1043| 错误码ID | 错误信息 | 1044| ------- | ---------------------------------------------------------------------------- | 1045| 9200001 | The application is not an administrator application of the device. | 1046| 9200002 | The administrator application does not have permission to manage the device. | 1047| 201 | Permission verification failed. The application does not have the permission required to call the API. | 1048| 202 | Permission verification failed. A non-system application calls a system API. | 1049| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1050 1051**示例:** 1052 1053```ts 1054import { bundleManager } from '@kit.MDMKit'; 1055import { Want } from '@kit.AbilityKit'; 1056import { BusinessError } from '@kit.BasicServicesKit'; 1057 1058let wantTemp: Want = { 1059 // 需根据实际情况进行替换 1060 bundleName: 'com.example.myapplication', 1061 abilityName: 'EntryAbility' 1062}; 1063 1064bundleManager.getDisallowedInstallBundles(wantTemp, 100).then((result) => { 1065 console.info(`Succeeded in getting disallowed install bundles, result : ${JSON.stringify(result)}`); 1066}).catch((err: BusinessError) => { 1067 console.error(`Failed to get disallowed install bundles. Code is ${err.code}, message is ${err.message}`); 1068}); 1069``` 1070 1071## bundleManager.addDisallowedUninstallBundles 1072 1073addDisallowedUninstallBundles(admin: Want, appIds: Array\<string>, callback: AsyncCallback<void>): void 1074 1075添加应用至应用程序包卸载禁止名单,添加至禁止名单的应用不允许在当前用户下卸载,使用callback异步回调。 1076 1077**需要权限:** ohos.permission.ENTERPRISE_SET_BUNDLE_INSTALL_POLICY 1078 1079**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager 1080 1081**模型约束:** 此接口仅可在Stage模型下使用。 1082 1083**系统接口:** 此接口为系统接口。 1084 1085**参数:** 1086 1087| 参数名 | 类型 | 必填 | 说明 | 1088| -------- | ---------------------------------------- | ---- | ------------------------------- | 1089| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是 | 企业设备管理扩展组件。 | 1090| appIds | Array<string> | 是 | 应用ID数组。 | 1091| callback | AsyncCallback<void> | 是 | 回调函数。当接口调用成功,err为null,否则为错误对象。 | 1092 1093**错误码**: 1094 1095以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。 1096 1097| 错误码ID | 错误信息 | 1098| ------- | ---------------------------------------------------------------------------- | 1099| 9200001 | The application is not an administrator application of the device. | 1100| 9200002 | The administrator application does not have permission to manage the device. | 1101| 201 | Permission verification failed. The application does not have the permission required to call the API. | 1102| 202 | Permission verification failed. A non-system application calls a system API. | 1103| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1104 1105**示例:** 1106 1107```ts 1108import { bundleManager } from '@kit.MDMKit'; 1109import { Want } from '@kit.AbilityKit'; 1110 1111let wantTemp: Want = { 1112 // 需根据实际情况进行替换 1113 bundleName: 'com.example.myapplication', 1114 abilityName: 'EntryAbility' 1115}; 1116// 需根据实际情况进行替换 1117let appIds: Array<string> = ['com.example.******_******/******5t5CoBM=']; 1118 1119bundleManager.addDisallowedUninstallBundles(wantTemp, appIds, (err) => { 1120 if (err) { 1121 console.error(`Failed to add disallowed uninstall bundles. Code is ${err.code}, message is ${err.message}`); 1122 return; 1123 } 1124 console.info('Succeeded in adding disallowed uninstall bundles'); 1125}); 1126``` 1127 1128## bundleManager.addDisallowedUninstallBundles 1129 1130addDisallowedUninstallBundles(admin: Want, appIds: Array\<string>, userId: number, callback: AsyncCallback<void>): void 1131 1132添加应用至应用程序包卸载禁止名单,添加至禁止名单的应用不允许在指定用户(通过userId指定)下卸载。使用callback异步回调。 1133 1134**需要权限:** ohos.permission.ENTERPRISE_SET_BUNDLE_INSTALL_POLICY 1135 1136**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager 1137 1138**模型约束:** 此接口仅可在Stage模型下使用。 1139 1140**系统接口:** 此接口为系统接口。 1141 1142**参数:** 1143 1144| 参数名 | 类型 | 必填 | 说明 | 1145| ----- | ----------------------------------- | ---- | ------- | 1146| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是 | 企业设备管理扩展组件。 | 1147| appIds | Array<string> | 是 | 应用ID数组。 | 1148| userId | number | 是 | 用户ID,指定具体用户。取值范围:大于等于0。 | 1149| callback | AsyncCallback<void> | 是 | 回调函数,当接口调用成功,err为null,否则为错误对象。 | 1150 1151**错误码**: 1152 1153以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。 1154 1155| 错误码ID | 错误信息 | 1156| ------- | ---------------------------------------------------------------------------- | 1157| 9200001 | The application is not an administrator application of the device. | 1158| 9200002 | The administrator application does not have permission to manage the device. | 1159| 201 | Permission verification failed. The application does not have the permission required to call the API. | 1160| 202 | Permission verification failed. A non-system application calls a system API. | 1161| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1162 1163**示例:** 1164 1165```ts 1166import { bundleManager } from '@kit.MDMKit'; 1167import { Want } from '@kit.AbilityKit'; 1168 1169let wantTemp: Want = { 1170 // 需根据实际情况进行替换 1171 bundleName: 'com.example.myapplication', 1172 abilityName: 'EntryAbility' 1173}; 1174// 需根据实际情况进行替换 1175let appIds: Array<string> = ['com.example.******_******/******5t5CoBM=']; 1176 1177bundleManager.addDisallowedUninstallBundles(wantTemp, appIds, 100, (err) => { 1178 if (err) { 1179 console.error(`Failed to add disallowed uninstall bundles. Code is ${err.code}, message is ${err.message}`); 1180 return; 1181 } 1182 console.info('Succeeded in adding disallowed uninstall bundles'); 1183}); 1184``` 1185 1186## bundleManager.addDisallowedUninstallBundles 1187 1188addDisallowedUninstallBundles(admin: Want, appIds: Array\<string>, userId?: number): Promise<void> 1189 1190添加应用至应用程序包卸载禁止名单,添加至禁止名单的应用不允许在当前/指定用户下卸载。使用promise异步回调。 1191 1192**需要权限:** ohos.permission.ENTERPRISE_SET_BUNDLE_INSTALL_POLICY 1193 1194**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager 1195 1196**模型约束:** 此接口仅可在Stage模型下使用。 1197 1198**系统接口:** 此接口为系统接口。 1199 1200**参数:** 1201 1202| 参数名 | 类型 | 必填 | 说明 | 1203| ----- | ----------------------------------- | ---- | ------- | 1204| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是 | 企业设备管理扩展组件。 | 1205| appIds | Array<string> | 是 | 应用ID数组。 | 1206| userId | number | 否 | 用户ID,取值范围:大于等于0。<br> - 调用接口时,若传入userId,表示指定用户。<br> - 调用接口时,若未传入userId,表示当前用户。 | 1207 1208**返回值:** 1209 1210| 类型 | 说明 | 1211| --------------------- | ------------------------- | 1212| Promise<void> | 无返回结果的Promise对象。当添加应用程序包卸载禁止名单失败时,会抛出错误对象。 | 1213 1214**错误码**: 1215 1216以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。 1217 1218| 错误码ID | 错误信息 | 1219| ------- | ---------------------------------------------------------------------------- | 1220| 9200001 | The application is not an administrator application of the device. | 1221| 9200002 | The administrator application does not have permission to manage the device. | 1222| 201 | Permission verification failed. The application does not have the permission required to call the API. | 1223| 202 | Permission verification failed. A non-system application calls a system API. | 1224| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1225 1226**示例:** 1227 1228```ts 1229import { bundleManager } from '@kit.MDMKit'; 1230import { Want } from '@kit.AbilityKit'; 1231import { BusinessError } from '@kit.BasicServicesKit'; 1232 1233let wantTemp: Want = { 1234 // 需根据实际情况进行替换 1235 bundleName: 'com.example.myapplication', 1236 abilityName: 'EntryAbility' 1237}; 1238// 需根据实际情况进行替换 1239let appIds: Array<string> = ['com.example.******_******/******5t5CoBM=']; 1240 1241bundleManager.addDisallowedUninstallBundles(wantTemp, appIds, 100).then(() => { 1242 console.info('Succeeded in adding disallowed uninstall bundles'); 1243}).catch((err: BusinessError) => { 1244 console.error(`Failed to add disallowed uninstall bundles. Code is ${err.code}, message is ${err.message}`); 1245}); 1246``` 1247 1248## bundleManager.removeDisallowedUninstallBundles 1249 1250removeDisallowedUninstallBundles(admin: Want, appIds: Array\<string>, callback: AsyncCallback<void>): void 1251 1252移除在应用程序包卸载禁止名单中的应用,在禁止名单存在的情况下,在禁止名单中的应用不允许在当前用户下卸载,使用callback异步回调。 1253 1254**需要权限:** ohos.permission.ENTERPRISE_SET_BUNDLE_INSTALL_POLICY 1255 1256**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager 1257 1258**模型约束:** 此接口仅可在Stage模型下使用。 1259 1260**系统接口:** 此接口为系统接口。 1261 1262**参数:** 1263 1264| 参数名 | 类型 | 必填 | 说明 | 1265| -------- | ---------------------------------------- | ---- | ------------------------------- | 1266| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是 | 企业设备管理扩展组件。 | 1267| appIds | Array<string> | 是 | 应用ID数组。 | 1268| callback | AsyncCallback<void> | 是 | 回调函数。当接口调用成功,err为null,否则为错误对象。 | 1269 1270**错误码**: 1271 1272以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。 1273 1274| 错误码ID | 错误信息 | 1275| ------- | ---------------------------------------------------------------------------- | 1276| 9200001 | The application is not an administrator application of the device. | 1277| 9200002 | The administrator application does not have permission to manage the device. | 1278| 201 | Permission verification failed. The application does not have the permission required to call the API. | 1279| 202 | Permission verification failed. A non-system application calls a system API. | 1280| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1281 1282**示例:** 1283 1284```ts 1285import { bundleManager } from '@kit.MDMKit'; 1286import { Want } from '@kit.AbilityKit'; 1287 1288let wantTemp: Want = { 1289 // 需根据实际情况进行替换 1290 bundleName: 'com.example.myapplication', 1291 abilityName: 'EntryAbility' 1292}; 1293// 需根据实际情况进行替换 1294let appIds: Array<string> = ['com.example.******_******/******5t5CoBM=']; 1295 1296bundleManager.removeDisallowedUninstallBundles(wantTemp, appIds, (err) => { 1297 if (err) { 1298 console.error(`Failed to remove disallowed uninstall bundles. Code is ${err.code}, message is ${err.message}`); 1299 return; 1300 } 1301 console.info('Succeeded in removing disallowed uninstall bundles'); 1302}); 1303``` 1304 1305## bundleManager.removeDisallowedUninstallBundles 1306 1307removeDisallowedUninstallBundles(admin: Want, appIds: Array\<string>, userId: number, callback: AsyncCallback<void>): void 1308 1309移除在应用程序包卸载禁止名单中的应用,在禁止名单存在的情况下,在禁止名单中的应用不允许在指定用户(通过userId指定)下卸载。使用callback异步回调。 1310 1311**需要权限:** ohos.permission.ENTERPRISE_SET_BUNDLE_INSTALL_POLICY 1312 1313**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager 1314 1315**模型约束:** 此接口仅可在Stage模型下使用。 1316 1317**系统接口:** 此接口为系统接口。 1318 1319**参数:** 1320 1321| 参数名 | 类型 | 必填 | 说明 | 1322| ----- | ----------------------------------- | ---- | ------- | 1323| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是 | 企业设备管理扩展组件。 | 1324| appIds | Array<string> | 是 | 应用ID数组。 | 1325| userId | number | 是 | 用户ID,指定具体用户。取值范围:大于等于0。 | 1326| callback | AsyncCallback<void> | 是 | 回调函数。当接口调用成功,err为null,否则为错误对象。 | 1327 1328**错误码**: 1329 1330以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。 1331 1332| 错误码ID | 错误信息 | 1333| ------- | ---------------------------------------------------------------------------- | 1334| 9200001 | The application is not an administrator application of the device. | 1335| 9200002 | The administrator application does not have permission to manage the device. | 1336| 201 | Permission verification failed. The application does not have the permission required to call the API. | 1337| 202 | Permission verification failed. A non-system application calls a system API. | 1338| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1339 1340**示例:** 1341 1342```ts 1343import { bundleManager } from '@kit.MDMKit'; 1344import { Want } from '@kit.AbilityKit'; 1345 1346let wantTemp: Want = { 1347 // 需根据实际情况进行替换 1348 bundleName: 'com.example.myapplication', 1349 abilityName: 'EntryAbility' 1350}; 1351// 需根据实际情况进行替换 1352let appIds: Array<string> = ['com.example.******_******/******5t5CoBM=']; 1353 1354bundleManager.removeDisallowedUninstallBundles(wantTemp, appIds, 100, (err) => { 1355 if (err) { 1356 console.error(`Failed to remove disallowed uninstall bundles. Code is ${err.code}, message is ${err.message}`); 1357 return; 1358 } 1359 console.info('Succeeded in removing disallowed uninstall bundles'); 1360}); 1361``` 1362 1363## bundleManager.removeDisallowedUninstallBundles 1364 1365removeDisallowedUninstallBundles(admin: Want, appIds: Array\<string>, userId?: number): Promise<void> 1366 1367移除在应用程序包卸载禁止名单中的应用。在禁止名单存在的情况下,在禁止名单中的应用不允许在当前/指定用户下卸载。使用promise异步回调。 1368 1369**需要权限:** ohos.permission.ENTERPRISE_SET_BUNDLE_INSTALL_POLICY 1370 1371**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager 1372 1373**模型约束:** 此接口仅可在Stage模型下使用。 1374 1375**系统接口:** 此接口为系统接口。 1376 1377**参数:** 1378 1379| 参数名 | 类型 | 必填 | 说明 | 1380| ----- | ----------------------------------- | ---- | ------- | 1381| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是 | 企业设备管理扩展组件。 | 1382| appIds | Array<string> | 是 | 应用ID数组。 | 1383| userId | number | 否 | 用户ID,取值范围:大于等于0。<br> - 调用接口时,若传入userId,表示指定用户。<br> - 调用接口时,若未传入userId,表示当前用户。 | 1384 1385**返回值:** 1386 1387| 类型 | 说明 | 1388| --------------------- | ------------------------- | 1389| Promise<void> | 无返回结果的Promise对象。当移除应用程序包卸载禁止名单失败时会抛出错误对象。 | 1390 1391**错误码**: 1392 1393以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。 1394 1395| 错误码ID | 错误信息 | 1396| ------- | ---------------------------------------------------------------------------- | 1397| 9200001 | The application is not an administrator application of the device. | 1398| 9200002 | The administrator application does not have permission to manage the device. | 1399| 201 | Permission verification failed. The application does not have the permission required to call the API. | 1400| 202 | Permission verification failed. A non-system application calls a system API. | 1401| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1402 1403**示例:** 1404 1405```ts 1406import { bundleManager } from '@kit.MDMKit'; 1407import { Want } from '@kit.AbilityKit'; 1408import { BusinessError } from '@kit.BasicServicesKit'; 1409 1410let wantTemp: Want = { 1411 // 需根据实际情况进行替换 1412 bundleName: 'com.example.myapplication', 1413 abilityName: 'EntryAbility' 1414}; 1415// 需根据实际情况进行替换 1416let appIds: Array<string> = ['com.example.******_******/******5t5CoBM=']; 1417 1418bundleManager.removeDisallowedUninstallBundles(wantTemp, appIds, 100).then(() => { 1419 console.info('Succeeded in removing disallowed uninstall bundles'); 1420}).catch((err: BusinessError) => { 1421 console.error(`Failed to remove disallowed uninstall bundles. Code is ${err.code}, message is ${err.message}`); 1422}); 1423``` 1424 1425## bundleManager.getDisallowedUninstallBundles 1426 1427getDisallowedUninstallBundles(admin: Want, callback: AsyncCallback<Array<string>>): void 1428 1429获取当前用户下的应用程序包卸载禁止名单,使用callback异步回调。 1430 1431**需要权限:** ohos.permission.ENTERPRISE_SET_BUNDLE_INSTALL_POLICY 1432 1433**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager 1434 1435**模型约束:** 此接口仅可在Stage模型下使用。 1436 1437**系统接口:** 此接口为系统接口。 1438 1439**参数:** 1440 1441| 参数名 | 类型 | 必填 | 说明 | 1442| -------- | ---------------------------------------- | ---- | ------------------------------- | 1443| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是 | 企业设备管理扩展组件。 | 1444| callback | AsyncCallback<Array<string>> | 是 | 回调函数,当接口调用成功,err为null,否则为错误对象。 | 1445 1446**错误码**: 1447 1448以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。 1449 1450| 错误码ID | 错误信息 | 1451| ------- | ---------------------------------------------------------------------------- | 1452| 9200001 | The application is not an administrator application of the device. | 1453| 9200002 | The administrator application does not have permission to manage the device. | 1454| 201 | Permission verification failed. The application does not have the permission required to call the API. | 1455| 202 | Permission verification failed. A non-system application calls a system API. | 1456| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1457 1458**示例:** 1459 1460```ts 1461import { bundleManager } from '@kit.MDMKit'; 1462import { Want } from '@kit.AbilityKit'; 1463 1464let wantTemp: Want = { 1465 // 需根据实际情况进行替换 1466 bundleName: 'com.example.myapplication', 1467 abilityName: 'EntryAbility' 1468}; 1469 1470bundleManager.getDisallowedUninstallBundles(wantTemp, (err, result) => { 1471 if (err) { 1472 console.error(`Failed to get disallowed uninstall bundles. Code is ${err.code}, message is ${err.message}`); 1473 return; 1474 } 1475 console.info(`Succeeded in getting disallowed uninstall bundles, result : ${JSON.stringify(result)}`); 1476}); 1477``` 1478 1479## bundleManager.getDisallowedUninstallBundles 1480 1481getDisallowedUninstallBundles(admin: Want, userId: number, callback: AsyncCallback<Array<string>>): void 1482 1483获取指定用户(通过userId指定)下的应用程序包卸载禁止名单,使用callback异步回调。 1484 1485**需要权限:** ohos.permission.ENTERPRISE_SET_BUNDLE_INSTALL_POLICY 1486 1487**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager 1488 1489**模型约束:** 此接口仅可在Stage模型下使用。 1490 1491**系统接口:** 此接口为系统接口。 1492 1493**参数:** 1494 1495| 参数名 | 类型 | 必填 | 说明 | 1496| -------- | ---------------------------------------- | ---- | ------------------------------- | 1497| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是 | 企业设备管理扩展组件。 | 1498| userId | number | 是 | 用户ID,指定具体用户。取值范围:大于等于0。 | 1499| callback | AsyncCallback<Array<string>> | 是 | 回调函数,当接口调用成功,err为null,否则为错误对象。 | 1500 1501**错误码**: 1502 1503以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。 1504 1505| 错误码ID | 错误信息 | 1506| ------- | ---------------------------------------------------------------------------- | 1507| 9200001 | The application is not an administrator application of the device. | 1508| 9200002 | The administrator application does not have permission to manage the device. | 1509| 201 | Permission verification failed. The application does not have the permission required to call the API. | 1510| 202 | Permission verification failed. A non-system application calls a system API. | 1511| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1512 1513**示例:** 1514 1515```ts 1516import { bundleManager } from '@kit.MDMKit'; 1517import { Want } from '@kit.AbilityKit'; 1518 1519let wantTemp: Want = { 1520 // 需根据实际情况进行替换 1521 bundleName: 'com.example.myapplication', 1522 abilityName: 'EntryAbility' 1523}; 1524 1525bundleManager.getDisallowedUninstallBundles(wantTemp, 100, (err, result) => { 1526 if (err) { 1527 console.error(`Failed to get disallowed uninstall bundles. Code is ${err.code}, message is ${err.message}`); 1528 return; 1529 } 1530 console.info(`Succeeded in getting disallowed uninstall bundles, result : ${JSON.stringify(result)}`); 1531}); 1532``` 1533 1534## bundleManager.getDisallowedUninstallBundles 1535 1536getDisallowedUninstallBundles(admin: Want, userId?: number): Promise<Array<string>> 1537 1538获取当前/指定用户下应用程序包卸载禁止名单接口,使用promise异步回调。 1539 1540**需要权限:** ohos.permission.ENTERPRISE_SET_BUNDLE_INSTALL_POLICY 1541 1542**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager 1543 1544**模型约束:** 此接口仅可在Stage模型下使用。 1545 1546**系统接口:** 此接口为系统接口。 1547 1548**参数:** 1549 1550| 参数名 | 类型 | 必填 | 说明 | 1551| ----- | ----------------------------------- | ---- | ------- | 1552| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是 | 企业设备管理扩展组件。 | 1553| userId | number | 否 | 用户ID,取值范围:大于等于0。<br> - 调用接口时,若传入userId,表示指定用户。<br> - 调用接口时,若未传入userId,表示当前用户。 | 1554 1555**返回值:** 1556 1557| 类型 | 说明 | 1558| --------------------- | ------------------------- | 1559| Promise<Array<string>> | Promise对象,返回当前/指定用户下的应用程序包卸载禁止名单。 | 1560 1561**错误码**: 1562 1563以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。 1564 1565| 错误码ID | 错误信息 | 1566| ------- | ---------------------------------------------------------------------------- | 1567| 9200001 | The application is not an administrator application of the device. | 1568| 9200002 | The administrator application does not have permission to manage the device. | 1569| 201 | Permission verification failed. The application does not have the permission required to call the API. | 1570| 202 | Permission verification failed. A non-system application calls a system API. | 1571| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1572 1573**示例:** 1574 1575```ts 1576import { bundleManager } from '@kit.MDMKit'; 1577import { Want } from '@kit.AbilityKit'; 1578import { BusinessError } from '@kit.BasicServicesKit'; 1579 1580let wantTemp: Want = { 1581 // 需根据实际情况进行替换 1582 bundleName: 'com.example.myapplication', 1583 abilityName: 'EntryAbility' 1584}; 1585 1586bundleManager.getDisallowedUninstallBundles(wantTemp, 100).then((result) => { 1587 console.info(`Succeeded in getting disallowed uninstall bundles, result : ${JSON.stringify(result)}`); 1588}).catch((err: BusinessError) => { 1589 console.error(`Failed to get disallowed uninstall bundles. Code is ${err.code}, message is ${err.message}`); 1590}); 1591``` 1592 1593## bundleManager.uninstall 1594 1595uninstall(admin: Want, bundleName: string, callback: AsyncCallback<void>): void 1596 1597卸载当前用户下的指定应用程序包,且不保留应用程序包数据。使用callback异步回调。 1598 1599**需要权限:** ohos.permission.ENTERPRISE_INSTALL_BUNDLE 1600 1601**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager 1602 1603**模型约束:** 此接口仅可在Stage模型下使用。 1604 1605**系统接口:** 此接口为系统接口。 1606 1607**参数:** 1608 1609| 参数名 | 类型 | 必填 | 说明 | 1610| -------- | ---------------------------------------- | ---- | ------------------------------- | 1611| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是 | 企业设备管理扩展组件。 | 1612| bundleName | string | 是 | 包名。 | 1613| callback | AsyncCallback<void> | 是 | 回调函数,当接口调用成功,err为null,否则为错误对象。 | 1614 1615**错误码**: 1616 1617以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。 1618 1619| 错误码ID | 错误信息 | 1620| ------- | ---------------------------------------------------------------------------- | 1621| 9200001 | The application is not an administrator application of the device. | 1622| 9200002 | The administrator application does not have permission to manage the device. | 1623| 201 | Permission verification failed. The application does not have the permission required to call the API. | 1624| 202 | Permission verification failed. A non-system application calls a system API. | 1625| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1626 1627**示例:** 1628 1629```ts 1630import { bundleManager } from '@kit.MDMKit'; 1631import { Want } from '@kit.AbilityKit'; 1632 1633let wantTemp: Want = { 1634 // 需根据实际情况进行替换 1635 bundleName: 'com.example.myapplication', 1636 abilityName: 'EntryAbility' 1637}; 1638 1639bundleManager.uninstall(wantTemp, 'bundleName', (err) => { 1640 if (err) { 1641 console.error(`Failed to uninstall bundles. Code is ${err.code}, message is ${err.message}`); 1642 return; 1643 } 1644 console.info('Succeeded in uninstalling bundles'); 1645}); 1646``` 1647 1648## bundleManager.uninstall 1649 1650uninstall(admin: Want, bundleName: string, userId: number, callback: AsyncCallback<void>): void 1651 1652卸载指定用户下(由参数userId指定)的指定应用程序包,且不保留应用程序包数据。使用callback异步回调。 1653 1654**需要权限:** ohos.permission.ENTERPRISE_INSTALL_BUNDLE 1655 1656**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager 1657 1658**模型约束:** 此接口仅可在Stage模型下使用。 1659 1660**系统接口:** 此接口为系统接口。 1661 1662**参数:** 1663 1664| 参数名 | 类型 | 必填 | 说明 | 1665| -------- | ---------------------------------------- | ---- | ------------------------------- | 1666| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是 | 企业设备管理扩展组件。 | 1667| bundleName | string | 是 | 包名。 | 1668| userId | number | 是 | 用户ID,指定具体用户。取值范围:大于等于0。 | 1669| callback | AsyncCallback<void> | 是 | 回调函数,当接口调用成功,err为null,否则为错误对象。 | 1670 1671**错误码**: 1672 1673以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。 1674 1675| 错误码ID | 错误信息 | 1676| ------- | ---------------------------------------------------------------------------- | 1677| 9200001 | The application is not an administrator application of the device. | 1678| 9200002 | The administrator application does not have permission to manage the device. | 1679| 201 | Permission verification failed. The application does not have the permission required to call the API. | 1680| 202 | Permission verification failed. A non-system application calls a system API. | 1681| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1682 1683**示例:** 1684 1685```ts 1686import { bundleManager } from '@kit.MDMKit'; 1687import { Want } from '@kit.AbilityKit'; 1688 1689let wantTemp: Want = { 1690 // 需根据实际情况进行替换 1691 bundleName: 'com.example.myapplication', 1692 abilityName: 'EntryAbility' 1693}; 1694 1695bundleManager.uninstall(wantTemp, 'bundleName', 100, (err) => { 1696 if (err) { 1697 console.error(`Failed to uninstall bundles. Code is ${err.code}, message is ${err.message}`); 1698 return; 1699 } 1700 console.info('Succeeded in uninstalling bundles'); 1701}); 1702``` 1703 1704## bundleManager.uninstall 1705 1706uninstall(admin: Want, bundleName: string, isKeepData: boolean, callback: AsyncCallback<void>): void 1707 1708卸载当前用户下的指定应用程序包,选择是否保留应用程序包数据(由isKeepData指定)。使用callback异步回调。 1709 1710**需要权限:** ohos.permission.ENTERPRISE_INSTALL_BUNDLE 1711 1712**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager 1713 1714**模型约束:** 此接口仅可在Stage模型下使用。 1715 1716**系统接口:** 此接口为系统接口。 1717 1718**参数:** 1719 1720| 参数名 | 类型 | 必填 | 说明 | 1721| -------- | ---------------------------------------- | ---- | ------------------------------- | 1722| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是 | 企业设备管理扩展组件。 | 1723| bundleName | string | 是 | 包名。 | 1724| isKeepData | boolean | 是 | 是否保留包数据,true表示保留,false表示不保留。 | 1725| callback | AsyncCallback<void> | 是 | 回调函数,当接口调用成功,err为null,否则为错误对象。 | 1726 1727**错误码**: 1728 1729以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。 1730 1731| 错误码ID | 错误信息 | 1732| ------- | ---------------------------------------------------------------------------- | 1733| 9200001 | The application is not an administrator application of the device. | 1734| 9200002 | The administrator application does not have permission to manage the device. | 1735| 201 | Permission verification failed. The application does not have the permission required to call the API. | 1736| 202 | Permission verification failed. A non-system application calls a system API. | 1737| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1738 1739**示例:** 1740 1741```ts 1742import { bundleManager } from '@kit.MDMKit'; 1743import { Want } from '@kit.AbilityKit'; 1744 1745let wantTemp: Want = { 1746 // 需根据实际情况进行替换 1747 bundleName: 'com.example.myapplication', 1748 abilityName: 'EntryAbility' 1749}; 1750 1751bundleManager.uninstall(wantTemp, 'bundleName', true, (err) => { 1752 if (err) { 1753 console.error(`Failed to uninstall bundles. Code is ${err.code}, message is ${err.message}`); 1754 return; 1755 } 1756 console.info('Succeeded in uninstalling bundles'); 1757}); 1758``` 1759 1760## bundleManager.uninstall 1761 1762uninstall(admin: Want, bundleName: string, userId: number, isKeepData: boolean, callback: AsyncCallback<void>): void 1763 1764卸载指定用户下(由参数userId指定)的指定应用程序包接口,选择是否保留应用程序包数据(由isKeepData指定)。使用callback异步回调。 1765 1766**需要权限:** ohos.permission.ENTERPRISE_INSTALL_BUNDLE 1767 1768**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager 1769 1770**模型约束:** 此接口仅可在Stage模型下使用。 1771 1772**系统接口:** 此接口为系统接口。 1773 1774**参数:** 1775 1776| 参数名 | 类型 | 必填 | 说明 | 1777| -------- | ---------------------------------------- | ---- | ------------------------------- | 1778| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是 | 企业设备管理扩展组件。 | 1779| bundleName | string | 是 | 包名。 | 1780| userId | number | 是 | 用户ID,指定具体用户。取值范围:大于等于0。 | 1781| isKeepData | boolean | 是 | 是否保留包数据,true表示保留,false表示不保留。 | 1782| callback | AsyncCallback<void> | 是 | 回调函数,当接口调用成功,err为null,否则为错误对象。 | 1783 1784**错误码**: 1785 1786以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。 1787 1788| 错误码ID | 错误信息 | 1789| ------- | ---------------------------------------------------------------------------- | 1790| 9200001 | The application is not an administrator application of the device. | 1791| 9200002 | The administrator application does not have permission to manage the device. | 1792| 201 | Permission verification failed. The application does not have the permission required to call the API. | 1793| 202 | Permission verification failed. A non-system application calls a system API. | 1794| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1795 1796**示例:** 1797 1798```ts 1799import { bundleManager } from '@kit.MDMKit'; 1800import { Want } from '@kit.AbilityKit'; 1801 1802let wantTemp: Want = { 1803 // 需根据实际情况进行替换 1804 bundleName: 'com.example.myapplication', 1805 abilityName: 'EntryAbility' 1806}; 1807 1808bundleManager.uninstall(wantTemp, 'bundleName', 100, true, (err) => { 1809 if (err) { 1810 console.error(`Failed to uninstall bundles. Code is ${err.code}, message is ${err.message}`); 1811 return; 1812 } 1813 console.info('Succeeded in uninstalling bundles'); 1814}); 1815``` 1816 1817## bundleManager.install 1818 1819install(admin: Want, hapFilePaths: Array\<string>, callback: AsyncCallback\<void>): void 1820 1821安装指定路径下的应用包。使用callback异步回调。 1822 1823**需要权限:** ohos.permission.ENTERPRISE_INSTALL_BUNDLE 1824 1825**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager 1826 1827**模型约束:** 此接口仅可在Stage模型下使用。 1828 1829**系统接口:** 此接口为系统接口。 1830 1831**参数:** 1832 1833| 参数名 | 类型 | 必填 | 说明 | 1834| -------- | ---------------------------------------- | ---- | ------------------------------- | 1835| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是 | 企业设备管理扩展组件。 | 1836| hapFilePaths | Array\<string> | 是 | 待安装应用包路径数组。 | 1837| callback | AsyncCallback<void> | 是 | 回调函数,当接口调用成功,err为null,否则为错误对象。 | 1838 1839**错误码**: 1840 1841以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。 1842 1843| 错误码ID | 错误信息 | 1844| ------- | ---------------------------------------------------------------------------- | 1845| 9200001 | The application is not an administrator application of the device. | 1846| 9200002 | The administrator application does not have permission to manage the device. | 1847| 9201002 | Failed to install the application. | 1848| 201 | Permission verification failed. The application does not have the permission required to call the API. | 1849| 202 | Permission verification failed. A non-system application calls a system API. | 1850| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1851 1852**示例:** 1853 1854```ts 1855import { bundleManager } from '@kit.MDMKit'; 1856import { Want } from '@kit.AbilityKit'; 1857 1858let wantTemp: Want = { 1859 // 需根据实际情况进行替换 1860 bundleName: 'com.example.myapplication', 1861 abilityName: 'EntryAbility' 1862}; 1863// 需根据实际情况进行替换 1864let hapFilePaths: Array<string> = ['/data/storage/el2/base/haps/entry/testinstall/ExtensionTest.hap']; 1865 1866bundleManager.install(wantTemp, hapFilePaths, (err) => { 1867 if (err) { 1868 console.error(`Failed to install bundles. Code is ${err.code}, message is ${err.message}`); 1869 return; 1870 } 1871 console.info('Succeeded in installing bundles'); 1872}); 1873``` 1874 1875## bundleManager.install 1876 1877install(admin: Want, hapFilePaths: Array\<string>, installParam: InstallParam, callback: AsyncCallback\<void>): void 1878 1879安装指定路径下的指定安装参数的应用包。使用callback异步回调。 1880 1881**需要权限:** ohos.permission.ENTERPRISE_INSTALL_BUNDLE 1882 1883**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager 1884 1885**模型约束:** 此接口仅可在Stage模型下使用。 1886 1887**系统接口:** 此接口为系统接口。 1888 1889**参数:** 1890 1891| 参数名 | 类型 | 必填 | 说明 | 1892| -------- | ---------------------------------------- | ---- | ------------------------------- | 1893| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是 | 企业设备管理扩展组件。 | 1894| hapFilePaths | Array\<string> | 是 | 待安装应用包路径数组。 | 1895| installParam | [InstallParam](js-apis-enterprise-bundleManager.md#installparam) | 是 | 应用包安装参数。 | 1896| callback | AsyncCallback<void> | 是 | 回调函数,当接口调用成功,err为null,否则为错误对象。 | 1897 1898**错误码**: 1899 1900以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。 1901 1902| 错误码ID | 错误信息 | 1903| ------- | ---------------------------------------------------------------------------- | 1904| 9200001 | The application is not an administrator application of the device. | 1905| 9200002 | The administrator application does not have permission to manage the device. | 1906| 9201002 | Failed to install the application. | 1907| 201 | Permission verification failed. The application does not have the permission required to call the API. | 1908| 202 | Permission verification failed. A non-system application calls a system API. | 1909| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1910 1911**示例:** 1912 1913```ts 1914import { bundleManager } from '@kit.MDMKit'; 1915import { Want } from '@kit.AbilityKit'; 1916 1917let wantTemp: Want = { 1918 // 需根据实际情况进行替换 1919 bundleName: 'com.example.myapplication', 1920 abilityName: 'EntryAbility' 1921}; 1922// 需根据实际情况进行替换 1923let hapFilePaths: Array<string> = ['/data/storage/el2/base/haps/entry/testinstall/ExtensionTest.hap']; 1924let installParam: bundleManager.InstallParam = { 1925 userId: 100, 1926 installFlag: 1, 1927}; 1928 1929bundleManager.install(wantTemp, hapFilePaths, installParam, (err) => { 1930 if (err) { 1931 console.error(`Failed to install bundles. Code is ${err.code}, message is ${err.message}`); 1932 return; 1933 } 1934 console.info('Succeeded in installing bundles'); 1935}); 1936``` 1937