1# @ohos.enterprise.applicationManager(应用管理) 2 3本模块提供应用管理能力,包括添加应用运行黑名单、获取应用运行黑名单、移除应用运行黑名单等。 4 5> **说明:** 6> 7> 本模块首批接口从API version 12开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 8> 9> 本模块接口仅可在Stage模型下使用。 10> 11> 本模块接口仅对[设备管理应用](../../mdm/mdm-kit-guide.md#功能介绍)开放,需将设备管理应用激活后调用,实现相应功能。 12> 13 14## 导入模块 15 16```ts 17import { applicationManager } from '@kit.MDMKit'; 18``` 19 20## applicationManager.addDisallowedRunningBundlesSync 21 22addDisallowedRunningBundlesSync(admin: Want, appIds: Array\<string>, accountId?: number): void 23 24指定设备管理应用添加应用至应用运行黑名单,添加至黑名单的应用不允许在当前/指定用户下运行。 25 26**需要权限:** ohos.permission.ENTERPRISE_MANAGE_APPLICATION 27 28**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager 29 30 31 32**参数:** 33 34| 参数名 | 类型 | 必填 | 说明 | 35| --------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ | 36| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是 | 设备管理应用。 | 37| appIds | Array<string> | 是 | 应用ID数组,指定具体应用。 | 38| accountId | number | 否 | 用户ID,取值范围:大于等于0。<br> - 调用接口时,若传入accountId,表示指定用户。<br> - 调用接口时,若未传入accountId,表示当前用户。 | 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| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 50 51**示例:** 52 53```ts 54import { Want } from '@kit.AbilityKit'; 55let wantTemp: Want = { 56 bundleName: 'com.example.myapplication', 57 abilityName: 'EntryAbility', 58}; 59let appIds: Array<string> = ['com.example.******_******/******5t5CoBM=']; 60 61try { 62 applicationManager.addDisallowedRunningBundlesSync(wantTemp, appIds); 63 console.info('Succeeded in adding disallowed running bundles.'); 64} catch (err) { 65 console.error(`Failed to add disallowed running bundles. Code is ${err.code}, message is ${err.message}`); 66} 67``` 68 69## applicationManager.removeDisallowedRunningBundlesSync 70 71removeDisallowedRunningBundlesSync(admin: Want, appIds: Array\<string>, accountId?: number): void 72 73指定当前/指定用户下的设备管理应用在应用运行黑名单中移除应用。 74 75**需要权限:** ohos.permission.ENTERPRISE_MANAGE_APPLICATION 76 77**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager 78 79 80 81**参数:** 82 83| 参数名 | 类型 | 必填 | 说明 | 84| --------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ | 85| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是 | 设备管理应用。 | 86| appIds | Array<string> | 是 | 应用ID数组,指定具体应用。 | 87| accountId | number | 否 | 用户ID,取值范围:大于等于0。<br> - 调用接口时,若传入accountId,表示指定用户。<br> - 调用接口时,若未传入accountId,表示当前用户。 | 88 89**错误码**: 90 91以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。 92 93| 错误码ID | 错误信息 | 94| -------- | ------------------------------------------------------------ | 95| 9200001 | The application is not an administrator application of the device. | 96| 9200002 | The administrator application does not have permission to manage the device. | 97| 201 | Permission verification failed. The application does not have the permission required to call the API. | 98| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 99 100**示例:** 101 102```ts 103import { Want } from '@kit.AbilityKit'; 104let wantTemp: Want = { 105 bundleName: 'com.example.myapplication', 106 abilityName: 'EntryAbility', 107}; 108let appIds: Array<string> = ['com.example.******_******/******5t5CoBM=']; 109 110try { 111 applicationManager.removeDisallowedRunningBundlesSync(wantTemp, appIds); 112 console.info('Succeeded in removing disallowed running bundles.'); 113} catch (err) { 114 console.error(`Failed to remove disallowed running bundles. Code is ${err.code}, message is ${err.message}`); 115} 116``` 117 118## applicationManager.getDisallowedRunningBundlesSync 119 120getDisallowedRunningBundlesSync(admin: Want, accountId?: number): Array<string> 121 122指定设备管理应用获取当前用户下的应用运行黑名单。 123 124**需要权限:** ohos.permission.ENTERPRISE_MANAGE_APPLICATION 125 126**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager 127 128 129 130**参数:** 131 132| 参数名 | 类型 | 必填 | 说明 | 133| --------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ | 134| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是 | 设备管理应用。 | 135| accountId | number | 否 | 用户ID,取值范围:大于等于0。<br/> - 调用接口时,若传入accountId,表示指定用户。<br/> - 调用接口时,若未传入accountId,表示当前用户。 | 136 137**返回值:** 138 139| 类型 | 说明 | 140| ------------------- | -------------------------------- | 141| Array<string> | 返回当前用户下的应用运行黑名单。 | 142 143**错误码**: 144 145以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。 146 147| 错误码ID | 错误信息 | 148| -------- | ------------------------------------------------------------ | 149| 9200001 | The application is not an administrator application of the device. | 150| 9200002 | The administrator application does not have permission to manage the device. | 151| 201 | Permission verification failed. The application does not have the permission required to call the API. | 152| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 153 154**示例:** 155 156```ts 157import { Want } from '@kit.AbilityKit'; 158let wantTemp: Want = { 159 bundleName: 'com.example.myapplication', 160 abilityName: 'EntryAbility', 161}; 162 163try { 164 let result: Array<string> = applicationManager.getDisallowedRunningBundlesSync(wantTemp) 165 console.info(`Succeeded in getting disallowed running bundles, result : ${JSON.stringify(result)}`); 166} catch (err) { 167 console.error(`Failed to get disallowed running bundles. Code is ${err.code}, message is ${err.message}`); 168} 169``` 170 171## applicationManager.addAutoStartApps 172 173addAutoStartApps(admin: Want, autoStartApps: Array\<Want>): void 174 175以同步方法指定设备管理应用添加开机自启动应用名单。该能力当前仅支持2in1设备。 176 177**需要权限:** ohos.permission.ENTERPRISE_MANAGE_APPLICATION 178 179**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager 180 181**参数:** 182 183| 参数名 | 类型 | 必填 | 说明 | 184| ------------- | ------------------------------------------------------------ | ---- | -------------------------------------- | 185| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是 | 设备管理应用。 | 186| autoStartApps | Array\<[Want](../apis-ability-kit/js-apis-app-ability-want.md)> | 是 | 开机自启动应用。数组长度上限长度为10。 | 187 188**错误码**: 189 190以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。 191 192| 错误码ID | 错误信息 | 193| -------- | ------------------------------------------------------------ | 194| 9200001 | The application is not an administrator application of the device. | 195| 9200002 | The administrator application does not have permission to manage the device. | 196| 201 | Permission verification failed. The application does not have the permission required to call the API. | 197| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 198 199**示例:** 200 201```ts 202import { Want } from '@kit.AbilityKit'; 203 204let wantTemp: Want = { 205 bundleName: 'com.example.myapplication', 206 abilityName: 'EntryAbility', 207}; 208let autoStartApps: Array<Want> = [ 209 { 210 bundleName: 'com.example.autoStartApplication', 211 abilityName: 'EntryAbility', 212 } 213]; 214 215try { 216 applicationManager.addAutoStartApps(wantTemp, autoStartApps); 217 console.info(`Succeeded in adding auto start applications.`); 218} catch(err) { 219 console.error(`Failed to add auto start applications. Code: ${err.code}, message: ${err.message}`); 220} 221``` 222 223## applicationManager.removeAutoStartApps 224 225removeAutoStartApps(admin: Want, autoStartApps: Array\<Want>): void 226 227以同步方法指定设备管理应用删除开机自启动应用名单。该能力当前仅支持2in1设备。 228 229**需要权限:** ohos.permission.ENTERPRISE_MANAGE_APPLICATION 230 231**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager 232 233**参数:** 234 235| 参数名 | 类型 | 必填 | 说明 | 236| ------------- | ------------------------------------------------------------ | ---- | ---------------- | 237| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是 | 设备管理应用。 | 238| autoStartApps | Array\<[Want](../apis-ability-kit/js-apis-app-ability-want.md)> | 是 | 开机自启动应用。 | 239 240**错误码**: 241 242以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。 243 244| 错误码ID | 错误信息 | 245| -------- | ------------------------------------------------------------ | 246| 9200001 | The application is not an administrator application of the device. | 247| 9200002 | The administrator application does not have permission to manage the device. | 248| 201 | Permission verification failed. The application does not have the permission required to call the API. | 249| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 250 251**示例:** 252 253```ts 254import { Want } from '@kit.AbilityKit'; 255 256let wantTemp: Want = { 257 bundleName: 'com.example.myapplication', 258 abilityName: 'EntryAbility', 259}; 260let autoStartApps: Array<Want> = [ 261 { 262 bundleName: 'com.example.autoStartApplication', 263 abilityName: 'EntryAbility', 264 } 265]; 266 267try { 268 applicationManager.removeAutoStartApps(wantTemp, autoStartApps); 269 console.info(`Succeeded in removing auto start applications.`); 270} catch(err) { 271 console.error(`Failed to remove auto start applications. Code: ${err.code}, message: ${err.message}`); 272} 273``` 274 275## applicationManager.getAutoStartApps 276 277getAutoStartApps(admin: Want): Array\<Want> 278 279以同步方法指定设备管理应用查询开机自启动应用名单。该能力当前仅支持2in1设备。 280 281**需要权限:** ohos.permission.ENTERPRISE_MANAGE_APPLICATION 282 283**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager 284 285**参数:** 286 287| 参数名 | 类型 | 必填 | 说明 | 288| ------ | ------------------------------------------------------- | ---- | -------------- | 289| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是 | 设备管理应用。 | 290 291**返回值:** 292 293| 类型 | 说明 | 294| ------------------------------------------------------------ | -------------------- | 295| Array\<[Want](../apis-ability-kit/js-apis-app-ability-want.md)> | 应用自启动名单数组。 | 296 297**错误码**: 298 299以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。 300 301| 错误码ID | 错误信息 | 302| -------- | ------------------------------------------------------------ | 303| 9200001 | The application is not an administrator application of the device. | 304| 9200002 | The administrator application does not have permission to manage the device. | 305| 201 | Permission verification failed. The application does not have the permission required to call the API. | 306| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 307 308**示例:** 309 310```ts 311import { Want } from '@kit.AbilityKit'; 312 313let wantTemp: Want = { 314 bundleName: 'com.example.myapplication', 315 abilityName: 'EntryAbility', 316}; 317 318try { 319 let res: Array<Want> = applicationManager.getAutoStartApps(wantTemp); 320 console.info(`Succeeded in adding auto start apps: ${JSON.stringify(res)}`); 321} catch(err) { 322 console.error(`Failed to auto start apps. Code: ${err.code}, message: ${err.message}`); 323} 324``` 325 326## applicationManager.addKeepAliveApps<sup>14+</sup> 327 328addKeepAliveApps(admin: Want, bundleNames: Array\<string>, accountId: number): void 329 330指定设备管理应用添加保活应用,当前仅支持2in1设备。 331 332**需要权限:** ohos.permission.ENTERPRISE_MANAGE_APPLICATION 333 334**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager 335 336 337 338**参数:** 339 340| 参数名 | 类型 | 必填 | 说明 | 341| --------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ | 342| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是 | 设备管理应用。 | 343| bundleNames | Array<string> | 是 | 应用包名数组,指定需要添加保活的应用,最大支持5个。 | 344| accountId | number | 是 | 用户ID,指定具体用户,取值范围:大于等于0。| 345 346**错误码**: 347 348以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。 349 350| 错误码ID | 错误信息 | 351| -------- | ------------------------------------------------------------ | 352| 9200001 | The application is not an administrator application of the device. | 353| 9200002 | The administrator application does not have permission to manage the device. | 354| 9200010 | A conflict policy has been configured. | 355| 9201005 | Add keep alive applications failed. | 356| 201 | Permission verification failed. The application does not have the permission required to call the 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 { Want } from '@kit.AbilityKit'; 363let wantTemp: Want = { 364 bundleName: 'com.example.myapplication', 365 abilityName: 'EntryAbility', 366}; 367let bundleNames: Array<string> = ['com.example.myapplication']; 368 369try { 370 applicationManager.addKeepAliveApps(wantTemp, bundleNames, 100); 371 console.info('Succeeded in adding keep alive apps.'); 372} catch (err) { 373 console.error(`Failed to add keep alive apps. Code is ${err.code}, message is ${err.message}`); 374} 375``` 376 377## applicationManager.removeKeepAliveApps<sup>14+</sup> 378 379removeKeepAliveApps(admin: Want, bundleNames: Array\<string>, accountId: number): void 380 381指定设备管理应用移除保活应用,当前仅支持2in1设备。 382 383**需要权限:** ohos.permission.ENTERPRISE_MANAGE_APPLICATION 384 385**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager 386 387 388 389**参数:** 390 391| 参数名 | 类型 | 必填 | 说明 | 392| --------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ | 393| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是 | 设备管理应用。 | 394| bundleNames | Array<string> | 是 | 应用包名数组,指定需要移除保活的应用,最大支持5个。 | 395| accountId | number | 是 | 用户ID,指定具体用户,取值范围:大于等于0。 | 396 397**错误码**: 398 399以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。 400 401| 错误码ID | 错误信息 | 402| -------- | ------------------------------------------------------------ | 403| 9200001 | The application is not an administrator application of the device. | 404| 9200002 | The administrator application does not have permission to manage the device. | 405| 201 | Permission verification failed. The application does not have the permission required to call the API. | 406| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 407 408**示例:** 409 410```ts 411import { Want } from '@kit.AbilityKit'; 412let wantTemp: Want = { 413 bundleName: 'com.example.myapplication', 414 abilityName: 'EntryAbility', 415}; 416let bundleNames: Array<string> = ['com.example.myapplication']; 417 418try { 419 applicationManager.removeKeepAliveApps(wantTemp, bundleNames, 100); 420 console.info('Succeeded in removing keep alive apps.'); 421} catch (err) { 422 console.error(`Failed to remove keep alive apps. Code is ${err.code}, message is ${err.message}`); 423} 424``` 425 426## applicationManager.getKeepAliveApps<sup>14+</sup> 427 428getKeepAliveApps(admin: Want, accountId: number): Array<string> 429 430指定设备管理应用获取保活应用包名,当前仅支持2in1设备。 431 432**需要权限:** ohos.permission.ENTERPRISE_MANAGE_APPLICATION 433 434**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager 435 436 437 438**参数:** 439 440| 参数名 | 类型 | 必填 | 说明 | 441| --------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ | 442| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是 | 设备管理应用。 | 443| accountId | number | 是 | 用户ID,指定具体用户,取值范围:大于等于0。 | 444 445**返回值:** 446 447| 类型 | 说明 | 448| ------------------- | -------------------------------- | 449| Array<string> | 返回指定用户下保活应用的包名。 | 450 451**错误码**: 452 453以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。 454 455| 错误码ID | 错误信息 | 456| -------- | ------------------------------------------------------------ | 457| 9200001 | The application is not an administrator application of the device. | 458| 9200002 | The administrator application does not have permission to manage the device. | 459| 201 | Permission verification failed. The application does not have the permission required to call the API. | 460| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 461 462**示例:** 463 464```ts 465import { Want } from '@kit.AbilityKit'; 466let wantTemp: Want = { 467 bundleName: 'com.example.myapplication', 468 abilityName: 'EntryAbility', 469}; 470 471try { 472 let result: Array<string> = applicationManager.getKeepAliveApps(wantTemp, 100); 473 console.info('Succeeded in getting keep alive apps.'); 474} catch (err) { 475 console.error(`Failed to get keep alive apps. Code is ${err.code}, message is ${err.message}`); 476} 477```