1# @ohos.app.ability.wantAgent (WantAgent模块) 2 3app.ability.WantAgent是一个封装了[Want](./js-apis-app-ability-want.md)对象的类,允许应用程序能够在未来的某个时间点执行该Want。该模块提供了创建WantAgent实例、获取实例的用户ID、获取want信息、比较WantAgent实例和获取包名等功能。 4WantAgent的一个典型应用场景是通知处理。例如,当用户点击通知时,会触发WantAgent的[trigger](#wantagenttrigger)接口,并拉起目标应用。具体使用请参考[通知模块](../../notification/notification-with-wantagent.md)。该模块将会取代[@ohos.wantAgent](js-apis-wantAgent.md)模块,建议优先使用本模块。 5 6> **说明:** 7> 8> 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 9 10## 导入模块 11 12```ts 13import { wantAgent } from '@kit.AbilityKit'; 14``` 15 16## wantAgent.getWantAgent 17 18getWantAgent(info: WantAgentInfo, callback: AsyncCallback\<WantAgent\>): void 19 20创建WantAgent(callback形式)。 创建失败返回的WantAgent为空值。 21 22三方应用只能设置自己应用的Ability。 23 24**原子化服务API**:从API version 12开始,该接口支持在原子化服务中使用。 25 26**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 27 28**参数:** 29 30| 参数名 | 类型 | 必填 | 说明 | 31| -------- | -------------------------- | ---- | ----------------------- | 32| info | [WantAgentInfo](js-apis-inner-wantAgent-wantAgentInfo.md) | 是 | WantAgent信息。 | 33| callback | AsyncCallback\<WantAgent\> | 是 | 创建WantAgent的回调方法。 | 34 35**错误码:** 36 37以下错误码详细介绍请参考[通用错误码](../errorcode-universal.md)和[元能力子系统错误码](errorcode-ability.md)。 38 39| 错误码ID | 错误信息 | 40|-----------|--------------------| 41| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 42| 16000007 | Service busy. There are concurrent tasks. Try again later. | 43| 16000151 | Invalid wantagent object.| 44 45**示例:** 46 47```ts 48import { wantAgent, Want } from '@kit.AbilityKit'; 49import type { WantAgent } from '@kit.AbilityKit'; 50import { BusinessError } from '@kit.BasicServicesKit'; 51 52//wantAgent对象 53let wantAgentData: WantAgent; 54//WantAgentInfo对象 55let wantAgentInfo: wantAgent.WantAgentInfo = { 56 wants: [ 57 { 58 deviceId: 'deviceId', 59 bundleName: 'com.example.myapplication', 60 abilityName: 'EntryAbility', 61 action: 'action1', 62 entities: ['entity1'], 63 type: 'MIMETYPE', 64 uri: 'key={true,true,false}', 65 parameters: 66 { 67 mykey0: 2222, 68 mykey1: [1, 2, 3], 69 mykey2: '[1, 2, 3]', 70 mykey3: 'ssssssssssssssssssssssssss', 71 mykey4: [false, true, false], 72 mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'], 73 mykey6: true, 74 } 75 } as Want 76 ], 77 actionType: wantAgent.OperationType.START_ABILITY, 78 requestCode: 0, 79 wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] 80}; 81 82//getWantAgent回调 83function getWantAgentCallback(err: BusinessError, data: WantAgent) { 84 if (err) { 85 console.error(`getWantAgent failed, code: ${JSON.stringify(err.code)}, message: ${JSON.stringify(err.message)}`); 86 } else { 87 wantAgentData = data; 88 } 89} 90 91try { 92 wantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback); 93} catch (err) { 94 console.error(`getWantAgent failed, error: ${JSON.stringify(err)}`); 95} 96``` 97 98## wantAgent.getWantAgent 99 100getWantAgent(info: WantAgentInfo): Promise\<WantAgent\> 101 102创建WantAgent(Promise形式)。 创建失败返回的WantAgent为空值。 103 104三方应用只能设置自己应用的Ability。 105 106**原子化服务API**:从API version 12开始,该接口支持在原子化服务中使用。 107 108**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 109 110**参数:** 111 112| 参数名 | 类型 | 必填 | 说明 | 113| ---- | ------------- | ---- | ------------- | 114| info | [WantAgentInfo](js-apis-inner-wantAgent-wantAgentInfo.md) | 是 | WantAgent信息。 | 115 116**返回值:** 117 118| 类型 | 说明 | 119| ----------------------------------------------------------- | ------------------------------------------------------------ | 120| Promise\<WantAgent\> | 以Promise形式返回WantAgent。 | 121 122**错误码:** 123 124以下错误码详细介绍请参考[通用错误码](../errorcode-universal.md)和[元能力子系统错误码](errorcode-ability.md)。 125 126| 错误码ID | 错误信息 | 127|-----------|--------------------| 128| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 129| 16000007 | Service busy. There are concurrent tasks. Try again later. | 130| 16000151 | Invalid wantagent object.| 131 132**示例:** 133 134```ts 135import { wantAgent, Want } from '@kit.AbilityKit'; 136import type { WantAgent } from '@kit.AbilityKit'; 137import { BusinessError } from '@kit.BasicServicesKit'; 138 139let wantAgentData: WantAgent; 140//WantAgentInfo对象 141let wantAgentInfo: wantAgent.WantAgentInfo = { 142 wants: [ 143 { 144 deviceId: 'deviceId', 145 bundleName: 'com.example.myapplication', 146 abilityName: 'EntryAbility', 147 action: 'action1', 148 entities: ['entity1'], 149 type: 'MIMETYPE', 150 uri: 'key={true,true,false}', 151 parameters: 152 { 153 mykey0: 2222, 154 mykey1: [1, 2, 3], 155 mykey2: '[1, 2, 3]', 156 mykey3: 'ssssssssssssssssssssssssss', 157 mykey4: [false, true, false], 158 mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'], 159 mykey6: true, 160 } 161 } as Want 162 ], 163 actionType: wantAgent.OperationType.START_ABILITY, 164 requestCode: 0, 165 wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] 166}; 167 168try { 169 wantAgent.getWantAgent(wantAgentInfo).then((data) => { 170 wantAgentData = data; 171 }).catch((err: BusinessError) => { 172 console.error(`getWantAgent failed, code: ${JSON.stringify(err.code)}, message: ${JSON.stringify(err.message)}`); 173 }); 174} catch (err) { 175 console.error(`getWantAgent failed! ${err.code} ${err.message}`); 176} 177``` 178 179 180 181## wantAgent.getBundleName 182 183getBundleName(agent: WantAgent, callback: AsyncCallback\<string\>): void 184 185获取WantAgent实例的包名(callback形式)。 186 187**原子化服务API**:从API version 12开始,该接口支持在原子化服务中使用。 188 189**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 190 191**参数:** 192 193| 参数名 | 类型 | 必填 | 说明 | 194| -------- | ----------------------- | ---- | --------------------------------- | 195| agent | WantAgent | 是 | WantAgent对象。 | 196| callback | AsyncCallback\<string\> | 是 | 获取WantAgent实例的包名的回调方法。 | 197 198**错误码:** 199 200以下错误码详细介绍请参考[通用错误码](../errorcode-universal.md)和[元能力子系统错误码](errorcode-ability.md)。 201 202| 错误码ID | 错误信息 | 203|-----------|--------------------| 204| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 205| 16000007 | Service busy. There are concurrent tasks. Try again later. | 206| 16000151 | Invalid wantagent object.| 207 208**示例:** 209 210```ts 211import { wantAgent, Want } from '@kit.AbilityKit'; 212import type { WantAgent } from '@kit.AbilityKit'; 213import { BusinessError } from '@kit.BasicServicesKit'; 214 215//wantAgent对象 216let wantAgentData: WantAgent; 217//WantAgentInfo对象 218let wantAgentInfo: wantAgent.WantAgentInfo = { 219 wants: [ 220 { 221 deviceId: 'deviceId', 222 bundleName: 'com.example.myapplication', 223 abilityName: 'EntryAbility', 224 action: 'action1', 225 entities: ['entity1'], 226 type: 'MIMETYPE', 227 uri: 'key={true,true,false}', 228 parameters: 229 { 230 mykey0: 2222, 231 mykey1: [1, 2, 3], 232 mykey2: '[1, 2, 3]', 233 mykey3: 'ssssssssssssssssssssssssss', 234 mykey4: [false, true, false], 235 mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'], 236 mykey6: true, 237 } 238 } as Want 239 ], 240 actionType: wantAgent.OperationType.START_ABILITY, 241 requestCode: 0, 242 wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] 243}; 244 245//getWantAgent回调 246function getWantAgentCallback(err: BusinessError, data: WantAgent) { 247 if (err) { 248 console.error(`getWantAgent failed, code: ${JSON.stringify(err.code)}, message: ${JSON.stringify(err.message)}`); 249 } else { 250 wantAgentData = data; 251 } 252 //getBundleName回调 253 let getBundleNameCallback = (err: BusinessError, data: string) => { 254 if (err) { 255 console.error(`getBundleName failed! ${err.code} ${err.message}`); 256 } else { 257 console.info(`getBundleName ok! ${JSON.stringify(data)}`); 258 } 259 } 260 try { 261 wantAgent.getBundleName(wantAgentData, getBundleNameCallback); 262 } catch (err) { 263 console.error(`getBundleName failed! ${err.code} ${err.message}`); 264 } 265} 266 267try { 268 wantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback); 269} catch (err) { 270 console.error(`getWantAgent failed! ${err.code} ${err.message}`); 271} 272``` 273 274## wantAgent.getBundleName 275 276getBundleName(agent: WantAgent): Promise\<string\> 277 278获取WantAgent实例的包名(Promise形式)。 279 280**原子化服务API**:从API version 12开始,该接口支持在原子化服务中使用。 281 282**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 283 284**参数:** 285 286| 参数名 | 类型 | 必填 | 说明 | 287| ----- | --------- | ---- | ------------- | 288| agent | WantAgent | 是 | WantAgent对象。 | 289 290**返回值:** 291 292| 类型 | 说明 | 293| ----------------------------------------------------------- | ------------------------------------------------------------ | 294| Promise\<string\> | 以Promise形式返回获取WantAgent实例的包名。 | 295 296**错误码:** 297 298以下错误码详细介绍请参考[通用错误码](../errorcode-universal.md)和[元能力子系统错误码](errorcode-ability.md)。 299 300| 错误码ID | 错误信息 | 301|-----------|--------------------| 302| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 303| 16000007 | Service busy. There are concurrent tasks. Try again later. | 304| 16000151 | Invalid wantagent object.| 305 306**示例:** 307 308```ts 309import { wantAgent, Want } from '@kit.AbilityKit'; 310import type { WantAgent } from '@kit.AbilityKit'; 311import { BusinessError } from '@kit.BasicServicesKit'; 312 313//wantAgent对象 314let wantAgentData: WantAgent; 315//WantAgentInfo对象 316let wantAgentInfo: wantAgent.WantAgentInfo = { 317 wants: [ 318 { 319 deviceId: 'deviceId', 320 bundleName: 'com.example.myapplication', 321 abilityName: 'EntryAbility', 322 action: 'action1', 323 entities: ['entity1'], 324 type: 'MIMETYPE', 325 uri: 'key={true,true,false}', 326 parameters: 327 { 328 mykey0: 2222, 329 mykey1: [1, 2, 3], 330 mykey2: '[1, 2, 3]', 331 mykey3: 'ssssssssssssssssssssssssss', 332 mykey4: [false, true, false], 333 mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'], 334 mykey6: true, 335 } 336 } as Want 337 ], 338 actionType: wantAgent.OperationType.START_ABILITY, 339 requestCode: 0, 340 wantAgentFlags:[wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] 341}; 342 343//getWantAgent回调 344function getWantAgentCallback(err: BusinessError, data: WantAgent) { 345 if (err) { 346 console.error(`getWantAgent failed, code: ${JSON.stringify(err.code)}, message: ${JSON.stringify(err.message)}`); 347 } else { 348 wantAgentData = data; 349 } 350 try { 351 wantAgent.getBundleName(wantAgentData).then((data)=>{ 352 console.info(`getBundleName ok! ${JSON.stringify(data)}`); 353 }).catch((err: BusinessError)=>{ 354 console.error(`getBundleName failed! ${err.code} ${err.message}`); 355 }); 356 } catch(err){ 357 console.error(`getBundleName failed! ${err.code} ${err.message}`); 358 } 359} 360try { 361 wantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback); 362} catch(err) { 363 console.error(`getWantAgent failed! ${err.code} ${err.message}`); 364} 365``` 366 367## wantAgent.getUid 368 369getUid(agent: WantAgent, callback: AsyncCallback\<number\>): void 370 371获取WantAgent实例的用户ID(callback形式)。 372 373**原子化服务API**:从API version 12开始,该接口支持在原子化服务中使用。 374 375**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 376 377**参数:** 378 379| 参数名 | 类型 | 必填 | 说明 | 380| -------- | ----------------------- | ---- | ----------------------------------- | 381| agent | WantAgent | 是 | WantAgent对象。 | 382| callback | AsyncCallback\<number\> | 是 | 获取WantAgent实例的用户ID的回调方法。 | 383 384**错误码:** 385 386以下错误码详细介绍请参考[通用错误码](../errorcode-universal.md)和[元能力子系统错误码](errorcode-ability.md)。 387 388| 错误码ID | 错误信息 | 389|-----------|--------------------| 390| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 391| 16000007 | Service busy. There are concurrent tasks. Try again later. | 392| 16000151 | Invalid wantagent object.| 393 394**示例:** 395 396```ts 397import { wantAgent, Want } from '@kit.AbilityKit'; 398import type { WantAgent } from '@kit.AbilityKit'; 399import { BusinessError } from '@kit.BasicServicesKit'; 400 401//wantAgent对象 402let wantAgentData: WantAgent; 403//WantAgentInfo对象 404let wantAgentInfo: wantAgent.WantAgentInfo = { 405 wants: [ 406 { 407 deviceId: 'deviceId', 408 bundleName: 'com.example.myapplication', 409 abilityName: 'EntryAbility', 410 action: 'action1', 411 entities: ['entity1'], 412 type: 'MIMETYPE', 413 uri: 'key={true,true,false}', 414 parameters: 415 { 416 mykey0: 2222, 417 mykey1: [1, 2, 3], 418 mykey2: '[1, 2, 3]', 419 mykey3: 'ssssssssssssssssssssssssss', 420 mykey4: [false, true, false], 421 mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'], 422 mykey6: true, 423 } 424 } as Want 425 ], 426 actionType: wantAgent.OperationType.START_ABILITY, 427 requestCode: 0, 428 wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] 429}; 430 431//getWantAgent回调 432function getWantAgentCallback(err: BusinessError, data: WantAgent) { 433 if (err) { 434 console.info(`getWantAgent failed, code: ${JSON.stringify(err.code)}, message: ${JSON.stringify(err.message)}`); 435 } else { 436 wantAgentData = data; 437 } 438 //getUid回调 439 let getUidCallback = (err: BusinessError, data: number) => { 440 if (err) { 441 console.error(`getUid failed! ${err.code} ${err.message}`); 442 } else { 443 console.info(`getUid ok! ${JSON.stringify(data)}`); 444 } 445 } 446 try { 447 wantAgent.getUid(wantAgentData, getUidCallback); 448 } catch (err) { 449 console.error(`getUid failed! ${err.code} ${err.message}`); 450 } 451} 452 453try { 454 wantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback); 455} catch (err) { 456 console.error(`getWantAgent failed! ${err.code} ${err.message}`); 457} 458``` 459 460## wantAgent.getUid 461 462getUid(agent: WantAgent): Promise\<number\> 463 464获取WantAgent实例的用户ID(Promise形式)。 465 466**原子化服务API**:从API version 12开始,该接口支持在原子化服务中使用。 467 468**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 469 470**参数:** 471 472| 参数名 | 类型 | 必填 | 说明 | 473| ----- | --------- | ---- | ------------- | 474| agent | WantAgent | 是 | WantAgent对象。 | 475 476**返回值:** 477 478| 类型 | 说明 | 479| ----------------------------------------------------------- | ------------------------------------------------------------ | 480| Promise\<number\> | 以Promise形式返回获取WantAgent实例的用户ID。 | 481 482**错误码:** 483 484以下错误码详细介绍请参考[通用错误码](../errorcode-universal.md)和[元能力子系统错误码](errorcode-ability.md)。 485 486| 错误码ID | 错误信息 | 487|-----------|--------------------| 488| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 489| 16000007 | Service busy. There are concurrent tasks. Try again later. | 490| 16000151 | Invalid wantagent object.| 491 492**示例:** 493 494```ts 495import { wantAgent, Want } from '@kit.AbilityKit'; 496import type { WantAgent } from '@kit.AbilityKit'; 497import { BusinessError } from '@kit.BasicServicesKit'; 498 499//wantAgent对象 500let wantAgentData: WantAgent; 501//WantAgentInfo对象 502let wantAgentInfo: wantAgent.WantAgentInfo = { 503 wants: [ 504 { 505 deviceId: 'deviceId', 506 bundleName: 'com.example.myapplication', 507 abilityName: 'EntryAbility', 508 action: 'action1', 509 entities: ['entity1'], 510 type: 'MIMETYPE', 511 uri: 'key={true,true,false}', 512 parameters: 513 { 514 mykey0: 2222, 515 mykey1: [1, 2, 3], 516 mykey2: '[1, 2, 3]', 517 mykey3: 'ssssssssssssssssssssssssss', 518 mykey4: [false, true, false], 519 mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'], 520 mykey6: true, 521 } 522 } as Want 523 ], 524 actionType: wantAgent.OperationType.START_ABILITY, 525 requestCode: 0, 526 wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] 527}; 528 529//getWantAgent回调 530function getWantAgentCallback(err: BusinessError, data: WantAgent) { 531 if (err) { 532 console.info(`getWantAgent failed, code: ${JSON.stringify(err.code)}, message: ${JSON.stringify(err.message)}`); 533 } else { 534 wantAgentData = data; 535 } 536 try { 537 wantAgent.getUid(wantAgentData).then((data) => { 538 console.info(`getUid ok! ${JSON.stringify(data)}`); 539 }).catch((err: BusinessError) => { 540 console.error(`getUid failed! ${err.code} ${err.message}`); 541 }); 542 } catch (err) { 543 console.error(`getUid failed! ${err.code} ${err.message}`); 544 } 545} 546 547try { 548 wantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback); 549} catch (err) { 550 console.error(`getWantAgent failed! ${err.code} ${err.message}`); 551} 552``` 553 554## wantAgent.cancel 555 556cancel(agent: WantAgent, callback: AsyncCallback\<void\>): void 557 558取消WantAgent实例(callback形式)。 559 560**原子化服务API**:从API version 12开始,该接口支持在原子化服务中使用。 561 562**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 563 564**参数:** 565 566| 参数名 | 类型 | 必填 | 说明 | 567| -------- | --------------------- | ---- | --------------------------- | 568| agent | WantAgent | 是 | WantAgent对象。 | 569| callback | AsyncCallback\<void\> | 是 | 取消WantAgent实例的回调方法。 | 570 571**错误码:** 572 573以下错误码详细介绍请参考[通用错误码](../errorcode-universal.md)和[元能力子系统错误码](errorcode-ability.md)。 574 575| 错误码ID | 错误信息 | 576|-----------|--------------------| 577| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 578| 16000007 | Service busy. There are concurrent tasks. Try again later. | 579| 16000151 | Invalid wantagent object.| 580 581**示例:** 582 583```ts 584import { wantAgent, Want } from '@kit.AbilityKit'; 585import type { WantAgent } from '@kit.AbilityKit'; 586import { BusinessError } from '@kit.BasicServicesKit'; 587 588//wantAgent对象 589let wantAgentData: WantAgent; 590//WantAgentInfo对象 591let wantAgentInfo: wantAgent.WantAgentInfo = { 592 wants: [ 593 { 594 deviceId: 'deviceId', 595 bundleName: 'com.example.myapplication', 596 abilityName: 'EntryAbility', 597 action: 'action1', 598 entities: ['entity1'], 599 type: 'MIMETYPE', 600 uri: 'key={true,true,false}', 601 parameters: 602 { 603 mykey0: 2222, 604 mykey1: [1, 2, 3], 605 mykey2: '[1, 2, 3]', 606 mykey3: 'ssssssssssssssssssssssssss', 607 mykey4: [false, true, false], 608 mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'], 609 mykey6: true, 610 } 611 } as Want 612 ], 613 actionType: wantAgent.OperationType.START_ABILITY, 614 requestCode: 0, 615 wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] 616}; 617 618//getWantAgent回调 619function getWantAgentCallback(err: BusinessError, data: WantAgent) { 620 if (err) { 621 console.info(`getWantAgent failed, code: ${JSON.stringify(err.code)}, message: ${JSON.stringify(err.message)}`); 622 } else { 623 wantAgentData = data; 624 } 625 //cancel回调 626 let cancelCallback = (err: BusinessError, data: void) => { 627 if (err) { 628 console.error(`cancel failed! ${err.code} ${err.message}`); 629 } else { 630 console.info(`cancel ok!`); 631 } 632 } 633 try { 634 wantAgent.cancel(wantAgentData, cancelCallback); 635 } catch (err) { 636 console.error(`cancel failed! ${err.code} ${err.message}`); 637 } 638} 639 640try { 641 wantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback); 642} catch (err) { 643 console.error(`getWantAgent failed! ${(err as BusinessError).code} ${(err as BusinessError).message}`); 644} 645``` 646 647## wantAgent.cancel 648 649cancel(agent: WantAgent): Promise\<void\> 650 651取消WantAgent实例(Promise形式)。 652 653**原子化服务API**:从API version 12开始,该接口支持在原子化服务中使用。 654 655**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 656 657**参数:** 658 659| 参数名 | 类型 | 必填 | 说明 | 660| ----- | --------- | ---- | ------------- | 661| agent | WantAgent | 是 | WantAgent对象。 | 662 663**返回值:** 664 665| 类型 | 说明 | 666| --------------- | ------------------------------- | 667| Promise\<void\> | 以Promise形式获取异步返回结果。 | 668 669**错误码:** 670 671以下错误码详细介绍请参考[通用错误码](../errorcode-universal.md)和[元能力子系统错误码](errorcode-ability.md)。 672 673| 错误码ID | 错误信息 | 674|-----------|--------------------| 675| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 676| 16000007 | Service busy. There are concurrent tasks. Try again later. | 677| 16000151 | Invalid wantagent object.| 678 679**示例:** 680 681```ts 682import { wantAgent, Want } from '@kit.AbilityKit'; 683import type { WantAgent } from '@kit.AbilityKit'; 684import { BusinessError } from '@kit.BasicServicesKit'; 685 686//wantAgent对象 687let wantAgentData: WantAgent; 688//WantAgentInfo对象 689let wantAgentInfo: wantAgent.WantAgentInfo = { 690 wants: [ 691 { 692 deviceId: 'deviceId', 693 bundleName: 'com.example.myapplication', 694 abilityName: 'EntryAbility', 695 action: 'action1', 696 entities: ['entity1'], 697 type: 'MIMETYPE', 698 uri: 'key={true,true,false}', 699 parameters: 700 { 701 mykey0: 2222, 702 mykey1: [1, 2, 3], 703 mykey2: '[1, 2, 3]', 704 mykey3: 'ssssssssssssssssssssssssss', 705 mykey4: [false, true, false], 706 mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'], 707 mykey6: true, 708 } 709 } as Want 710 ], 711 actionType: wantAgent.OperationType.START_ABILITY, 712 requestCode: 0, 713 wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] 714}; 715 716//getWantAgent回调 717function getWantAgentCallback(err: BusinessError, data: WantAgent) { 718 if (err) { 719 console.info(`getWantAgent failed, code: ${JSON.stringify(err.code)}, message: ${JSON.stringify(err.message)}`); 720 } else { 721 wantAgentData = data; 722 } 723 try { 724 wantAgent.cancel(wantAgentData).then((data) => { 725 console.info('cancel ok!'); 726 }).catch((err: BusinessError) => { 727 console.error(`cancel failed! ${err.code} ${err.message}`); 728 }); 729 } catch (err) { 730 console.error(`cancel failed! ${err.code} ${err.message}`); 731 } 732} 733 734try { 735 wantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback); 736} catch (err) { 737 console.error(`getWantAgent failed! ${(err as BusinessError).code} ${(err as BusinessError).message}`); 738} 739``` 740 741## wantAgent.trigger 742 743trigger(agent: WantAgent, triggerInfo: TriggerInfo, callback?: AsyncCallback\<CompleteData\>): void 744 745主动激发WantAgent实例(callback形式)。 746 747**原子化服务API**:从API version 12开始,该接口支持在原子化服务中使用。 748 749**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 750 751**参数:** 752 753| 参数名 | 类型 | 必填 | 说明 | 754| ----------- | ----------------------------- | ---- | ------------------------------- | 755| agent | WantAgent | 是 | WantAgent对象。 | 756| triggerInfo | [TriggerInfo](js-apis-inner-wantAgent-triggerInfo.md) | 是 | TriggerInfo对象。 | 757| callback | AsyncCallback\<[CompleteData](#completedata)\> | 否 | 主动激发WantAgent实例的回调方法。 | 758 759**错误码:** 760 761以下错误码详细介绍请参考[通用错误码](../errorcode-universal.md)。 762 763| 错误码ID | 错误信息 | 764|-----------|--------------------| 765| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 766 767**示例:** 768 769```ts 770import { wantAgent, Want } from '@kit.AbilityKit'; 771import type { WantAgent } from '@kit.AbilityKit'; 772import { BusinessError } from '@kit.BasicServicesKit'; 773 774//wantAgent对象 775let wantAgentData: WantAgent; 776// triggerInfo 777let triggerInfo: wantAgent.TriggerInfo = { 778 code: 0 //自定义义结果码 779}; 780//WantAgentInfo对象 781let wantAgentInfo: wantAgent.WantAgentInfo = { 782 wants: [ 783 { 784 deviceId: 'deviceId', 785 bundleName: 'com.example.myapplication', 786 abilityName: 'EntryAbility', 787 action: 'action1', 788 entities: ['entity1'], 789 type: 'MIMETYPE', 790 uri: 'key={true,true,false}', 791 parameters: 792 { 793 mykey0: 2222, 794 mykey1: [1, 2, 3], 795 mykey2: '[1, 2, 3]', 796 mykey3: 'ssssssssssssssssssssssssss', 797 mykey4: [false, true, false], 798 mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'], 799 mykey6: true, 800 } 801 } as Want 802 ], 803 actionType: wantAgent.OperationType.START_ABILITY, 804 requestCode: 0, 805 wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] 806}; 807 808//getWantAgent回调 809function getWantAgentCallback(err: BusinessError, data: WantAgent) { 810 if (err) { 811 console.info(`getWantAgent failed, code: ${err.code}, message: ${err.message}`); 812 } else { 813 wantAgentData = data; 814 } 815 //trigger回调 816 let triggerCallback = (err: BusinessError, data: wantAgent.CompleteData) => { 817 if (err) { 818 console.error(`trigger failed, code: ${err.code}, message: ${err.message}`); 819 } else { 820 console.info(`trigger success, data: ${JSON.stringify(data)}`); 821 } 822 } 823 try { 824 wantAgent.trigger(wantAgentData, triggerInfo, triggerCallback); 825 } catch (err) { 826 let code = (err as BusinessError).code; 827 let msg = (err as BusinessError).message; 828 console.error(`trigger failed, code: ${code}, message: ${msg}.`); 829 } 830} 831 832try { 833 wantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback); 834} catch (err) { 835 let code = (err as BusinessError).code; 836 let msg = (err as BusinessError).message; 837 console.error(`getWantAgent failed, code: ${code}, message: ${msg}.`); 838} 839``` 840 841## wantAgent.equal 842 843equal(agent: WantAgent, otherAgent: WantAgent, callback: AsyncCallback\<boolean\>): void 844 845判断两个WantAgent实例是否相等(Callback形式),以此来判断是否是来自同一应用的相同操作。 846 847**原子化服务API**:从API version 12开始,该接口支持在原子化服务中使用。 848 849**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 850 851**参数:** 852 853| 参数名 | 类型 | 必填 | 说明 | 854| ---------- | ------------------------ | ---- | --------------------------------------- | 855| agent | WantAgent | 是 | WantAgent对象。 | 856| otherAgent | WantAgent | 是 | WantAgent对象。 | 857| callback | AsyncCallback\<boolean\> | 是 | 判断两个WantAgent实例是否相等的回调方法。返回true表示两个WantAgent实例相等,false表示两个WantAgent实例不相等。 | 858 859**错误码:** 860 861以下错误码详细介绍请参考[通用错误码](../errorcode-universal.md)。 862 863| 错误码ID | 错误信息 | 864|-----------|--------------------| 865| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 866 867**示例:** 868 869```ts 870import { wantAgent, Want } from '@kit.AbilityKit'; 871import type { WantAgent } from '@kit.AbilityKit'; 872import { BusinessError } from '@kit.BasicServicesKit'; 873 874//wantAgent对象 875let wantAgent1: WantAgent; 876let wantAgent2: WantAgent; 877//WantAgentInfo对象 878let wantAgentInfo: wantAgent.WantAgentInfo = { 879 wants: [ 880 { 881 deviceId: 'deviceId', 882 bundleName: 'com.example.myapplication', 883 abilityName: 'EntryAbility', 884 action: 'action1', 885 entities: ['entity1'], 886 type: 'MIMETYPE', 887 uri: 'key={true,true,false}', 888 parameters: 889 { 890 mykey0: 2222, 891 mykey1: [1, 2, 3], 892 mykey2: '[1, 2, 3]', 893 mykey3: 'ssssssssssssssssssssssssss', 894 mykey4: [false, true, false], 895 mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'], 896 mykey6: true, 897 } 898 } as Want 899 ], 900 actionType: wantAgent.OperationType.START_ABILITY, 901 requestCode: 0, 902 wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] 903}; 904 905//getWantAgent回调 906function getWantAgentCallback(err: BusinessError, data: WantAgent) { 907 if (err) { 908 console.error(`getWantAgent failed, code: ${JSON.stringify(err.code)}, message: ${JSON.stringify(err.message)}`); 909 } else { 910 wantAgent1 = data; 911 wantAgent2 = data; 912 } 913 //equal回调 914 let equalCallback = (err: BusinessError, data: boolean) => { 915 if (err) { 916 console.error(`equal failed! ${err.code} ${err.message}`); 917 } else { 918 console.info(`equal ok! ${JSON.stringify(data)}`); 919 } 920 } 921 try { 922 wantAgent.equal(wantAgent1, wantAgent2, equalCallback); 923 } catch (err) { 924 console.error(`equal failed! ${(err as BusinessError).code} ${(err as BusinessError).message}`); 925 } 926} 927 928try { 929 wantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback); 930} catch (err) { 931 console.error(`getWantAgent failed! ${(err as BusinessError).code} ${(err as BusinessError).message}`); 932} 933``` 934 935## wantAgent.equal 936 937equal(agent: WantAgent, otherAgent: WantAgent): Promise\<boolean\> 938 939判断两个WantAgent实例是否相等(Promise形式),以此来判断是否是来自同一应用的相同操作。 940 941**原子化服务API**:从API version 12开始,该接口支持在原子化服务中使用。 942 943**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 944 945**参数:** 946 947| 参数名 | 类型 | 必填 | 说明 | 948| ---------- | --------- | ---- | ------------- | 949| agent | WantAgent | 是 | WantAgent对象。 | 950| otherAgent | WantAgent | 是 | WantAgent对象。 | 951 952**返回值:** 953 954| 类型 | 说明 | 955| ----------------------------------------------------------- | ------------------------------------------------------------ | 956| Promise\<boolean\> | 以Promise形式返回获取判断两个WantAgent实例是否相等的结果。返回true表示两个WantAgent实例相等,false表示两个WantAgent实例不相等。 | 957 958**错误码:** 959 960以下错误码详细介绍请参考[通用错误码](../errorcode-universal.md)。 961 962| 错误码ID | 错误信息 | 963|-----------|--------------------| 964| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 965 966**示例:** 967 968```ts 969import { wantAgent, Want } from '@kit.AbilityKit'; 970import type { WantAgent } from '@kit.AbilityKit'; 971import { BusinessError } from '@kit.BasicServicesKit'; 972 973//wantAgent对象 974let wantAgent1: WantAgent; 975let wantAgent2: WantAgent; 976//WantAgentInfo对象 977let wantAgentInfo: wantAgent.WantAgentInfo = { 978 wants: [ 979 { 980 deviceId: 'deviceId', 981 bundleName: 'com.example.myapplication', 982 abilityName: 'EntryAbility', 983 action: 'action1', 984 entities: ['entity1'], 985 type: 'MIMETYPE', 986 uri: 'key={true,true,false}', 987 parameters: 988 { 989 mykey0: 2222, 990 mykey1: [1, 2, 3], 991 mykey2: '[1, 2, 3]', 992 mykey3: 'ssssssssssssssssssssssssss', 993 mykey4: [false, true, false], 994 mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'], 995 mykey6: true, 996 } 997 } as Want 998 ], 999 actionType: wantAgent.OperationType.START_ABILITY, 1000 requestCode: 0, 1001 wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] 1002}; 1003 1004//getWantAgent回调 1005function getWantAgentCallback(err: BusinessError, data: WantAgent) { 1006 if (err) { 1007 console.error(`getWantAgent failed, code: ${JSON.stringify(err.code)}, message: ${JSON.stringify(err.message)}`); 1008 } else { 1009 wantAgent1 = data; 1010 wantAgent2 = data; 1011 } 1012 try { 1013 wantAgent.equal(wantAgent1, wantAgent2).then((data) => { 1014 console.info(`equal ok! ${JSON.stringify(data)}`); 1015 }).catch((err: BusinessError) => { 1016 console.error(`equal failed! ${err.code} ${err.message}`); 1017 }) 1018 } catch (err) { 1019 console.error(`equal failed! ${(err as BusinessError).code} ${(err as BusinessError).message}`); 1020 } 1021} 1022 1023try { 1024 wantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback); 1025} catch (err) { 1026 console.error(`getWantAgent failed! ${(err as BusinessError).code} ${(err as BusinessError).message}`); 1027} 1028``` 1029 1030## wantAgent.getOperationType 1031 1032getOperationType(agent: WantAgent, callback: AsyncCallback\<number>): void 1033 1034获取一个WantAgent的OperationType信息(callback形式)。 1035 1036**原子化服务API**:从API version 12开始,该接口支持在原子化服务中使用。 1037 1038**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 1039 1040**参数:** 1041 1042| 参数名 | 类型 | 必填 | 说明 | 1043| ---------- | ------------------------ | ---- | --------------------------------------- | 1044| agent | WantAgent | 是 | WantAgent对象。 | 1045| callback | AsyncCallback\<number> | 是 | 获取一个WantAgent的OperationType信息的回调方法。 | 1046 1047**错误码:** 1048 1049以下错误码详细介绍请参考[通用错误码](../errorcode-universal.md)和[元能力子系统错误码](errorcode-ability.md)。 1050 1051| 错误码ID | 错误信息 | 1052|-----------|--------------------| 1053| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1054| 16000007 | Service busy. There are concurrent tasks. Try again later. | 1055| 16000015 | Service timeout.| 1056| 16000151 | Invalid wantagent object.| 1057 1058**示例:** 1059 1060```ts 1061import { wantAgent, Want } from '@kit.AbilityKit'; 1062import type { WantAgent } from '@kit.AbilityKit'; 1063import { BusinessError } from '@kit.BasicServicesKit'; 1064 1065//wantAgent对象 1066let wantAgentData: WantAgent; 1067//WantAgentInfo对象 1068let wantAgentInfo: wantAgent.WantAgentInfo = { 1069 wants: [ 1070 { 1071 deviceId: 'deviceId', 1072 bundleName: 'com.example.myapplication', 1073 abilityName: 'EntryAbility', 1074 action: 'action1', 1075 entities: ['entity1'], 1076 type: 'MIMETYPE', 1077 uri: 'key={true,true,false}', 1078 parameters: 1079 { 1080 mykey0: 2222, 1081 mykey1: [1, 2, 3], 1082 mykey2: '[1, 2, 3]', 1083 mykey3: 'ssssssssssssssssssssssssss', 1084 mykey4: [false, true, false], 1085 mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'], 1086 mykey6: true, 1087 } 1088 } as Want 1089 ], 1090 actionType: wantAgent.OperationType.START_ABILITY, 1091 requestCode: 0, 1092 wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] 1093}; 1094 1095//getWantAgent回调 1096function getWantAgentCallback(err: BusinessError, data: WantAgent) { 1097 if (err) { 1098 console.error(`getWantAgent failed, code: ${JSON.stringify(err.code)}, message: ${JSON.stringify(err.message)}`); 1099 } else { 1100 wantAgentData = data; 1101 } 1102 //getOperationTypeCallback回调 1103 let getOperationTypeCallback = (err: BusinessError, data: number) => { 1104 if (err) { 1105 console.error(`getOperationType failed! ${err.code} ${err.message}`); 1106 } else { 1107 console.info(`getOperationType ok! ${JSON.stringify(data)}`); 1108 } 1109 } 1110 try { 1111 wantAgent.getOperationType(wantAgentData, getOperationTypeCallback); 1112 } catch (err) { 1113 console.error(`getOperationTypeCallback failed! ${(err as BusinessError).code} ${(err as BusinessError).message}`); 1114 } 1115} 1116 1117try { 1118 wantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback); 1119} catch (err) { 1120 console.error(`getWantAgent failed! ${(err as BusinessError).code} ${(err as BusinessError).message}`); 1121} 1122``` 1123 1124## wantAgent.getOperationType 1125 1126getOperationType(agent: WantAgent): Promise\<number> 1127 1128获取一个WantAgent的OperationType信息(Promise形式)。 1129 1130**原子化服务API**:从API version 12开始,该接口支持在原子化服务中使用。 1131 1132**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 1133 1134**参数:** 1135 1136| 参数名 | 类型 | 必填 | 说明 | 1137| ---------- | --------- | ---- | ------------- | 1138| agent | WantAgent | 是 | WantAgent对象。 | 1139 1140**返回值:** 1141 1142| 类型 | 说明 | 1143| ----------------------------------------------------------- | ------------------------------------------------------------ | 1144| Promise\<number> | 以Promise形式返回获取operationType的结果。 | 1145 1146**错误码:** 1147 1148以下错误码详细介绍请参考[通用错误码](../errorcode-universal.md)和[元能力子系统错误码](errorcode-ability.md)。 1149 1150| 错误码ID | 错误信息 | 1151|-----------|--------------------| 1152| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1153| 16000007 | Service busy. There are concurrent tasks. Try again later. | 1154| 16000015 | Service timeout.| 1155| 16000151 | Invalid wantagent object.| 1156 1157错误码详细介绍请参考[元能力子系统错误码](errorcode-ability.md) 1158 1159**示例:** 1160 1161```ts 1162import { wantAgent, Want } from '@kit.AbilityKit'; 1163import type { WantAgent } from '@kit.AbilityKit'; 1164import { BusinessError } from '@kit.BasicServicesKit'; 1165 1166//wantAgent对象 1167let wantAgentData: WantAgent; 1168//WantAgentInfo对象 1169let wantAgentInfo: wantAgent.WantAgentInfo = { 1170 wants: [ 1171 { 1172 deviceId: 'deviceId', 1173 bundleName: 'com.example.myapplication', 1174 abilityName: 'EntryAbility', 1175 action: 'action1', 1176 entities: ['entity1'], 1177 type: 'MIMETYPE', 1178 uri: 'key={true,true,false}', 1179 parameters: 1180 { 1181 mykey0: 2222, 1182 mykey1: [1, 2, 3], 1183 mykey2: '[1, 2, 3]', 1184 mykey3: 'ssssssssssssssssssssssssss', 1185 mykey4: [false, true, false], 1186 mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'], 1187 mykey6: true, 1188 } 1189 } as Want 1190 ], 1191 actionType: wantAgent.OperationType.START_ABILITY, 1192 requestCode: 0, 1193 wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] 1194}; 1195 1196//getWantAgent回调 1197function getWantAgentCallback(err: BusinessError, data: WantAgent) { 1198 if (err) { 1199 console.error(`getWantAgent failed, code: ${JSON.stringify(err.code)}, message: ${JSON.stringify(err.message)}`); 1200 } else { 1201 wantAgentData = data; 1202 } 1203 try { 1204 wantAgent.getOperationType(wantAgentData).then((data) => { 1205 console.info(`getOperationType ok! ${JSON.stringify(data)}`); 1206 }).catch((err: BusinessError) => { 1207 console.error(`getOperationType failed! ${err.code} ${err.message}`); 1208 }); 1209 } catch (err) { 1210 console.error(`getOperationType failed! ${(err as BusinessError).code} ${(err as BusinessError).message}`); 1211 } 1212} 1213 1214try { 1215 wantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback); 1216} catch (err) { 1217 console.error(`getWantAgent failed! ${(err as BusinessError).code} ${(err as BusinessError).message}`); 1218} 1219``` 1220 1221## WantAgentFlags 1222 1223表示使用WantAgent类型的枚举。 1224 1225**原子化服务API**:从API version 12开始,该接口支持在原子化服务中使用。 1226 1227**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 1228 1229| 名称 | 值 | 说明 | 1230| ------------------- | -------------- |-------------------------------------------------------------------------| 1231| ONE_TIME_FLAG | 0 | WantAgent仅能使用一次。 | 1232| NO_BUILD_FLAG | 1 | 如果描述WantAgent对象不存在,则不创建它,直接返回null。 | 1233| CANCEL_PRESENT_FLAG | 2 | 在生成一个新的WantAgent对象前取消已存在的一个WantAgent对象。 | 1234| UPDATE_PRESENT_FLAG | 3 | 使用新的WantAgent的额外数据替换已存在的WantAgent中的额外数据。 | 1235| CONSTANT_FLAG | 4 | WantAgent是不可变的。 | 1236| REPLACE_ELEMENT | 5 | 当前Want中的element属性可被WantAgent.trigger()中Want的element属性取代。当前版本暂不支持。 | 1237| REPLACE_ACTION | 6 | 当前Want中的action属性可被WantAgent.trigger()中Want的action属性取代。当前版本暂不支持。 | 1238| REPLACE_URI | 7 | 当前Want中的uri属性可被WantAgent.trigger()中Want的uri属性取代。当前版本暂不支持。 | 1239| REPLACE_ENTITIES | 8 | 当前Want中的entities属性可被WantAgent.trigger()中Want的entities属性取代。当前版本暂不支持。 | 1240| REPLACE_BUNDLE | 9 | 当前Want中的bundleName属性可被WantAgent.trigger()中Want的bundleName属性取代。当前版本暂不支持。 | 1241 1242 1243 1244## OperationType 1245 1246表示操作WantAgent类型的枚举。 1247 1248**原子化服务API**:从API version 12开始,该接口支持在原子化服务中使用。 1249 1250**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 1251 1252| 名称 | 值 | 说明 | 1253| ----------------- | ------------- | ------------------------- | 1254| UNKNOWN_TYPE | 0 | 不识别的类型。 | 1255| START_ABILITY | 1 | 开启一个有页面的Ability。 | 1256| START_ABILITIES | 2 | 开启多个有页面的Ability。 | 1257| START_SERVICE | 3 | 开启一个无页面的Ability(仅在FA模型下生效)。 | 1258| SEND_COMMON_EVENT | 4 | 发送一个公共事件。 | 1259 1260 1261 1262## CompleteData 1263 1264表示主动激发WantAgent返回的数据。 1265 1266**原子化服务API**:从API version 12开始,该接口支持在原子化服务中使用。 1267 1268**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 1269 1270| 名称 | 类型 | 只读 | 可选 | 说明 | 1271| -------- | -------- | -------- | -------- | -------- | 1272| info | WantAgent | 否 | 否 | 触发的wantAgent。 | 1273| want | [Want](js-apis-app-ability-want.md#属性) | 否 | 否 | 存在的被触发的want。 | 1274| finalCode | number | 否 | 否 | 触发wantAgent的请求代码。 | 1275| finalData | string | 否 | 否 | 公共事件收集的最终数据。 | 1276| extraInfo | Record\<string, Object> | 否 |是 | 额外数据。 | 1277 1278## TriggerInfo 1279 1280type TriggerInfo = _TriggerInfo 1281 1282TriggerInfo对象。 1283 1284**原子化服务API**:从API version 12开始,该接口支持在原子化服务中使用。 1285 1286**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 1287 1288| 类型 | 说明 | 1289| --- | --- | 1290| [_TriggerInfo](js-apis-inner-wantAgent-triggerInfo.md) | TriggerInfo对象。 | 1291 1292## WantAgentInfo 1293 1294type WantAgentInfo = _WantAgentInfo 1295 1296WantAgentInfo对象。 1297 1298**原子化服务API**:从API version 12开始,该接口支持在原子化服务中使用。 1299 1300**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 1301 1302| 类型 | 说明 | 1303| --- | --- | 1304| [_WantAgentInfo](js-apis-inner-wantAgent-wantAgentInfo.md) | WantAgentInfo对象。 | 1305 1306## WantAgent 1307 1308type WantAgent = object 1309 1310WantAgent对象。 1311 1312**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 1313 1314| 类型 | 说明 | 1315| --- | --- | 1316| object | WantAgent对象。 | 1317