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