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