1# @ohos.wantAgent (WantAgent) 2 3The **WantAgent** module provides APIs for creating and comparing **WantAgent** objects, and obtaining the user ID and bundle name of a **WantAgent** object. 4 5> **NOTE** 6> 7> The APIs of this module are supported since API version 7 and deprecated since API version 9. You are advised to use [@ohos.app.ability.wantAgent](js-apis-app-ability-wantAgent.md) instead. Newly added APIs will be marked with a superscript to indicate their earliest API version. 8 9## Modules to Import 10 11```ts 12import WantAgent from '@ohos.wantAgent'; 13``` 14 15## WantAgent.getWant 16 17getWant(agent: WantAgent, callback: AsyncCallback\<Want\>): void 18 19Obtains the Want in a **WantAgent** object. This API uses an asynchronous callback to return the result. 20 21**System capability**: SystemCapability.Ability.AbilityRuntime.Core 22 23**Parameters** 24 25| Name | Type | Mandatory| Description | 26| -------- | -------------------------- | ---- | ----------------------- | 27| agent | [WantAgent](js-apis-inner-wantAgent-wantAgentInfo.md) | Yes | **WantAgent** object. | 28| callback | AsyncCallback\<Want\> | Yes | Callback used to return the Want.| 29 30**Example** 31 32```ts 33import WantAgent from '@ohos.wantAgent'; 34 35 36// WantAgent object 37let wantAgent; 38 39// getWantAgent callback 40function getWantAgentCallback(err, data) { 41 console.info('==========================>getWantAgentCallback=======================>'); 42 if (err.code == 0) { 43 wantAgent = data; 44 } else { 45 console.error('getWantAgent failed, error: ' + JSON.stringify(err)); 46 return; 47 } 48 49 // getWant callback 50 function getWantCallback(err, data) { 51 console.info('==========================>getWantCallback=======================>'); 52 } 53 WantAgent.getWant(wantAgent, getWantCallback); 54} 55// WantAgentInfo object 56let wantAgentInfo = { 57 wants: [ 58 { 59 deviceId: 'deviceId', 60 bundleName: 'com.neu.setResultOnAbilityResultTest1', 61 abilityName: 'com.example.test.EntryAbility', 62 action: 'action1', 63 entities: ['entity1'], 64 type: 'MIMETYPE', 65 uri: 'key={true,true,false}', 66 parameters: 67 { 68 mykey0: 2222, 69 mykey1: [1, 2, 3], 70 mykey2: '[1, 2, 3]', 71 mykey3: 'ssssssssssssssssssssssssss', 72 mykey4: [false, true, false], 73 mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'], 74 mykey6: true, 75 } 76 } 77 ], 78 operationType: WantAgent.OperationType.START_ABILITIES, 79 requestCode: 0, 80 wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] 81}; 82 83WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback); 84``` 85 86## WantAgent.getWant 87 88getWant(agent: WantAgent): Promise\<Want\> 89 90Obtains the Want in a **WantAgent** object. This API uses a promise to return the result. 91 92**System capability**: SystemCapability.Ability.AbilityRuntime.Core 93 94**Parameters** 95 96| Name| Type | Mandatory| Description | 97| ---- | ------------- | ---- | ------------- | 98| agent | [WantAgent](js-apis-inner-wantAgent-wantAgentInfo.md) | Yes | **WantAgent** object.| 99 100**Return value** 101 102| Type | Description | 103| ----------------------------------------------------------- | ------------------------------------------------------------ | 104| Promise\<Want\> | Promise used to return the Want.| 105 106**Example** 107 108```ts 109import WantAgent from '@ohos.wantAgent'; 110 111 112// WantAgent object 113let wantAgent; 114 115// WantAgentInfo object 116let wantAgentInfo = { 117 wants: [ 118 { 119 deviceId: 'deviceId', 120 bundleName: 'com.neu.setResultOnAbilityResultTest1', 121 abilityName: 'com.example.test.EntryAbility', 122 action: 'action1', 123 entities: ['entity1'], 124 type: 'MIMETYPE', 125 uri: 'key={true,true,false}', 126 parameters: 127 { 128 mykey0: 2222, 129 mykey1: [1, 2, 3], 130 mykey2: '[1, 2, 3]', 131 mykey3: 'ssssssssssssssssssssssssss', 132 mykey4: [false, true, false], 133 mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'], 134 mykey6: true, 135 } 136 } 137 ], 138 operationType: WantAgent.OperationType.START_ABILITIES, 139 requestCode: 0, 140 wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] 141} 142 143WantAgent.getWantAgent(wantAgentInfo).then((data) => { 144 console.info('==========================>getWantAgentCallback=======================>'); 145 wantAgent = data; 146 if (wantAgent) { 147 WantAgent.getWant(wantAgent).then((data) => { 148 console.info('==========================>getWantCallback=======================>'); 149 }); 150 } 151}); 152``` 153 154## WantAgent.getWantAgent 155 156getWantAgent(info: WantAgentInfo, callback: AsyncCallback\<WantAgent\>): void 157 158Obtains a **WantAgent** object. This API uses an asynchronous callback to return the result. If the creation fails, a null **WantAgent** object is returned. 159 160**System capability**: SystemCapability.Ability.AbilityRuntime.Core 161 162**Parameters** 163 164| Name | Type | Mandatory| Description | 165| -------- | -------------------------- | ---- | ----------------------- | 166| info | [WantAgentInfo](js-apis-inner-wantAgent-wantAgentInfo.md) | Yes | Information about the **WantAgent** object to obtain. | 167| callback | AsyncCallback\<WantAgent\> | Yes | Callback used to return the **WantAgent** object.| 168 169**Example** 170 171```ts 172import WantAgent from '@ohos.wantAgent'; 173 174// getWantAgent callback 175function getWantAgentCallback(err, data) { 176 if (err.code) { 177 console.info('getWantAgent Callback err:' + JSON.stringify(err)) 178 } else { 179 console.info('getWantAgent Callback success') 180 } 181} 182// WantAgentInfo object 183let wantAgentInfo = { 184 wants: [ 185 { 186 deviceId: 'deviceId', 187 bundleName: 'com.neu.setResultOnAbilityResultTest1', 188 abilityName: 'com.example.test.EntryAbility', 189 action: 'action1', 190 entities: ['entity1'], 191 type: 'MIMETYPE', 192 uri: 'key={true,true,false}', 193 parameters: 194 { 195 mykey0: 2222, 196 mykey1: [1, 2, 3], 197 mykey2: '[1, 2, 3]', 198 mykey3: 'ssssssssssssssssssssssssss', 199 mykey4: [false, true, false], 200 mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'], 201 mykey6: true, 202 } 203 } 204 ], 205 operationType: WantAgent.OperationType.START_ABILITIES, 206 requestCode: 0, 207 wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] 208} 209 210WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback); 211``` 212 213## WantAgent.getWantAgent 214 215getWantAgent(info: WantAgentInfo): Promise\<WantAgent\> 216 217Obtains a **WantAgent** object. This API uses a promise to return the result. If the creation fails, a null **WantAgent** object is returned. 218 219**System capability**: SystemCapability.Ability.AbilityRuntime.Core 220 221**Parameters** 222 223| Name| Type | Mandatory| Description | 224| ---- | ------------- | ---- | ------------- | 225| info | [WantAgentInfo](js-apis-inner-wantAgent-wantAgentInfo.md) | Yes | Information about the **WantAgent** object to obtain.| 226 227**Return value** 228 229| Type | Description | 230| ----------------------------------------------------------- | ------------------------------------------------------------ | 231| Promise\<WantAgent\> | Promise used to return the **WantAgent** object.| 232 233**Example** 234 235```ts 236import WantAgent from '@ohos.wantAgent'; 237 238 239// WantAgentInfo object 240let wantAgentInfo = { 241 wants: [ 242 { 243 deviceId: 'deviceId', 244 bundleName: 'com.neu.setResultOnAbilityResultTest1', 245 abilityName: 'com.example.test.EntryAbility', 246 action: 'action1', 247 entities: ['entity1'], 248 type: 'MIMETYPE', 249 uri: 'key={true,true,false}', 250 parameters: 251 { 252 mykey0: 2222, 253 mykey1: [1, 2, 3], 254 mykey2: '[1, 2, 3]', 255 mykey3: 'ssssssssssssssssssssssssss', 256 mykey4: [false, true, false], 257 mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'], 258 mykey6: true, 259 } 260 } 261 ], 262 operationType: WantAgent.OperationType.START_ABILITIES, 263 requestCode: 0, 264 wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] 265} 266 267WantAgent.getWantAgent(wantAgentInfo).then((data) => { 268 console.info('==========================>getWantAgentCallback=======================>'); 269}); 270``` 271 272## WantAgent.getBundleName 273 274getBundleName(agent: WantAgent, callback: AsyncCallback\<string\>): void 275 276Obtains the bundle name of a **WantAgent** object. This API uses an asynchronous callback to return the result. 277 278**System capability**: SystemCapability.Ability.AbilityRuntime.Core 279 280**Parameters** 281 282| Name | Type | Mandatory| Description | 283| -------- | ----------------------- | ---- | --------------------------------- | 284| agent | WantAgent | Yes | Target **WantAgent** object. | 285| callback | AsyncCallback\<string\> | Yes | Callback used to return the bundle name.| 286 287**Example** 288 289```ts 290import WantAgent from '@ohos.wantAgent'; 291 292 293// WantAgent object 294let wantAgent; 295 296// getWantAgent callback 297function getWantAgentCallback(err, data) { 298 console.info('==========================>getWantAgentCallback=======================>'); 299 if (err.code == 0) { 300 wantAgent = data; 301 } else { 302 console.error('getWantAgent failed, error: ' + JSON.stringify(err)); 303 return; 304 } 305 306 // getBundleName callback 307 function getBundleNameCallback(err, data) { 308 console.info('==========================>getBundleNameCallback=======================>'); 309 } 310 WantAgent.getBundleName(wantAgent, getBundleNameCallback); 311} 312// WantAgentInfo object 313let wantAgentInfo = { 314 wants: [ 315 { 316 deviceId: 'deviceId', 317 bundleName: 'com.neu.setResultOnAbilityResultTest1', 318 abilityName: 'com.example.test.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 } 334 ], 335 operationType: WantAgent.OperationType.START_ABILITIES, 336 requestCode: 0, 337 wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] 338} 339 340WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback) 341``` 342 343 344 345## WantAgent.getBundleName 346 347getBundleName(agent: WantAgent): Promise\<string\> 348 349Obtains the bundle name of a **WantAgent** object. This API uses a promise to return the result. 350 351**System capability**: SystemCapability.Ability.AbilityRuntime.Core 352 353**Parameters** 354 355| Name | Type | Mandatory| Description | 356| ----- | --------- | ---- | ------------- | 357| agent | WantAgent | Yes | Target **WantAgent** object.| 358 359**Return value** 360 361| Type | Description | 362| ----------------- | ------------------------------------------------ | 363| Promise\<string\> | Promise used to return the bundle name.| 364 365**Example** 366 367```ts 368import WantAgent from '@ohos.wantAgent'; 369 370// WantAgent object 371let wantAgent; 372 373// WantAgentInfo object 374let wantAgentInfo = { 375 wants: [ 376 { 377 deviceId: 'deviceId', 378 bundleName: 'com.neu.setResultOnAbilityResultTest1', 379 abilityName: 'com.example.test.EntryAbility', 380 action: 'action1', 381 entities: ['entity1'], 382 type: 'MIMETYPE', 383 uri: 'key={true,true,false}', 384 parameters: 385 { 386 mykey0: 2222, 387 mykey1: [1, 2, 3], 388 mykey2: '[1, 2, 3]', 389 mykey3: 'ssssssssssssssssssssssssss', 390 mykey4: [false, true, false], 391 mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'], 392 mykey6: true, 393 } 394 } 395 ], 396 operationType: WantAgent.OperationType.START_ABILITIES, 397 requestCode: 0, 398 wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] 399} 400 401WantAgent.getWantAgent(wantAgentInfo).then((data) => { 402 console.info('==========================>getWantAgentCallback=======================>'); 403 wantAgent = data; 404 if (wantAgent) { 405 WantAgent.getBundleName(wantAgent).then((data) => { 406 console.info('==========================>getBundleNameCallback=======================>'); 407 }); 408 } 409}); 410``` 411 412 413 414## WantAgent.getUid 415 416getUid(agent: WantAgent, callback: AsyncCallback\<number\>): void 417 418Obtains the user ID of a **WantAgent** object. This API uses an asynchronous callback to return the result. 419 420**System capability**: SystemCapability.Ability.AbilityRuntime.Core 421 422**Parameters** 423 424| Name | Type | Mandatory| Description | 425| -------- | ----------------------- | ---- | ----------------------------------- | 426| agent | WantAgent | Yes | Target **WantAgent** object. | 427| callback | AsyncCallback\<number\> | Yes | Callback used to return the user ID.| 428 429**Example** 430 431```ts 432import WantAgent from '@ohos.wantAgent'; 433 434 435// WantAgent object 436let wantAgent; 437 438// getWantAgent callback 439function getWantAgentCallback(err, data) { 440 console.info('==========================>getWantAgentCallback=======================>'); 441 if (err.code == 0) { 442 wantAgent = data; 443 } else { 444 console.error('getWantAgent failed, error: ' + JSON.stringify(err)); 445 return; 446 } 447 448 // getUid callback 449 function getUidCallback(err, data) { 450 console.info('==========================>getUidCallback=======================>'); 451 } 452 WantAgent.getUid(wantAgent, getUidCallback); 453} 454// WantAgentInfo object 455let wantAgentInfo = { 456 wants: [ 457 { 458 deviceId: 'deviceId', 459 bundleName: 'com.neu.setResultOnAbilityResultTest1', 460 abilityName: 'com.example.test.EntryAbility', 461 action: 'action1', 462 entities: ['entity1'], 463 type: 'MIMETYPE', 464 uri: 'key={true,true,false}', 465 parameters: 466 { 467 mykey0: 2222, 468 mykey1: [1, 2, 3], 469 mykey2: '[1, 2, 3]', 470 mykey3: 'ssssssssssssssssssssssssss', 471 mykey4: [false, true, false], 472 mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'], 473 mykey6: true, 474 } 475 } 476 ], 477 operationType: WantAgent.OperationType.START_ABILITIES, 478 requestCode: 0, 479 wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] 480} 481 482WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback) 483``` 484 485 486 487## WantAgent.getUid 488 489getUid(agent: WantAgent): Promise\<number\> 490 491Obtains the user ID of a **WantAgent** object. This API uses a promise to return the result. 492 493**System capability**: SystemCapability.Ability.AbilityRuntime.Core 494 495**Parameters** 496 497| Name | Type | Mandatory| Description | 498| ----- | --------- | ---- | ------------- | 499| agent | WantAgent | Yes | Target **WantAgent** object.| 500 501**Return value** 502 503| Type | Description | 504| ----------------------------------------------------------- | ------------------------------------------------------------ | 505| Promise\<number\> | Promise used to return the user ID.| 506 507**Example** 508 509```ts 510import WantAgent from '@ohos.wantAgent'; 511 512 513// WantAgent object 514let wantAgent; 515 516// WantAgentInfo object 517let wantAgentInfo = { 518 wants: [ 519 { 520 deviceId: 'deviceId', 521 bundleName: 'com.neu.setResultOnAbilityResultTest1', 522 abilityName: 'com.example.test.EntryAbility', 523 action: 'action1', 524 entities: ['entity1'], 525 type: 'MIMETYPE', 526 uri: 'key={true,true,false}', 527 parameters: 528 { 529 mykey0: 2222, 530 mykey1: [1, 2, 3], 531 mykey2: '[1, 2, 3]', 532 mykey3: 'ssssssssssssssssssssssssss', 533 mykey4: [false, true, false], 534 mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'], 535 mykey6: true, 536 } 537 } 538 ], 539 operationType: WantAgent.OperationType.START_ABILITIES, 540 requestCode: 0, 541 wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] 542} 543 544WantAgent.getWantAgent(wantAgentInfo).then((data) => { 545 console.info('==========================>getWantAgentCallback=======================>'); 546 wantAgent = data; 547 if (wantAgent) { 548 WantAgent.getUid(wantAgent).then((data) => { 549 console.info('==========================>getUidCallback=======================>'); 550 }); 551 } 552}); 553``` 554 555 556## WantAgent.cancel 557 558cancel(agent: WantAgent, callback: AsyncCallback\<void\>): void 559 560Cancels a **WantAgent** object. This API uses an asynchronous callback to return the result. 561 562**System capability**: SystemCapability.Ability.AbilityRuntime.Core 563 564**Parameters** 565 566| Name | Type | Mandatory| Description | 567| -------- | --------------------- | ---- | --------------------------- | 568| agent | WantAgent | Yes | Target **WantAgent** object. | 569| callback | AsyncCallback\<void\> | Yes | Callback used to return the result.| 570 571**Example** 572 573```ts 574import WantAgent from '@ohos.wantAgent'; 575 576 577// WantAgent object 578let wantAgent; 579 580// getWantAgent callback 581function getWantAgentCallback(err, data) { 582 console.info('==========================>getWantAgentCallback=======================>'); 583 if (err.code == 0) { 584 wantAgent = data; 585 } else { 586 console.error('getWantAgent failed, error: ' + JSON.stringify(err)); 587 return; 588 } 589 590 // cancel callback 591 function cancelCallback(err, data) { 592 console.info('==========================>cancelCallback=======================>'); 593 } 594 WantAgent.cancel(wantAgent, cancelCallback); 595} 596// WantAgentInfo object 597let wantAgentInfo = { 598 wants: [ 599 { 600 deviceId: 'deviceId', 601 bundleName: 'com.neu.setResultOnAbilityResultTest1', 602 abilityName: 'com.example.test.EntryAbility', 603 action: 'action1', 604 entities: ['entity1'], 605 type: 'MIMETYPE', 606 uri: 'key={true,true,false}', 607 parameters: 608 { 609 mykey0: 2222, 610 mykey1: [1, 2, 3], 611 mykey2: '[1, 2, 3]', 612 mykey3: 'ssssssssssssssssssssssssss', 613 mykey4: [false, true, false], 614 mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'], 615 mykey6: true, 616 } 617 } 618 ], 619 operationType: WantAgent.OperationType.START_ABILITIES, 620 requestCode: 0, 621 wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] 622} 623 624WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback) 625``` 626 627 628 629## WantAgent.cancel 630 631cancel(agent: WantAgent): Promise\<void\> 632 633Cancels a **WantAgent** object. This API uses a promise to return the result. 634 635**System capability**: SystemCapability.Ability.AbilityRuntime.Core 636 637**Parameters** 638 639| Name | Type | Mandatory| Description | 640| ----- | --------- | ---- | ------------- | 641| agent | WantAgent | Yes | Target **WantAgent** object.| 642 643**Return value** 644 645| Type | Description | 646| --------------- | ------------------------------- | 647| Promise\<void\> | Promise used to return the result.| 648 649**Example** 650 651```ts 652import WantAgent from '@ohos.wantAgent'; 653 654 655// WantAgent object 656let wantAgent; 657 658// WantAgentInfo object 659let wantAgentInfo = { 660 wants: [ 661 { 662 deviceId: 'deviceId', 663 bundleName: 'com.neu.setResultOnAbilityResultTest1', 664 abilityName: 'com.example.test.EntryAbility', 665 action: 'action1', 666 entities: ['entity1'], 667 type: 'MIMETYPE', 668 uri: 'key={true,true,false}', 669 parameters: 670 { 671 mykey0: 2222, 672 mykey1: [1, 2, 3], 673 mykey2: '[1, 2, 3]', 674 mykey3: 'ssssssssssssssssssssssssss', 675 mykey4: [false, true, false], 676 mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'], 677 mykey6: true, 678 } 679 } 680 ], 681 operationType: WantAgent.OperationType.START_ABILITIES, 682 requestCode: 0, 683 wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] 684} 685 686WantAgent.getWantAgent(wantAgentInfo).then((data) => { 687 console.info('==========================>getWantAgentCallback=======================>'); 688 wantAgent = data; 689 if (wantAgent) { 690 WantAgent.cancel(wantAgent).then((data) => { 691 console.info('==========================>cancelCallback=======================>'); 692 }); 693 } 694}); 695``` 696 697 698 699## WantAgent.trigger 700 701trigger(agent: WantAgent, triggerInfo: TriggerInfo, callback?: Callback\<CompleteData\>): void 702 703Triggers a **WantAgent** object. This API uses an asynchronous callback to return the result. 704 705**System capability**: SystemCapability.Ability.AbilityRuntime.Core 706 707**Parameters** 708 709| Name | Type | Mandatory| Description | 710| ----------- | ----------------------------- | ---- | ------------------------------- | 711| agent | WantAgent | Yes | Target **WantAgent** object. | 712| triggerInfo | [TriggerInfo](js-apis-inner-wantAgent-triggerInfo.md) | Yes | **TriggerInfo** object. | 713| callback | AsyncCallback\<CompleteData\> | No | Callback used to return the result.| 714 715**Example** 716 717```ts 718import WantAgent from '@ohos.wantAgent'; 719 720 721// WantAgent object 722let wantAgent; 723 724// getWantAgent callback 725function getWantAgentCallback(err, data) { 726 console.info('==========================>getWantAgentCallback=======================>'); 727 if (err.code == 0) { 728 wantAgent = data; 729 } else { 730 console.error('getWantAgent failed, error: ' + JSON.stringify(err)); 731 return; 732 } 733 734 // trigger callback 735 function triggerCallback(data) { 736 console.info('==========================>triggerCallback=======================>'); 737 } 738 739 var triggerInfo = { 740 code:0 741 } 742 WantAgent.trigger(wantAgent, triggerInfo, triggerCallback) 743} 744// WantAgentInfo object 745let wantAgentInfo = { 746 wants: [ 747 { 748 deviceId: 'deviceId', 749 bundleName: 'com.neu.setResultOnAbilityResultTest1', 750 abilityName: 'com.example.test.EntryAbility', 751 action: 'action1', 752 entities: ['entity1'], 753 type: 'MIMETYPE', 754 uri: 'key={true,true,false}', 755 parameters: 756 { 757 mykey0: 2222, 758 mykey1: [1, 2, 3], 759 mykey2: '[1, 2, 3]', 760 mykey3: 'ssssssssssssssssssssssssss', 761 mykey4: [false, true, false], 762 mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'], 763 mykey6: true, 764 } 765 } 766 ], 767 operationType: WantAgent.OperationType.START_ABILITIES, 768 requestCode: 0, 769 wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] 770} 771 772WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback) 773``` 774 775 776 777## WantAgent.equal 778 779equal(agent: WantAgent, otherAgent: WantAgent, callback: AsyncCallback\<boolean\>): void 780 781Checks whether two **WantAgent** objects are equal to determine whether the same operation is from the same application. This API uses an asynchronous callback to return the result. 782 783**System capability**: SystemCapability.Ability.AbilityRuntime.Core 784 785**Parameters** 786 787| Name | Type | Mandatory| Description | 788| ---------- | ------------------------ | ---- | --------------------------------------- | 789| agent | WantAgent | Yes | The first **WantAgent** object. | 790| otherAgent | WantAgent | Yes | The second **WantAgent** object. | 791| callback | AsyncCallback\<boolean\> | Yes | Callback used to return the result.| 792 793**Example** 794 795```ts 796import WantAgent from '@ohos.wantAgent'; 797 798 799// WantAgent object 800let wantAgent1; 801let wantAgent2; 802 803// getWantAgent callback 804function getWantAgentCallback(err, data) { 805 console.info('==========================>getWantAgentCallback=======================>'); 806 if (err.code == 0) { 807 wantAgent1 = data; 808 wantAgent2 = data; 809 } else { 810 console.error('getWantAgent failed, error: ' + JSON.stringify(err)); 811 return; 812 } 813 814 // equal callback 815 function equalCallback(err, data) { 816 console.info('==========================>equalCallback=======================>'); 817 } 818 WantAgent.equal(wantAgent1, wantAgent2, equalCallback) 819} 820// WantAgentInfo object 821let wantAgentInfo = { 822 wants: [ 823 { 824 deviceId: 'deviceId', 825 bundleName: 'com.neu.setResultOnAbilityResultTest1', 826 abilityName: 'com.example.test.EntryAbility', 827 action: 'action1', 828 entities: ['entity1'], 829 type: 'MIMETYPE', 830 uri: 'key={true,true,false}', 831 parameters: 832 { 833 mykey0: 2222, 834 mykey1: [1, 2, 3], 835 mykey2: '[1, 2, 3]', 836 mykey3: 'ssssssssssssssssssssssssss', 837 mykey4: [false, true, false], 838 mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'], 839 mykey6: true, 840 } 841 } 842 ], 843 operationType: WantAgent.OperationType.START_ABILITIES, 844 requestCode: 0, 845 wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] 846} 847 848WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback) 849``` 850 851 852 853## WantAgent.equal 854 855equal(agent: WantAgent, otherAgent: WantAgent): Promise\<boolean\> 856 857Checks whether two **WantAgent** objects are equal to determine whether the same operation is from the same application. This API uses a promise to return the result. 858 859**System capability**: SystemCapability.Ability.AbilityRuntime.Core 860 861**Parameters** 862 863| Name | Type | Mandatory| Description | 864| ---------- | --------- | ---- | ------------- | 865| agent | WantAgent | Yes | The first **WantAgent** object.| 866| otherAgent | WantAgent | Yes | The second **WantAgent** object.| 867 868**Return value** 869 870| Type | Description | 871| ----------------------------------------------------------- | ------------------------------------------------------------ | 872| Promise\<boolean\> | Promise used to return the result.| 873 874**Example** 875 876```ts 877import WantAgent from '@ohos.wantAgent'; 878 879 880// WantAgent object 881let wantAgent1; 882let wantAgent2; 883 884// WantAgentInfo object 885let wantAgentInfo = { 886 wants: [ 887 { 888 deviceId: 'deviceId', 889 bundleName: 'com.neu.setResultOnAbilityResultTest1', 890 abilityName: 'com.example.test.EntryAbility', 891 action: 'action1', 892 entities: ['entity1'], 893 type: 'MIMETYPE', 894 uri: 'key={true,true,false}', 895 parameters: 896 { 897 mykey0: 2222, 898 mykey1: [1, 2, 3], 899 mykey2: '[1, 2, 3]', 900 mykey3: 'ssssssssssssssssssssssssss', 901 mykey4: [false, true, false], 902 mykey5: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'], 903 mykey6: true, 904 } 905 } 906 ], 907 operationType: WantAgent.OperationType.START_ABILITIES, 908 requestCode: 0, 909 wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] 910} 911 912WantAgent.getWantAgent(wantAgentInfo).then((data) => { 913 console.info('==========================>getWantAgentCallback=======================>'); 914 wantAgent1 = data; 915 wantAgent2 = data; 916 if (data) { 917 WantAgent.equal(wantAgent1, wantAgent2).then((data) => { 918 console.info('==========================>equalCallback=======================>'); 919 }); 920 } 921}); 922 923WantAgent.equal(wantAgent1, wantAgent2).then((data) => { 924 console.info('==========================>equalCallback=======================>'); 925}); 926``` 927 928## WantAgentFlags 929 930**System capability**: SystemCapability.Ability.AbilityRuntime.Core 931 932| Name | Value | Description | 933| ------------------- | -------------- | ------------------------------------------------------------ | 934| ONE_TIME_FLAG | 0 | The **WantAgent** object can be used only once. | 935| NO_BUILD_FLAG | 1 | The **WantAgent** object does not exist and hence it is not created. In this case, **null** is returned. | 936| CANCEL_PRESENT_FLAG | 2 | The existing **WantAgent** object should be canceled before a new object is generated.| 937| UPDATE_PRESENT_FLAG | 3 | Extra information of the existing **WantAgent** object is replaced with that of the new object.| 938| CONSTANT_FLAG | 4 | The **WantAgent** object is immutable. | 939| REPLACE_ELEMENT | 5 | The **element** attribute of the current **Want** can be replaced by the **element** attribute of the **Want** in **WantAgent.trigger()**.| 940| REPLACE_ACTION | 6 | The **action** attribute of the current **Want** can be replaced by the **action** attribute of the **Want** in **WantAgent.trigger()**.| 941| REPLACE_URI | 7 | The **uri** attribute of the current **Want** can be replaced by the **uri** attribute of the **Want** in **WantAgent.trigger()**.| 942| REPLACE_ENTITIES | 8 | The **entities** attribute of the current **Want** can be replaced by the **entities** attribute of the **Want** in **WantAgent.trigger()**.| 943| REPLACE_BUNDLE | 9 | The **bundleName** attribute of the current **Want** can be replaced by the **bundleName** attribute of **Want** in **WantAgent.trigger()**.| 944 945## OperationType 946 947**System capability**: SystemCapability.Ability.AbilityRuntime.Core 948 949| Name | Value | Description | 950| ----------------- | ------------- | ------------------------- | 951| UNKNOWN_TYPE | 0 | Unknown operation type. | 952| START_ABILITY | 1 | Starts an ability with a UI.| 953| START_ABILITIES | 2 | Starts multiple abilities with a UI.| 954| START_SERVICE | 3 | Starts an ability without a UI.| 955| SEND_COMMON_EVENT | 4 | Sends a common event. | 956 957## CompleteData 958 959**System capability**: SystemCapability.Ability.AbilityRuntime.Core 960 961| Name | Type | Mandatory| Description | 962| -------------- | ------------------------------ | ---- | ---------------------- | 963| info | WantAgent | Yes | A triggered **WantAgent** object. | 964| want | Want | Yes | An existing triggered **want**. | 965| finalCode | number | Yes | Request code that triggers the **WantAgent** object.| 966| finalData | string | Yes | Final data collected by the common event. | 967| extraInfo | {[key: string]: any} | No | Extra information. | 968