1# AbilityDelegator 2 3> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明** 4> 5> 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 6> 7> API 9当前为Canary版本,仅供试用,不保证接口可稳定调用。 8 9## 导入模块 10 11```js 12import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry' 13``` 14 15 16 17## AbilityDelegator 18 19### addAbilityMonitor<sup>9+</sup> 20 21addAbilityMonitor(monitor: AbilityMonitor, callback: AsyncCallback\<void>): void 22 23添加AbilityMonitor实例(callback形式) 24 25**系统能力:**SystemCapability.Ability.AbilityRuntime.Core 26 27**参数:** 28 29| 参数名 | 类型 | 必填说明 | 说明 | 30| -------- | ------------------------------------------------------------ | -------- | ------------------------------------------------------------ | 31| monitor | [AbilityMonitor](js-apis-application-abilityMonitor.md#AbilityMonitor) | 是 | [AbilityMonitor](js-apis-application-abilityMonitor.md#AbilityMonitor)实例 | 32| callback | AsyncCallback\<void> | 是 | 表示指定的回调方法 | 33 34**示例:** 35 36```js 37var abilityDelegator; 38 39function onAbilityCreateCallback(data) { 40 console.info("onAbilityCreateCallback"); 41} 42 43var monitor = { 44 abilityName: "abilityname", 45 onAbilityCreate: onAbilityCreateCallback 46} 47 48abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator(); 49abilityDelegator.addAbilityMonitor(monitor, (err : any) => { 50 console.info("addAbilityMonitor callback"); 51}); 52``` 53 54### addAbilityMonitor<sup>9+</sup> 55 56addAbilityMonitor(monitor: AbilityMonitor): Promise\<void> 57 58添加AbilityMonitor实例(promise形式) 59 60**系统能力:** SystemCapability.Ability.AbilityRuntime.Core 61 62**参数:** 63 64| 参数名 | 类型 | 必填 | 说明 | 65| ------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 66| monitor | [AbilityMonitor](js-apis-application-abilityMonitor.md#AbilityMonitor) | 是 | [AbilityMonitor](js-apis-application-abilityMonitor.md#AbilityMonitor)实例 | 67 68**返回值:** 69 70| 类型 | 说明 | 71| -------------- | ------------------- | 72| Promise\<void> | 以Promise形式返回。 | 73 74**示例:** 75 76```js 77var abilityDelegator; 78 79function onAbilityCreateCallback(data) { 80 console.info("onAbilityCreateCallback"); 81} 82 83var monitor = { 84 abilityName: "abilityname", 85 onAbilityCreate: onAbilityCreateCallback 86} 87 88abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator(); 89abilityDelegator.addAbilityMonitor(monitor).then(() => { 90 console.info("addAbilityMonitor promise"); 91}); 92``` 93 94### removeAbilityMonitor<sup>9+</sup> 95 96removeAbilityMonitor(monitor: AbilityMonitor, callback: AsyncCallback\<void>): void 97 98删除已经添加的AbilityMonitor实例(callback形式) 99 100**系统能力:** SystemCapability.Ability.AbilityRuntime.Core 101 102**参数:** 103 104| 参数名 | 类型 | 必填 | 说明 | 105| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 106| monitor | [AbilityMonitor](js-apis-application-abilityMonitor.md#AbilityMonitor) | 是 | [AbilityMonitor](js-apis-application-abilityMonitor.md#AbilityMonitor)实例 | 107| callback | AsyncCallback\<void> | 是 | 表示指定的回调方法 | 108 109**示例:** 110 111```js 112var abilityDelegator; 113 114function onAbilityCreateCallback(data) { 115 console.info("onAbilityCreateCallback"); 116} 117 118var monitor = { 119 abilityName: "abilityname", 120 onAbilityCreate: onAbilityCreateCallback 121} 122 123abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator(); 124abilityDelegator.removeAbilityMonitor(monitor, (err : any) => { 125 console.info("removeAbilityMonitor callback"); 126}); 127``` 128 129### removeAbilityMonitor<sup>9+</sup> 130 131removeAbilityMonitor(monitor: AbilityMonitor): Promise\<void> 132 133删除已经添加的AbilityMonitor实例(promise形式) 134 135**系统能力:** SystemCapability.Ability.AbilityRuntime.Core 136 137**参数:** 138 139| 名称 | 类型 | 必填 | 说明 | 140| ------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 141| monitor | [AbilityMonitor](js-apis-application-abilityMonitor.md#AbilityMonitor) | 是 | [AbilityMonitor](js-apis-application-abilityMonitor.md#AbilityMonitor)实例 | 142 143**返回值:** 144 145| 类型 | 说明 | 146| -------------- | ------------------- | 147| Promise\<void> | 以Promise形式返回。 | 148 149- 示例 150 151```js 152var abilityDelegator; 153 154function onAbilityCreateCallback(data) { 155 console.info("onAbilityCreateCallback"); 156} 157 158var monitor = { 159 abilityName: "abilityname", 160 onAbilityCreate: onAbilityCreateCallback 161} 162 163abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator(); 164abilityDelegator.removeAbilityMonitor(monitor).then(() => { 165 console.info("removeAbilityMonitor promise"); 166}); 167``` 168 169### waitAbilityMonitor<sup>9+</sup> 170 171waitAbilityMonitor(monitor: AbilityMonitor, callback: AsyncCallback\<Ability>): void 172 173等待与AbilityMonitor实例匹配的ability到达OnCreate生命周期,并返回ability实例(callback形式) 174 175**系统能力:** SystemCapability.Ability.AbilityRuntime.Core 176 177**参数:** 178 179| 参数名 | 类型 | 必填 | 说明 | 180| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 181| monitor | [AbilityMonitor](js-apis-application-abilityMonitor.md#AbilityMonitor) | 是 | [AbilityMonitor](js-apis-application-abilityMonitor.md#AbilityMonitor)实例 | 182| callback | AsyncCallback\<[Ability](js-apis-application-ability.md#Ability)> | 是 | 表示指定的回调方法 | 183 184**示例:** 185 186```js 187var abilityDelegator; 188 189function onAbilityCreateCallback(data) { 190 console.info("onAbilityCreateCallback"); 191} 192 193var monitor = { 194 abilityName: "abilityname", 195 onAbilityCreate: onAbilityCreateCallback 196} 197 198abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator(); 199abilityDelegator.waitAbilityMonitor(monitor, (err : any, data : any) => { 200 console.info("waitAbilityMonitor callback"); 201}); 202``` 203 204### waitAbilityMonitor<sup>9+</sup> 205 206waitAbilityMonitor(monitor: AbilityMonitor, timeout: number, callback: AsyncCallback\<Ability>): void 207 208设置等待时间,等待与AbilityMonitor实例匹配的ability到达OnCreate生命周期,并返回ability实例(callback形式) 209 210**系统能力:** SystemCapability.Ability.AbilityRuntime.Core 211 212**参数:** 213 214| 参数名 | 类型 | 必填 | 说明 | 215| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 216| monitor | [AbilityMonitor](js-apis-application-abilityMonitor.md#AbilityMonitor) | 是 | [AbilityMonitor](js-apis-application-abilityMonitor.md#AbilityMonitor)实例 | 217| timeout | number | 是 | 最大等待时间,单位毫秒(ms) | 218| callback | AsyncCallback\<[Ability](js-apis-application-ability.md#Ability)> | 是 | 表示指定的回调方法 | 219 220**示例:** 221 222```js 223var abilityDelegator; 224var timeout = 100; 225 226function onAbilityCreateCallback(data) { 227 console.info("onAbilityCreateCallback"); 228} 229 230var monitor = { 231 abilityName: "abilityname", 232 onAbilityCreate: onAbilityCreateCallback 233} 234 235abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator(); 236abilityDelegator.waitAbilityMonitor(monitor, timeout, (err : any, data : any) => { 237 console.info("waitAbilityMonitor callback"); 238}); 239``` 240 241### waitAbilityMonitor<sup>9+</sup> 242 243waitAbilityMonitor(monitor: AbilityMonitor, timeout?: number): Promise\<Ability> 244 245设置等待时间,等待与AbilityMonitor实例匹配的ability到达OnCreate生命周期,并返回ability实例(promise形式) 246 247**系统能力:** SystemCapability.Ability.AbilityRuntime.Core 248 249**参数:** 250 251| 参数名 | 类型 | 必填 | 说明 | 252| ------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 253| monitor | [AbilityMonitor](js-apis-application-abilityMonitor.md#AbilityMonitor) | 是 | [AbilityMonitor](js-apis-application-abilityMonitor.md#AbilityMonitor)实例 | 254| timeout | number | 否 | 最大等待时间,单位毫秒(ms) | 255 256**返回值:** 257 258| 类型 | 说明 | 259| ----------------------------------------------------------- | -------------------------- | 260| Promise\<[Ability](js-apis-application-ability.md#Ability)> | 以Promise形式返回Ability。 | 261 262**示例:** 263 264```js 265var abilityDelegator; 266 267function onAbilityCreateCallback(data) { 268 console.info("onAbilityCreateCallback"); 269} 270 271var monitor = { 272 abilityName: "abilityname", 273 onAbilityCreate: onAbilityCreateCallback 274} 275 276abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator(); 277abilityDelegator.waitAbilityMonitor(monitor).then((data : any) => { 278 console.info("waitAbilityMonitor promise"); 279}); 280``` 281 282### getAppContext<sup>9+</sup> 283 284getAppContext(): Context 285 286获取应用Context 287 288**系统能力:** SystemCapability.Ability.AbilityRuntime.Core 289 290**返回值:** 291 292| 类型 | 说明 | 293| ------------------------------------- | ------------------------------------------- | 294| [Context](js-apis-Context.md#Context) | 应用[Context](js-apis-Context.md#Context)。 | 295 296**示例:** 297 298```js 299var abilityDelegator; 300 301abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator(); 302var context = abilityDelegator.getAppContext(); 303``` 304 305### getAbilityState<sup>9+</sup> 306 307getAbilityState(ability: Ability): number 308 309获取指定ability的生命周期状态 310 311**系统能力:** SystemCapability.Ability.AbilityRuntime.Core 312 313**参数:** 314 315| 参数名 | 类型 | 必填 | 说明 | 316| ------- | ------------------------------------------------- | ---- | --------------- | 317| ability | [Ability](js-apis-application-ability.md#Ability) | 是 | 指定Ability对象 | 318 319**返回值:** 320 321| 类型 | 说明 | 322| ------ | ------------------------------------------------------------ | 323| number | 指定ability的生命周期状态。状态枚举值使用[AbilityLifecycleState](js-apis-abilityDelegatorRegistry.md#AbilityLifecycleState)。 | 324 325**示例:** 326 327```js 328var abilityDelegator; 329var ability; 330 331abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator(); 332abilityDelegator.getCurrentTopAbility((err : any, data : any) => { 333 console.info("getCurrentTopAbility callback"); 334 ability = data; 335 var state = abilityDelegator.getAbilityState(ability); 336 console.info("getAbilityState" + state); 337}); 338``` 339 340### getCurrentTopAbility<sup>9+</sup> 341 342getCurrentTopAbility(callback: AsyncCallback\<Ability>): void 343 344获取当前应用顶部ability(callback形式) 345 346**系统能力:** SystemCapability.Ability.AbilityRuntime.Core 347 348**参数:** 349 350| 参数名 | 类型 | 必填 | 说明 | 351| -------- | ------------------------------------------------------------ | ---- | ------------------ | 352| callback | AsyncCallback\<[Ability](js-apis-application-ability.md#Ability)> | 是 | 表示指定的回调方法 | 353 354**示例:** 355 356```js 357var abilityDelegator; 358var ability; 359 360abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator(); 361abilityDelegator.getCurrentTopAbility((err : any, data : any) => { 362 console.info("getCurrentTopAbility callback"); 363 ability = data; 364}); 365``` 366 367### getCurrentTopAbility<sup>9+</sup> 368 369getCurrentTopAbility(): Promise\<Ability> 370 371获取当前应用顶部ability(promise形式) 372 373**系统能力:** SystemCapability.Ability.AbilityRuntime.Core 374 375**返回值:** 376 377| 类型 | 说明 | 378| ----------------------------------------------------------- | -------------------------------------- | 379| Promise\<[Ability](js-apis-application-ability.md#Ability)> | 以Promise形式返回当前应用顶部ability。 | 380 381**示例:** 382 383```js 384var abilityDelegator; 385var ability; 386 387abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator(); 388abilityDelegator.getCurrentTopAbility().then((data : any) => { 389 console.info("getCurrentTopAbility promise"); 390 ability = data; 391}); 392``` 393 394### doAbilityForeground<sup>9+</sup> 395 396doAbilityForeground(ability: Ability, callback: AsyncCallback\<boolean>): void 397 398调度指定ability生命周期状态到Foreground状态(callback形式) 399 400**系统能力:** SystemCapability.Ability.AbilityRuntime.Core 401 402**参数:** 403 404| 参数名 | 类型 | 必填 | 说明 | 405| -------- | ----------------------- | ---- | ------------------------------------------------------- | 406| ability | Ability | 是 | 指定Ability对象 | 407| callback | AsyncCallback\<boolean> | 是 | 表示指定的回调方法<br/>\- true:成功<br/>\- false:失败 | 408 409**示例:** 410 411```js 412var abilityDelegator; 413var ability; 414 415abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator(); 416abilityDelegator.getCurrentTopAbility((err : any, data : any) => { 417 console.info("getCurrentTopAbility callback"); 418 ability = data; 419 abilityDelegator.doAbilityForeground(ability, (err : any, data : any) => { 420 console.info("doAbilityForeground callback"); 421 }); 422}); 423``` 424 425### doAbilityForeground<sup>9+</sup> 426 427doAbilityForeground(ability: Ability): Promise\<boolean> 428 429调度指定ability生命周期状态到Foreground状态(promise形式) 430 431**系统能力:** SystemCapability.Ability.AbilityRuntime.Core 432 433**参数:** 434 435| 参数名 | 类型 | 必填 | 说明 | 436| ------- | ------- | ---- | --------------- | 437| ability | Ability | 是 | 指定Ability对象 | 438 439**返回值:** 440 441| 类型 | 说明 | 442| ----------------- | ------------------------------------------------------------ | 443| Promise\<boolean> | 以Promise形式返回执行结果。<br/>\- true:成功<br/>\- false:失败 | 444 445**示例:** 446 447```js 448var abilityDelegator; 449var ability; 450 451abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator(); 452abilityDelegator.getCurrentTopAbility((err : any, data : any) => { 453 console.info("getCurrentTopAbility callback"); 454 ability = data; 455 abilityDelegator.doAbilityForeground(ability).then((data : any) => { 456 console.info("doAbilityForeground promise"); 457 }); 458}); 459``` 460 461### doAbilityBackground<sup>9+</sup> 462 463doAbilityBackground(ability: Ability, callback: AsyncCallback\<boolean>): void 464 465调度指定ability生命周期状态到Background状态(callback形式) 466 467**系统能力:** SystemCapability.Ability.AbilityRuntime.Core 468 469**参数:** 470 471| 参数名 | 类型 | 必填 | 说明 | 472| -------- | ----------------------- | ---- | ------------------------------------------------------- | 473| ability | Ability | 是 | 指定Ability对象 | 474| callback | AsyncCallback\<boolean> | 是 | 表示指定的回调方法<br/>\- true:成功<br/>\- false:失败 | 475 476**示例:** 477 478```js 479var abilityDelegator; 480var ability; 481 482abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator(); 483abilityDelegator.getCurrentTopAbility((err : any, data : any) => { 484 console.info("getCurrentTopAbility callback"); 485 ability = data; 486 abilityDelegator.doAbilityBackground(ability, (err : any, data : any) => { 487 console.info("doAbilityBackground callback"); 488 }); 489}); 490``` 491 492### doAbilityBackground<sup>9+</sup> 493 494doAbilityBackground(ability: Ability): Promise\<boolean> 495 496调度指定ability生命周期状态到Background状态(promise形式) 497 498**系统能力:** SystemCapability.Ability.AbilityRuntime.Core 499 500**参数:** 501 502| 参数名 | 类型 | 必填 | 说明 | 503| ------- | ------- | ---- | --------------- | 504| ability | Ability | 是 | 指定Ability对象 | 505 506**返回值:** 507 508| 类型 | 说明 | 509| ----------------- | ------------------------------------------------------------ | 510| Promise\<boolean> | 以Promise形式返回执行结果。<br/>\- true:成功<br/>\- false:失败 | 511 512**示例:** 513 514```js 515var abilityDelegator; 516var ability; 517 518abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator(); 519abilityDelegator.getCurrentTopAbility((err : any, data : any) => { 520 console.info("getCurrentTopAbility callback"); 521 ability = data; 522 abilityDelegator.doAbilityBackground(ability).then((data : any) => { 523 console.info("doAbilityBackground promise"); 524 }); 525}); 526``` 527 528### startAbility<sup>9+</sup> 529 530startAbility(want: Want, callback: AsyncCallback\<void>): void 531 532启动指定ability(callback形式) 533 534**系统能力:** SystemCapability.Ability.AbilityRuntime.Core 535 536**参数:** 537 538| 参数名 | 类型 | 必填 | 说明 | 539| -------- | -------------------------------------- | ---- | ------------------ | 540| want | [Want](js-apis-featureAbility.md#Want) | 是 | 启动Ability参数 | 541| callback | AsyncCallback\<void> | 是 | 表示指定的回调方法 | 542 543**示例:** 544 545```js 546var abilityDelegator; 547var want = { 548 bundleName: "bundleName", 549 abilityName: "abilityName" 550}; 551 552abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator(); 553abilityDelegator.startAbility(want, (err, data) => { 554 console.info("startAbility callback"); 555}); 556``` 557 558 559 560### startAbility<sup>9+</sup> 561 562startAbility(want: Want): Promise\<void> 563 564启动指定ability(promise形式) 565 566**系统能力:** SystemCapability.Ability.AbilityRuntime.Core 567 568**参数:** 569 570| 参数名 | 类型 | 必填 | 说明 | 571| ------ | -------------------------------------- | ---- | --------------- | 572| want | [Want](js-apis-featureAbility.md#Want) | 是 | 启动Ability参数 | 573 574**返回值:** 575 576| 类型 | 说明 | 577| -------------- | ------------------- | 578| Promise\<void> | 以Promise形式返回。 | 579 580**示例:** 581 582```js 583var abilityDelegator; 584var want = { 585 bundleName: "bundleName", 586 abilityName: "abilityName" 587}; 588 589abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator(); 590abilityDelegator.startAbility(want).then((data: any) => { 591 console.info("startAbility promise"); 592}); 593``` 594 595 596 597### print 598 599print(msg: string, callback: AsyncCallback\<void>): void 600 601打印日志信息到单元测试终端控制台(callback形式) 602 603**系统能力:** SystemCapability.Ability.AbilityRuntime.Core 604 605**参数:** 606 607| 参数名 | 类型 | 必填 | 说明 | 608| -------- | -------------------- | ---- | ------------------ | 609| msg | string | 是 | 日志字符串 | 610| callback | AsyncCallback\<void> | 是 | 表示指定的回调方法 | 611 612**示例:** 613 614```js 615var abilityDelegator; 616var msg = "msg"; 617 618abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator(); 619abilityDelegator.print(msg, (err) => { 620 console.info("print callback"); 621}); 622``` 623 624 625 626### print 627 628print(msg: string): Promise\<void> 629 630打印日志信息到单元测试终端控制台(promise形式) 631 632**系统能力:** SystemCapability.Ability.AbilityRuntime.Core 633 634**参数:** 635 636| 参数名 | 类型 | 必填 | 说明 | 637| ------ | ------ | ---- | ---------- | 638| msg | string | 是 | 日志字符串 | 639 640**返回值:** 641 642| 类型 | 说明 | 643| -------------- | ------------------- | 644| Promise\<void> | 以Promise形式返回。 | 645 646**示例:** 647 648```js 649var abilityDelegator; 650var msg = "msg"; 651 652abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator(); 653abilityDelegator.print(msg).then(() => { 654 console.info("print promise"); 655}); 656``` 657 658 659 660### executeShellCommand 661 662executeShellCommand(cmd: string, callback: AsyncCallback\<ShellCmdResult>): void 663 664执行指定的shell命令(callback形式) 665 666**系统能力:** SystemCapability.Ability.AbilityRuntime.Core 667 668**参数:** 669 670| 参数名 | 类型 | 必填 | 说明 | 671| -------- | ------------------------------------------------------------ | ---- | ------------------ | 672| cmd | string | 是 | shell命令字符串 | 673| callback | AsyncCallback\<[ShellCmdResult](js-apis-application-shellCmdResult.md#ShellCmdResult)> | 是 | 表示指定的回调方法 | 674 675**示例:** 676 677```js 678var abilityDelegator; 679var cmd = "cmd"; 680 681abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator(); 682abilityDelegator.executeShellCommand(cmd, (err, data) => { 683 console.info("executeShellCommand callback"); 684}); 685``` 686 687 688 689### executeShellCommand 690 691executeShellCommand(cmd: string, timeoutSecs: number, callback: AsyncCallback\<ShellCmdResult>): void 692 693指定超时时间,并执行指定的shell命令(callback形式) 694 695**系统能力:** SystemCapability.Ability.AbilityRuntime.Core 696 697**参数:** 698 699| 参数名 | 类型 | 必填 | 说明 | 700| ----------- | ------------------------------------------------------------ | ---- | ----------------------------- | 701| cmd | string | 是 | shell命令字符串 | 702| timeoutSecs | number | 是 | 设定命令超时时间,单位秒(s) | 703| callback | AsyncCallback\<[ShellCmdResult](js-apis-application-shellCmdResult.md#ShellCmdResult)> | 是 | 表示指定的回调方法 | 704 705**示例:** 706 707```js 708var abilityDelegator; 709var cmd = "cmd"; 710var timeout = 100; 711 712abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator(); 713abilityDelegator.executeShellCommand(cmd, timeout, (err, data) => { 714 console.info("executeShellCommand callback"); 715}); 716``` 717 718 719 720### executeShellCommand 721 722executeShellCommand(cmd: string, timeoutSecs?: number): Promise\<ShellCmdResult>; 723 724指定超时时间,并执行指定的shell命令(promise形式) 725 726**系统能力:** SystemCapability.Ability.AbilityRuntime.Core 727 728**参数:** 729 730| 参数名 | 类型 | 必填 | 说明 | 731| ----------- | ------ | ---- | ----------------------------- | 732| cmd | string | 是 | shell命令字符串 | 733| timeoutSecs | number | 否 | 设定命令超时时间,单位秒(s) | 734 735**返回值:** 736 737| 类型 | 说明 | 738| ------------------------------------------------------------ | ------------------------------------------------------------ | 739| Promise\<[ShellCmdResult](js-apis-application-shellCmdResult.md#ShellCmdResult)> | 以Promise形式返回Shell命令执行结果[ShellCmdResult](js-apis-application-shellCmdResult.md#ShellCmdResult)对象。 | 740 741**示例:** 742 743```js 744var abilityDelegator; 745var cmd = "cmd"; 746var timeout = 100; 747 748abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator(); 749abilityDelegator.executeShellCommand(cmd, timeout).then((data : any) => { 750 console.info("executeShellCommand promise"); 751}); 752``` 753