1# @ohos.app.ability.wantAgent (WantAgent) 2 3WantAgent is a class that encapsulates a [Want](./js-apis-app-ability-want.md) object and allows the application to execute the Want at a future time point. 4 5This module provides the APIs for creating a WantAgent object, obtaining the bundle name and UID of the application to which a WantAgent object belongs, proactively triggering a WantAgent object, and checking whether two WantAgent objects are the same. A typical use scenario of WantAgent is notification processing. For example, when a user touches a notification, the [trigger](#wantagenttrigger) API of WantAgent is triggered and the target application is started. For details, see [Notification](../../notification/notification-with-wantagent.md). 6 7> **NOTE** 8> 9> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version. 10 11## Modules to Import 12 13```ts 14import { wantAgent } from '@kit.AbilityKit'; 15``` 16 17## wantAgent.getWantAgent 18 19getWantAgent(info: WantAgentInfo, callback: AsyncCallback\<WantAgent\>): void 20 21Obtains a WantAgent object. This API uses an asynchronous callback to return the result. If the creation fails, a null value is returned. 22 23**Atomic service API**: This API can be used in atomic services since API version 12. 24 25**System capability**: SystemCapability.Ability.AbilityRuntime.Core 26 27**Parameters** 28 29| Name | Type | Mandatory| Description | 30| -------- | -------------------------- | ---- | ----------------------- | 31| info | [WantAgentInfo](js-apis-inner-wantAgent-wantAgentInfo.md) | Yes | Configuration information required for creating the WantAgent object, including the target UIAbility, operation type, and request code. In **WantAgentInfo**, a third-party application is only allowed to specify its own UIAbility.| 32| callback | AsyncCallback\<WantAgent\> | Yes | Callback used to return the WantAgent object.| 33 34**Error codes** 35 36For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 37 38| ID | Error Message | 39|-----------|--------------------| 40| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 41| 16000007 | Service busy. There are concurrent tasks. Try again later. | 42| 16000151 | Invalid wantAgent object.| 43 44**Example** 45 46```ts 47import { wantAgent, Want } from '@kit.AbilityKit'; 48import type { WantAgent } from '@kit.AbilityKit'; 49import { BusinessError } from '@kit.BasicServicesKit'; 50 51// WantAgent object 52let wantAgentData: WantAgent; 53// WantAgentInfo object 54let wantAgentInfo: wantAgent.WantAgentInfo = { 55 wants: [ 56 { 57 deviceId: 'deviceId', 58 bundleName: 'com.example.myapplication', 59 abilityName: 'EntryAbility', 60 action: 'action1', 61 entities: ['entity1'], 62 type: 'MIMETYPE', 63 uri: 'key={true,true,false}', 64 parameters: 65 { 66 mykey0: 2222, 67 mykey1: [1, 2, 3], 68 mykey2: '[1, 2, 3]', 69 mykey3: 'ssssssssssssssssssssssssss', 70 mykey4: [false, true, false], 71 mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'], 72 mykey6: true, 73 } 74 } as Want 75 ], 76 actionType: wantAgent.OperationType.START_ABILITY, 77 requestCode: 0, 78 wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] 79}; 80 81// getWantAgent callback 82function getWantAgentCallback(err: BusinessError, data: WantAgent) { 83 if (err) { 84 console.error(`getWantAgent failed, code: ${JSON.stringify(err.code)}, message: ${JSON.stringify(err.message)}`); 85 } else { 86 wantAgentData = data; 87 } 88} 89 90try { 91 wantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback); 92} catch (err) { 93 console.error(`getWantAgent failed, error: ${JSON.stringify(err)}`); 94} 95``` 96 97## wantAgent.getWantAgent 98 99getWantAgent(info: WantAgentInfo): Promise\<WantAgent\> 100 101Obtains a WantAgent object. This API uses a promise to return the result. If the creation fails, a null value is returned. 102 103**Atomic service API**: This API can be used in atomic services since API version 12. 104 105**System capability**: SystemCapability.Ability.AbilityRuntime.Core 106 107**Parameters** 108 109| Name| Type | Mandatory| Description | 110| ---- | ------------- | ---- | ------------- | 111| info | [WantAgentInfo](js-apis-inner-wantAgent-wantAgentInfo.md) | Yes | Configuration information required for creating the WantAgent object, including the target UIAbility, operation type, and request code. In **WantAgentInfo**, a third-party application is only allowed to specify its own UIAbility.| 112 113**Return value** 114 115| Type | Description | 116| ----------------------------------------------------------- | ------------------------------------------------------------ | 117| Promise\<WantAgent\> | Promise used to return the WantAgent object.| 118 119**Error codes** 120 121For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 122 123| ID | Error Message | 124|-----------|--------------------| 125| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 126| 16000007 | Service busy. There are concurrent tasks. Try again later. | 127| 16000151 | Invalid wantAgent object.| 128 129**Example** 130 131```ts 132import { wantAgent, Want } from '@kit.AbilityKit'; 133import type { WantAgent } from '@kit.AbilityKit'; 134import { BusinessError } from '@kit.BasicServicesKit'; 135 136let wantAgentData: WantAgent; 137// WantAgentInfo object 138let wantAgentInfo: wantAgent.WantAgentInfo = { 139 wants: [ 140 { 141 deviceId: 'deviceId', 142 bundleName: 'com.example.myapplication', 143 abilityName: 'EntryAbility', 144 action: 'action1', 145 entities: ['entity1'], 146 type: 'MIMETYPE', 147 uri: 'key={true,true,false}', 148 parameters: 149 { 150 mykey0: 2222, 151 mykey1: [1, 2, 3], 152 mykey2: '[1, 2, 3]', 153 mykey3: 'ssssssssssssssssssssssssss', 154 mykey4: [false, true, false], 155 mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'], 156 mykey6: true, 157 } 158 } as Want 159 ], 160 actionType: wantAgent.OperationType.START_ABILITY, 161 requestCode: 0, 162 wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] 163}; 164 165try { 166 wantAgent.getWantAgent(wantAgentInfo).then((data) => { 167 wantAgentData = data; 168 }).catch((err: BusinessError) => { 169 console.error(`getWantAgent failed, code: ${JSON.stringify(err.code)}, message: ${JSON.stringify(err.message)}`); 170 }); 171} catch (err) { 172 console.error(`getWantAgent failed! ${err.code} ${err.message}`); 173} 174``` 175 176 177 178## wantAgent.getBundleName 179 180getBundleName(agent: WantAgent, callback: AsyncCallback\<string\>): void 181 182Obtains the bundle name of the application to which the WantAgent object belongs. This API uses an asynchronous callback to return the result. 183 184**Atomic service API**: This API can be used in atomic services since API version 12. 185 186**System capability**: SystemCapability.Ability.AbilityRuntime.Core 187 188**Parameters** 189 190| Name | Type | Mandatory| Description | 191| -------- | ----------------------- | ---- | --------------------------------- | 192| agent | WantAgent | Yes | Target WantAgent object. | 193| callback | AsyncCallback\<string\> | Yes | Callback used to return the bundle name.| 194 195**Error codes** 196 197For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 198 199| ID | Error Message | 200|-----------|--------------------| 201| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 202| 16000007 | Service busy. There are concurrent tasks. Try again later. | 203| 16000151 | Invalid wantAgent object.| 204 205**Example** 206 207```ts 208import { wantAgent, Want } from '@kit.AbilityKit'; 209import type { WantAgent } from '@kit.AbilityKit'; 210import { BusinessError } from '@kit.BasicServicesKit'; 211 212// WantAgent object 213let wantAgentData: WantAgent; 214// WantAgentInfo object 215let wantAgentInfo: wantAgent.WantAgentInfo = { 216 wants: [ 217 { 218 deviceId: 'deviceId', 219 bundleName: 'com.example.myapplication', 220 abilityName: 'EntryAbility', 221 action: 'action1', 222 entities: ['entity1'], 223 type: 'MIMETYPE', 224 uri: 'key={true,true,false}', 225 parameters: 226 { 227 mykey0: 2222, 228 mykey1: [1, 2, 3], 229 mykey2: '[1, 2, 3]', 230 mykey3: 'ssssssssssssssssssssssssss', 231 mykey4: [false, true, false], 232 mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'], 233 mykey6: true, 234 } 235 } as Want 236 ], 237 actionType: wantAgent.OperationType.START_ABILITY, 238 requestCode: 0, 239 wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] 240}; 241 242// getWantAgent callback 243function getWantAgentCallback(err: BusinessError, data: WantAgent) { 244 if (err) { 245 console.error(`getWantAgent failed, code: ${JSON.stringify(err.code)}, message: ${JSON.stringify(err.message)}`); 246 } else { 247 wantAgentData = data; 248 } 249 // getBundleName callback 250 let getBundleNameCallback = (err: BusinessError, data: string) => { 251 if (err) { 252 console.error(`getBundleName failed! ${err.code} ${err.message}`); 253 } else { 254 console.info(`getBundleName ok! ${JSON.stringify(data)}`); 255 } 256 } 257 try { 258 wantAgent.getBundleName(wantAgentData, getBundleNameCallback); 259 } catch (err) { 260 console.error(`getBundleName failed! ${err.code} ${err.message}`); 261 } 262} 263 264try { 265 wantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback); 266} catch (err) { 267 console.error(`getWantAgent failed! ${err.code} ${err.message}`); 268} 269``` 270 271## wantAgent.getBundleName 272 273getBundleName(agent: WantAgent): Promise\<string\> 274 275Obtains the bundle name of the application to which the WantAgent object belongs. This API uses a promise to return the result. 276 277**Atomic service API**: This API can be used in atomic services since API version 12. 278 279**System capability**: SystemCapability.Ability.AbilityRuntime.Core 280 281**Parameters** 282 283| Name | Type | Mandatory| Description | 284| ----- | --------- | ---- | ------------- | 285| agent | WantAgent | Yes | Target WantAgent object.| 286 287**Return value** 288 289| Type | Description | 290| ----------------------------------------------------------- | ------------------------------------------------------------ | 291| Promise\<string\> | Promise used to return the bundle name.| 292 293**Error codes** 294 295For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 296 297| ID | Error Message | 298|-----------|--------------------| 299| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 300| 16000007 | Service busy. There are concurrent tasks. Try again later. | 301| 16000151 | Invalid wantAgent object.| 302 303**Example** 304 305```ts 306import { wantAgent, Want } from '@kit.AbilityKit'; 307import type { WantAgent } from '@kit.AbilityKit'; 308import { BusinessError } from '@kit.BasicServicesKit'; 309 310// WantAgent object 311let wantAgentData: WantAgent; 312// WantAgentInfo object 313let wantAgentInfo: wantAgent.WantAgentInfo = { 314 wants: [ 315 { 316 deviceId: 'deviceId', 317 bundleName: 'com.example.myapplication', 318 abilityName: 'EntryAbility', 319 action: 'action1', 320 entities: ['entity1'], 321 type: 'MIMETYPE', 322 uri: 'key={true,true,false}', 323 parameters: 324 { 325 mykey0: 2222, 326 mykey1: [1, 2, 3], 327 mykey2: '[1, 2, 3]', 328 mykey3: 'ssssssssssssssssssssssssss', 329 mykey4: [false, true, false], 330 mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'], 331 mykey6: true, 332 } 333 } as Want 334 ], 335 actionType: wantAgent.OperationType.START_ABILITY, 336 requestCode: 0, 337 wantAgentFlags:[wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] 338}; 339 340// getWantAgent callback 341function getWantAgentCallback(err: BusinessError, data: WantAgent) { 342 if (err) { 343 console.error(`getWantAgent failed, code: ${JSON.stringify(err.code)}, message: ${JSON.stringify(err.message)}`); 344 } else { 345 wantAgentData = data; 346 } 347 try { 348 wantAgent.getBundleName(wantAgentData).then((data)=>{ 349 console.info(`getBundleName ok! ${JSON.stringify(data)}`); 350 }).catch((err: BusinessError)=>{ 351 console.error(`getBundleName failed! ${err.code} ${err.message}`); 352 }); 353 } catch(err){ 354 console.error(`getBundleName failed! ${err.code} ${err.message}`); 355 } 356} 357try { 358 wantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback); 359} catch(err) { 360 console.error(`getWantAgent failed! ${err.code} ${err.message}`); 361} 362``` 363 364## wantAgent.getUid 365 366getUid(agent: WantAgent, callback: AsyncCallback\<number\>): void 367 368Obtains the UID of the application to which the WantAgent object belongs. This API uses an asynchronous callback to return the result. 369 370**Atomic service API**: This API can be used in atomic services since API version 12. 371 372**System capability**: SystemCapability.Ability.AbilityRuntime.Core 373 374**Parameters** 375 376| Name | Type | Mandatory| Description | 377| -------- | ----------------------- | ---- | ----------------------------------- | 378| agent | WantAgent | Yes | Target WantAgent object. | 379| callback | AsyncCallback\<number\> | Yes | Callback used to return the UID of the application.| 380 381**Error codes** 382 383For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 384 385| ID | Error Message | 386|-----------|--------------------| 387| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 388| 16000007 | Service busy. There are concurrent tasks. Try again later. | 389| 16000151 | Invalid wantAgent object.| 390 391**Example** 392 393```ts 394import { wantAgent, Want } from '@kit.AbilityKit'; 395import type { WantAgent } from '@kit.AbilityKit'; 396import { BusinessError } from '@kit.BasicServicesKit'; 397 398// WantAgent object 399let wantAgentData: WantAgent; 400// WantAgentInfo object 401let wantAgentInfo: wantAgent.WantAgentInfo = { 402 wants: [ 403 { 404 deviceId: 'deviceId', 405 bundleName: 'com.example.myapplication', 406 abilityName: 'EntryAbility', 407 action: 'action1', 408 entities: ['entity1'], 409 type: 'MIMETYPE', 410 uri: 'key={true,true,false}', 411 parameters: 412 { 413 mykey0: 2222, 414 mykey1: [1, 2, 3], 415 mykey2: '[1, 2, 3]', 416 mykey3: 'ssssssssssssssssssssssssss', 417 mykey4: [false, true, false], 418 mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'], 419 mykey6: true, 420 } 421 } as Want 422 ], 423 actionType: wantAgent.OperationType.START_ABILITY, 424 requestCode: 0, 425 wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] 426}; 427 428// getWantAgent callback 429function getWantAgentCallback(err: BusinessError, data: WantAgent) { 430 if (err) { 431 console.error(`getWantAgent failed, code: ${err.code}, message: ${err.message}.`); 432 } else { 433 wantAgentData = data; 434 } 435 // getUid callback 436 let getUidCallback = (err: BusinessError, data: number) => { 437 if (err) { 438 console.error(`getUid failed, err code: ${err.code}, err msg: ${err.message}.`); 439 } else { 440 console.info(`getUid ok, data: ${JSON.stringify(data)}.`); 441 } 442 } 443 try { 444 wantAgent.getUid(wantAgentData, getUidCallback); 445 } catch (err) { 446 let code = (err as BusinessError).code; 447 let msg = (err as BusinessError).message; 448 console.error(`getUid failed, err code: ${code}, err msg: ${msg}.`); 449 } 450} 451 452try { 453 wantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback); 454} catch (err) { 455 let code = (err as BusinessError).code; 456 let msg = (err as BusinessError).message; 457 console.error(`getWantAgent failed, err code: ${code}, err msg: ${msg}.`); 458} 459``` 460 461## wantAgent.getUid 462 463getUid(agent: WantAgent): Promise\<number\> 464 465Obtains the UID of the application to which the WantAgent object belongs. This API uses a promise to return the result. 466 467**Atomic service API**: This API can be used in atomic services since API version 12. 468 469**System capability**: SystemCapability.Ability.AbilityRuntime.Core 470 471**Parameters** 472 473| Name | Type | Mandatory| Description | 474| ----- | --------- | ---- | ------------- | 475| agent | WantAgent | Yes | Target WantAgent object.| 476 477**Return value** 478 479| Type | Description | 480| ----------------- | ------------------------------------------------- | 481| Promise\<number\> | Promise used to return the UID of the application.| 482 483**Error codes** 484 485For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 486 487| ID | Error Message | 488|-----------|--------------------| 489| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 490| 16000007 | Service busy. There are concurrent tasks. Try again later. | 491| 16000151 | Invalid wantAgent object.| 492 493**Example** 494 495```ts 496import { wantAgent, Want } from '@kit.AbilityKit'; 497import type { WantAgent } from '@kit.AbilityKit'; 498import { BusinessError } from '@kit.BasicServicesKit'; 499 500// WantAgent object 501let wantAgentData: WantAgent; 502// WantAgentInfo object 503let wantAgentInfo: wantAgent.WantAgentInfo = { 504 wants: [ 505 { 506 deviceId: 'deviceId', 507 bundleName: 'com.example.myapplication', 508 abilityName: 'EntryAbility', 509 action: 'action1', 510 entities: ['entity1'], 511 type: 'MIMETYPE', 512 uri: 'key={true,true,false}', 513 parameters: 514 { 515 mykey0: 2222, 516 mykey1: [1, 2, 3], 517 mykey2: '[1, 2, 3]', 518 mykey3: 'ssssssssssssssssssssssssss', 519 mykey4: [false, true, false], 520 mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'], 521 mykey6: true, 522 } 523 } as Want 524 ], 525 actionType: wantAgent.OperationType.START_ABILITY, 526 requestCode: 0, 527 wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] 528}; 529 530// getWantAgent callback 531function getWantAgentCallback(err: BusinessError, data: WantAgent) { 532 if (err) { 533 console.error(`getWantAgent failed, err code: ${err.code}, err msg: ${err.message}.`); 534 } else { 535 wantAgentData = data; 536 } 537 try { 538 wantAgent.getUid(wantAgentData).then((data) => { 539 console.info(`getUid ok, data: ${JSON.stringify(data)}.`); 540 }).catch((err: BusinessError) => { 541 console.error(`getUid failed, err code: ${err.code}, err msg: ${err.message}.`); 542 }); 543 } catch (err) { 544 let code = (err as BusinessError).code; 545 let msg = (err as BusinessError).message; 546 console.error(`getUid failed, err code: ${code}, err msg: ${msg}.`); 547 } 548} 549 550try { 551 wantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback); 552} catch (err) { 553 let code = (err as BusinessError).code; 554 let msg = (err as BusinessError).message; 555 console.error(`getWantAgent failed, err code: ${code}, err msg: ${msg}.`); 556} 557``` 558 559## wantAgent.cancel 560 561cancel(agent: WantAgent, callback: AsyncCallback\<void\>): void 562 563Cancels a WantAgent object. This API uses an asynchronous callback to return the result. 564 565**Atomic service API**: This API can be used in atomic services since API version 12. 566 567**System capability**: SystemCapability.Ability.AbilityRuntime.Core 568 569**Parameters** 570 571| Name | Type | Mandatory| Description | 572| -------- | --------------------- | ---- | --------------------------- | 573| agent | WantAgent | Yes | Target WantAgent object. | 574| callback | AsyncCallback\<void\> | Yes | Callback used to return the result.| 575 576**Error codes** 577 578For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 579 580| ID | Error Message | 581|-----------|--------------------| 582| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 583| 16000007 | Service busy. There are concurrent tasks. Try again later. | 584| 16000151 | Invalid wantAgent object.| 585 586**Example** 587 588```ts 589import { wantAgent, Want } from '@kit.AbilityKit'; 590import type { WantAgent } from '@kit.AbilityKit'; 591import { BusinessError } from '@kit.BasicServicesKit'; 592 593// WantAgent object 594let wantAgentData: WantAgent; 595// WantAgentInfo object 596let wantAgentInfo: wantAgent.WantAgentInfo = { 597 wants: [ 598 { 599 deviceId: 'deviceId', 600 bundleName: 'com.example.myapplication', 601 abilityName: 'EntryAbility', 602 action: 'action1', 603 entities: ['entity1'], 604 type: 'MIMETYPE', 605 uri: 'key={true,true,false}', 606 parameters: 607 { 608 mykey0: 2222, 609 mykey1: [1, 2, 3], 610 mykey2: '[1, 2, 3]', 611 mykey3: 'ssssssssssssssssssssssssss', 612 mykey4: [false, true, false], 613 mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'], 614 mykey6: true, 615 } 616 } as Want 617 ], 618 actionType: wantAgent.OperationType.START_ABILITY, 619 requestCode: 0, 620 wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] 621}; 622 623// getWantAgent callback 624function getWantAgentCallback(err: BusinessError, data: WantAgent) { 625 if (err) { 626 console.error(`getWantAgent failed, err code: ${err.code}, err msg: ${err.message}.`); 627 } else { 628 wantAgentData = data; 629 } 630 // cancel callback 631 let cancelCallback = (err: BusinessError, data: void) => { 632 if (err) { 633 console.error(`cancel failed, err code: ${err.code}, err msg: ${err.message}.`); 634 } else { 635 console.info(`cancel sucecss.`); 636 } 637 } 638 try { 639 wantAgent.cancel(wantAgentData, cancelCallback); 640 } catch (err) { 641 let code = (err as BusinessError).code; 642 let msg = (err as BusinessError).message; 643 console.error(`cancel failed, err code: ${code}, err msg: ${msg}.`); 644 } 645} 646 647try { 648 wantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback); 649} catch (err) { 650 let code = (err as BusinessError).code; 651 let msg = (err as BusinessError).message; 652 console.error(`getWantAgent failed, err code: ${code}, err msg: ${msg}.`); 653} 654``` 655 656## wantAgent.cancel 657 658cancel(agent: WantAgent): Promise\<void\> 659 660Cancels a WantAgent object. This API uses a promise to return the result. 661 662**Atomic service API**: This API can be used in atomic services since API version 12. 663 664**System capability**: SystemCapability.Ability.AbilityRuntime.Core 665 666**Parameters** 667 668| Name | Type | Mandatory| Description | 669| ----- | --------- | ---- | ------------- | 670| agent | WantAgent | Yes | Target WantAgent object.| 671 672**Return value** 673 674| Type | Description | 675| --------------- | ------------------------------- | 676| Promise\<void\> | Promise used to return the result.| 677 678**Error codes** 679 680For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 681 682| ID | Error Message | 683|-----------|--------------------| 684| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 685| 16000007 | Service busy. There are concurrent tasks. Try again later. | 686| 16000151 | Invalid wantAgent object.| 687 688**Example** 689 690```ts 691import { wantAgent, Want } from '@kit.AbilityKit'; 692import type { WantAgent } from '@kit.AbilityKit'; 693import { BusinessError } from '@kit.BasicServicesKit'; 694 695// WantAgent object 696let wantAgentData: WantAgent; 697// WantAgentInfo object 698let wantAgentInfo: wantAgent.WantAgentInfo = { 699 wants: [ 700 { 701 deviceId: 'deviceId', 702 bundleName: 'com.example.myapplication', 703 abilityName: 'EntryAbility', 704 action: 'action1', 705 entities: ['entity1'], 706 type: 'MIMETYPE', 707 uri: 'key={true,true,false}', 708 parameters: 709 { 710 mykey0: 2222, 711 mykey1: [1, 2, 3], 712 mykey2: '[1, 2, 3]', 713 mykey3: 'ssssssssssssssssssssssssss', 714 mykey4: [false, true, false], 715 mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'], 716 mykey6: true, 717 } 718 } as Want 719 ], 720 actionType: wantAgent.OperationType.START_ABILITY, 721 requestCode: 0, 722 wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] 723}; 724 725// getWantAgent callback 726function getWantAgentCallback(err: BusinessError, data: WantAgent) { 727 if (err) { 728 console.error(`getWantAgent failed, err code: ${err.code}, err msg: ${err.message}.`); 729 } else { 730 wantAgentData = data; 731 } 732 try { 733 wantAgent.cancel(wantAgentData).then((data) => { 734 console.info('cancel success.'); 735 }).catch((err: BusinessError) => { 736 console.error(`cancel failed, err code: ${err.code}, err msg: ${err.message}.`); 737 }); 738 } catch (err) { 739 let code = (err as BusinessError).code; 740 let msg = (err as BusinessError).message; 741 console.error(`cancel failed, err code: ${code}, err msg: ${msg}.`); 742 } 743} 744 745try { 746 wantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback); 747} catch (err) { 748 let code = (err as BusinessError).code; 749 let msg = (err as BusinessError).message; 750 console.error(`getWantAgent failed, err code: ${code}, err msg: ${msg}.`); 751} 752``` 753 754## wantAgent.trigger 755 756trigger(agent: WantAgent, triggerInfo: TriggerInfo, callback?: AsyncCallback\<CompleteData\>): void 757 758Proactively triggers a WantAgent object. This API uses an asynchronous callback to return the result. 759 760**Atomic service API**: This API can be used in atomic services since API version 12. 761 762**System capability**: SystemCapability.Ability.AbilityRuntime.Core 763 764**Parameters** 765 766| Name | Type | Mandatory| Description | 767| ----------- | ----------------------------- | ---- | ------------------------------- | 768| agent | WantAgent | Yes | Target WantAgent object. | 769| triggerInfo | [TriggerInfo](js-apis-inner-wantAgent-triggerInfo.md) | Yes | Information carried when the WantAgent object is triggered, for example, **extraInfos**.| 770| callback | AsyncCallback\<[CompleteData](#completedata)\> | No | Callback used to return the result.| 771 772**Error codes** 773 774For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 775 776| ID | Error Message | 777|-----------|--------------------| 778| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 779 780**Example** 781 782```ts 783import { wantAgent, Want } from '@kit.AbilityKit'; 784import type { WantAgent } from '@kit.AbilityKit'; 785import { BusinessError } from '@kit.BasicServicesKit'; 786 787// WantAgent object 788let wantAgentData: WantAgent; 789// triggerInfo 790let triggerInfo: wantAgent.TriggerInfo = { 791 code: 0 // Custom result code. 792}; 793// WantAgentInfo object 794let wantAgentInfo: wantAgent.WantAgentInfo = { 795 wants: [ 796 { 797 deviceId: 'deviceId', 798 bundleName: 'com.example.myapplication', 799 abilityName: 'EntryAbility', 800 action: 'action1', 801 entities: ['entity1'], 802 type: 'MIMETYPE', 803 uri: 'key={true,true,false}', 804 parameters: 805 { 806 mykey0: 2222, 807 mykey1: [1, 2, 3], 808 mykey2: '[1, 2, 3]', 809 mykey3: 'ssssssssssssssssssssssssss', 810 mykey4: [false, true, false], 811 mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'], 812 mykey6: true, 813 } 814 } as Want 815 ], 816 actionType: wantAgent.OperationType.START_ABILITY, 817 requestCode: 0, 818 wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] 819}; 820 821// getWantAgent callback 822function getWantAgentCallback(err: BusinessError, data: WantAgent) { 823 if (err) { 824 console.info(`getWantAgent failed, code: ${err.code}, message: ${err.message}`); 825 } else { 826 wantAgentData = data; 827 } 828 // trigger callback 829 let triggerCallback = (err: BusinessError, data: wantAgent.CompleteData) => { 830 if (err) { 831 console.error(`trigger failed, code: ${err.code}, message: ${err.message}`); 832 } else { 833 console.info(`trigger success, data: ${JSON.stringify(data)}`); 834 } 835 } 836 try { 837 wantAgent.trigger(wantAgentData, triggerInfo, triggerCallback); 838 } catch (err) { 839 let code = (err as BusinessError).code; 840 let msg = (err as BusinessError).message; 841 console.error(`trigger failed, code: ${code}, message: ${msg}.`); 842 } 843} 844 845try { 846 wantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback); 847} catch (err) { 848 let code = (err as BusinessError).code; 849 let msg = (err as BusinessError).message; 850 console.error(`getWantAgent failed, code: ${code}, message: ${msg}.`); 851} 852``` 853 854## wantAgent.equal 855 856equal(agent: WantAgent, otherAgent: WantAgent, callback: AsyncCallback\<boolean\>): void 857 858Checks whether two WantAgent objects are equal, so as to determine whether the same operation is from the same application. This API uses an asynchronous callback to return the result. 859 860**Atomic service API**: This API can be used in atomic services since API version 12. 861 862**System capability**: SystemCapability.Ability.AbilityRuntime.Core 863 864**Parameters** 865 866| Name | Type | Mandatory| Description | 867| ---------- | ------------------------ | ---- | --------------------------------------- | 868| agent | WantAgent | Yes | The first WantAgent object. | 869| otherAgent | WantAgent | Yes | The second WantAgent object. | 870| callback | AsyncCallback\<boolean\> | Yes | Callback used to return the result. **true** if equal, **false** otherwise.| 871 872**Error codes** 873 874For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 875 876| ID | Error Message | 877|-----------|--------------------| 878| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 879 880**Example** 881 882```ts 883import { wantAgent, Want } from '@kit.AbilityKit'; 884import type { WantAgent } from '@kit.AbilityKit'; 885import { BusinessError } from '@kit.BasicServicesKit'; 886 887// WantAgent object 888let wantAgent1: WantAgent; 889let wantAgent2: WantAgent; 890// WantAgentInfo object 891let wantAgentInfo: wantAgent.WantAgentInfo = { 892 wants: [ 893 { 894 deviceId: 'deviceId', 895 bundleName: 'com.example.myapplication', 896 abilityName: 'EntryAbility', 897 action: 'action1', 898 entities: ['entity1'], 899 type: 'MIMETYPE', 900 uri: 'key={true,true,false}', 901 parameters: 902 { 903 mykey0: 2222, 904 mykey1: [1, 2, 3], 905 mykey2: '[1, 2, 3]', 906 mykey3: 'ssssssssssssssssssssssssss', 907 mykey4: [false, true, false], 908 mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'], 909 mykey6: true, 910 } 911 } as Want 912 ], 913 actionType: wantAgent.OperationType.START_ABILITY, 914 requestCode: 0, 915 wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] 916}; 917 918// getWantAgent callback 919function getWantAgentCallback(err: BusinessError, data: WantAgent) { 920 if (err) { 921 console.error(`getWantAgent failed, code: ${JSON.stringify(err.code)}, message: ${JSON.stringify(err.message)}`); 922 } else { 923 wantAgent1 = data; 924 wantAgent2 = data; 925 } 926 // equal callback 927 let equalCallback = (err: BusinessError, data: boolean) => { 928 if (err) { 929 console.error(`equal failed! ${err.code} ${err.message}`); 930 } else { 931 console.info(`equal ok! ${JSON.stringify(data)}`); 932 } 933 } 934 try { 935 wantAgent.equal(wantAgent1, wantAgent2, equalCallback); 936 } catch (err) { 937 console.error(`equal failed! ${(err as BusinessError).code} ${(err as BusinessError).message}`); 938 } 939} 940 941try { 942 wantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback); 943} catch (err) { 944 console.error(`getWantAgent failed! ${(err as BusinessError).code} ${(err as BusinessError).message}`); 945} 946``` 947 948## wantAgent.equal 949 950equal(agent: WantAgent, otherAgent: WantAgent): Promise\<boolean\> 951 952Checks whether two WantAgent object are equal, so as to determine whether the same operation is from the same application. This API uses a promise to return the result. 953 954**Atomic service API**: This API can be used in atomic services since API version 12. 955 956**System capability**: SystemCapability.Ability.AbilityRuntime.Core 957 958**Parameters** 959 960| Name | Type | Mandatory| Description | 961| ---------- | --------- | ---- | ------------- | 962| agent | WantAgent | Yes | The first WantAgent object.| 963| otherAgent | WantAgent | Yes | The second WantAgent object.| 964 965**Return value** 966 967| Type | Description | 968| ----------------------------------------------------------- | ------------------------------------------------------------ | 969| Promise\<boolean\> | Promise used to return the result. **true** if equal, **false** otherwise.| 970 971**Error codes** 972 973For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 974 975| ID | Error Message | 976|-----------|--------------------| 977| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 978 979**Example** 980 981```ts 982import { wantAgent, Want } from '@kit.AbilityKit'; 983import type { WantAgent } from '@kit.AbilityKit'; 984import { BusinessError } from '@kit.BasicServicesKit'; 985 986// WantAgent object 987let wantAgent1: WantAgent; 988let wantAgent2: WantAgent; 989// WantAgentInfo object 990let wantAgentInfo: wantAgent.WantAgentInfo = { 991 wants: [ 992 { 993 deviceId: 'deviceId', 994 bundleName: 'com.example.myapplication', 995 abilityName: 'EntryAbility', 996 action: 'action1', 997 entities: ['entity1'], 998 type: 'MIMETYPE', 999 uri: 'key={true,true,false}', 1000 parameters: 1001 { 1002 mykey0: 2222, 1003 mykey1: [1, 2, 3], 1004 mykey2: '[1, 2, 3]', 1005 mykey3: 'ssssssssssssssssssssssssss', 1006 mykey4: [false, true, false], 1007 mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'], 1008 mykey6: true, 1009 } 1010 } as Want 1011 ], 1012 actionType: wantAgent.OperationType.START_ABILITY, 1013 requestCode: 0, 1014 wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] 1015}; 1016 1017// getWantAgent callback 1018function getWantAgentCallback(err: BusinessError, data: WantAgent) { 1019 if (err) { 1020 console.error(`getWantAgent failed, code: ${JSON.stringify(err.code)}, message: ${JSON.stringify(err.message)}`); 1021 } else { 1022 wantAgent1 = data; 1023 wantAgent2 = data; 1024 } 1025 try { 1026 wantAgent.equal(wantAgent1, wantAgent2).then((data) => { 1027 console.info(`equal ok! ${JSON.stringify(data)}`); 1028 }).catch((err: BusinessError) => { 1029 console.error(`equal failed! ${err.code} ${err.message}`); 1030 }) 1031 } catch (err) { 1032 console.error(`equal failed! ${(err as BusinessError).code} ${(err as BusinessError).message}`); 1033 } 1034} 1035 1036try { 1037 wantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback); 1038} catch (err) { 1039 console.error(`getWantAgent failed! ${(err as BusinessError).code} ${(err as BusinessError).message}`); 1040} 1041``` 1042 1043## wantAgent.getOperationType 1044 1045getOperationType(agent: WantAgent, callback: AsyncCallback\<number>): void 1046 1047Obtains the operation type of a WantAgent object. This API uses an asynchronous callback to return the result. 1048 1049**Atomic service API**: This API can be used in atomic services since API version 12. 1050 1051**System capability**: SystemCapability.Ability.AbilityRuntime.Core 1052 1053**Parameters** 1054 1055| Name | Type | Mandatory| Description | 1056| ---------- | ------------------------ | ---- | --------------------------------------- | 1057| agent | WantAgent | Yes | Target WantAgent object. | 1058| callback | AsyncCallback\<number> | Yes | Callback used to return the operation type.| 1059 1060**Error codes** 1061 1062For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 1063 1064| ID | Error Message | 1065|-----------|--------------------| 1066| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1067| 16000007 | Service busy. There are concurrent tasks. Try again later. | 1068| 16000015 | Service timeout.| 1069| 16000151 | Invalid wantAgent object.| 1070 1071**Example** 1072 1073```ts 1074import { wantAgent, Want } from '@kit.AbilityKit'; 1075import type { WantAgent } from '@kit.AbilityKit'; 1076import { BusinessError } from '@kit.BasicServicesKit'; 1077 1078// WantAgent object 1079let wantAgentData: WantAgent; 1080// WantAgentInfo object 1081let wantAgentInfo: wantAgent.WantAgentInfo = { 1082 wants: [ 1083 { 1084 deviceId: 'deviceId', 1085 bundleName: 'com.example.myapplication', 1086 abilityName: 'EntryAbility', 1087 action: 'action1', 1088 entities: ['entity1'], 1089 type: 'MIMETYPE', 1090 uri: 'key={true,true,false}', 1091 parameters: 1092 { 1093 mykey0: 2222, 1094 mykey1: [1, 2, 3], 1095 mykey2: '[1, 2, 3]', 1096 mykey3: 'ssssssssssssssssssssssssss', 1097 mykey4: [false, true, false], 1098 mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'], 1099 mykey6: true, 1100 } 1101 } as Want 1102 ], 1103 actionType: wantAgent.OperationType.START_ABILITY, 1104 requestCode: 0, 1105 wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] 1106}; 1107 1108// getWantAgent callback 1109function getWantAgentCallback(err: BusinessError, data: WantAgent) { 1110 if (err) { 1111 console.error(`getWantAgent failed, code: ${JSON.stringify(err.code)}, message: ${JSON.stringify(err.message)}`); 1112 } else { 1113 wantAgentData = data; 1114 } 1115 // getOperationTypeCallback callback 1116 let getOperationTypeCallback = (err: BusinessError, data: number) => { 1117 if (err) { 1118 console.error(`getOperationType failed! ${err.code} ${err.message}`); 1119 } else { 1120 console.info(`getOperationType ok! ${JSON.stringify(data)}`); 1121 } 1122 } 1123 try { 1124 wantAgent.getOperationType(wantAgentData, getOperationTypeCallback); 1125 } catch (err) { 1126 console.error(`getOperationTypeCallback failed! ${(err as BusinessError).code} ${(err as BusinessError).message}`); 1127 } 1128} 1129 1130try { 1131 wantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback); 1132} catch (err) { 1133 console.error(`getWantAgent failed! ${(err as BusinessError).code} ${(err as BusinessError).message}`); 1134} 1135``` 1136 1137## wantAgent.getOperationType 1138 1139getOperationType(agent: WantAgent): Promise\<number> 1140 1141Obtains the operation type of a WantAgent object. This API uses a promise to return the result. 1142 1143**Atomic service API**: This API can be used in atomic services since API version 12. 1144 1145**System capability**: SystemCapability.Ability.AbilityRuntime.Core 1146 1147**Parameters** 1148 1149| Name | Type | Mandatory| Description | 1150| ---------- | --------- | ---- | ------------- | 1151| agent | WantAgent | Yes | Target WantAgent object.| 1152 1153**Return value** 1154 1155| Type | Description | 1156| ----------------------------------------------------------- | ------------------------------------------------------------ | 1157| Promise\<number> | Promise used to return the operation type.| 1158 1159**Error codes** 1160 1161For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 1162 1163| ID | Error Message | 1164|-----------|--------------------| 1165| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1166| 16000007 | Service busy. There are concurrent tasks. Try again later. | 1167| 16000015 | Service timeout.| 1168| 16000151 | Invalid wantAgent object.| 1169 1170**Example** 1171 1172```ts 1173import { wantAgent, Want } from '@kit.AbilityKit'; 1174import type { WantAgent } from '@kit.AbilityKit'; 1175import { BusinessError } from '@kit.BasicServicesKit'; 1176 1177// WantAgent object 1178let wantAgentData: WantAgent; 1179// WantAgentInfo object 1180let wantAgentInfo: wantAgent.WantAgentInfo = { 1181 wants: [ 1182 { 1183 deviceId: 'deviceId', 1184 bundleName: 'com.example.myapplication', 1185 abilityName: 'EntryAbility', 1186 action: 'action1', 1187 entities: ['entity1'], 1188 type: 'MIMETYPE', 1189 uri: 'key={true,true,false}', 1190 parameters: 1191 { 1192 mykey0: 2222, 1193 mykey1: [1, 2, 3], 1194 mykey2: '[1, 2, 3]', 1195 mykey3: 'ssssssssssssssssssssssssss', 1196 mykey4: [false, true, false], 1197 mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'], 1198 mykey6: true, 1199 } 1200 } as Want 1201 ], 1202 actionType: wantAgent.OperationType.START_ABILITY, 1203 requestCode: 0, 1204 wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] 1205}; 1206 1207// getWantAgent callback 1208function getWantAgentCallback(err: BusinessError, data: WantAgent) { 1209 if (err) { 1210 console.error(`getWantAgent failed, code: ${JSON.stringify(err.code)}, message: ${JSON.stringify(err.message)}`); 1211 } else { 1212 wantAgentData = data; 1213 } 1214 try { 1215 wantAgent.getOperationType(wantAgentData).then((data) => { 1216 console.info(`getOperationType ok! ${JSON.stringify(data)}`); 1217 }).catch((err: BusinessError) => { 1218 console.error(`getOperationType failed! ${err.code} ${err.message}`); 1219 }); 1220 } catch (err) { 1221 console.error(`getOperationType failed! ${(err as BusinessError).code} ${(err as BusinessError).message}`); 1222 } 1223} 1224 1225try { 1226 wantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback); 1227} catch (err) { 1228 console.error(`getWantAgent failed! ${(err as BusinessError).code} ${(err as BusinessError).message}`); 1229} 1230``` 1231 1232## WantAgentFlags 1233 1234Enumerates the flags used by the WantAgent objects. 1235 1236**Atomic service API**: This API can be used in atomic services since API version 12. 1237 1238**System capability**: SystemCapability.Ability.AbilityRuntime.Core 1239 1240| Name | Value | Description | 1241| ------------------- | -------------- |-------------------------------------------------------------------------| 1242| ONE_TIME_FLAG | 0 | The WantAgent object can be used only once. | 1243| NO_BUILD_FLAG | 1 | The WantAgent object does not exist and hence it is not created. In this case, **null** is returned. | 1244| CANCEL_PRESENT_FLAG | 2 | The existing WantAgent object should be canceled before a new object is generated. | 1245| UPDATE_PRESENT_FLAG | 3 | Extra information of the existing WantAgent object is replaced with that of the new object. | 1246| CONSTANT_FLAG | 4 | The WantAgent object is immutable. | 1247| REPLACE_ELEMENT | 5 | The **element** property in the current Want can be replaced by the **element** property in the Want passed in **WantAgent.trigger()**. This processing is not supported yet. | 1248| REPLACE_ACTION | 6 | The **action** property in the current Want can be replaced by the **action** property in the Want passed in **WantAgent.trigger()**. This processing is not supported yet. | 1249| REPLACE_URI | 7 | The **uri** property in the current Want can be replaced by the **uri** property in the Want passed in **WantAgent.trigger()**. This processing is not supported yet. | 1250| REPLACE_ENTITIES | 8 | The **entities** property in the current Want can be replaced by the **entities** property in the Want passed in **WantAgent.trigger()**. This processing is not supported yet. | 1251| REPLACE_BUNDLE | 9 | The **bundleName** property in the current Want can be replaced by the **bundleName** property in the Want passed in **WantAgent.trigger()**. This processing is not supported yet.| 1252 1253 1254 1255## OperationType 1256 1257Enumerates the operation types of the WantAgent objects. 1258 1259**Atomic service API**: This API can be used in atomic services since API version 12. 1260 1261**System capability**: SystemCapability.Ability.AbilityRuntime.Core 1262 1263| Name | Value | Description | 1264| ----------------- | ------------- | ------------------------- | 1265| UNKNOWN_TYPE | 0 | Unknown operation type. | 1266| START_ABILITY | 1 | Starts an ability with a UI.| 1267| START_ABILITIES | 2 | Starts multiple abilities with a UI.| 1268| START_SERVICE | 3 | Starts an ability without a UI (valid only in the FA model).| 1269| SEND_COMMON_EVENT | 4 | Sends a common event. | 1270 1271 1272 1273## CompleteData 1274 1275Describes the data returned by the operation of proactive triggering a WantAgent object. 1276 1277**Atomic service API**: This API can be used in atomic services since API version 12. 1278 1279**System capability**: SystemCapability.Ability.AbilityRuntime.Core 1280 1281| Name| Type| Read-only| Optional| Description| 1282| -------- | -------- | -------- | -------- | -------- | 1283| info | WantAgent | No| No | WantAgent object that is triggered. | 1284| want | [Want](js-apis-app-ability-want.md) | No| No | Existing Want that is triggered. | 1285| finalCode | number | No| No | Request code that triggers the WantAgent object.| 1286| finalData | string | No| No | Final data collected by the common event. | 1287| extraInfo | Record\<string, Object> | No|Yes | Extra information. | 1288 1289## TriggerInfo 1290 1291type TriggerInfo = _TriggerInfo 1292 1293Defines the TriggerInfo object. 1294 1295**Atomic service API**: This API can be used in atomic services since API version 12. 1296 1297**System capability**: SystemCapability.Ability.AbilityRuntime.Core 1298 1299| Type| Description| 1300| --- | --- | 1301| [_TriggerInfo](js-apis-inner-wantAgent-triggerInfo.md) | TriggerInfo object.| 1302 1303## WantAgentInfo 1304 1305type WantAgentInfo = _WantAgentInfo 1306 1307Defines the WantAgentInfo object. 1308 1309**Atomic service API**: This API can be used in atomic services since API version 12. 1310 1311**System capability**: SystemCapability.Ability.AbilityRuntime.Core 1312 1313| Type| Description| 1314| --- | --- | 1315| [_WantAgentInfo](js-apis-inner-wantAgent-wantAgentInfo.md) | WantAgentInfo object.| 1316 1317## WantAgent 1318 1319type WantAgent = object 1320 1321Target WantAgent object. 1322 1323**System capability**: SystemCapability.Ability.AbilityRuntime.Core 1324 1325| Type| Description| 1326| --- | --- | 1327| object | Target WantAgent object.| 1328